Een tijdje geleden kreeg ik van Arco onderstaande code om te bepalen of het zomer-of wintertijd is:
Of 't zomer of wintertijd is kun je softwarematig makkelijk vaststellen.
Deze routine kan van een Europese of USA datum/tijd afleiden of het zomertijd (DST) is of niet...Als het zomertijd is, is bit 0 van het resultaat '1'
Als er een zomer <-> wintertijd omschakeling is geweest sinds laatste aanroep, dan is bit 1 geset.Als pZone=1 dan Europees, als pZone=2 dan USA tijd.
pic basic code:
Dim DSTState As Byte OldDSTState As Byte Const DSTParm As Byte[16] = (31,5,31,2,3,10,2,3,14,2,7,2,3,11,2,2) '============================================================================== Sub Function Is_DST(Dim pZone As Byte) As Byte 'Tests if it's DST '============================================================================== Dim lBegin, lEnd, lZone As Byte '---------------------------------------------------------------------------- If pZone Then lZone = (pZone - 1) << 3 Result = 0 lBegin = (((5 * tYear) div 4) - (tYear div 100) + (tYear div 400)) Mod 7 lEnd = DstParm[lZone+2] - (lBegin+DstParm[lZone+3]) Mod 7 lBegin = DstParm[lZone+0] - (lBegin+DstParm[lZone+1]) Mod 7 '-------------------------------------------------------------------------- If (tMonth <= DstParm[lZone+4]) Or (tMonth >= DstParm[lZone+5]) Then If ((tMonth = DstParm[lZone+4]) And (tMonthDay < lBegin)) Or ((tMonth = DstParm[lZone+5]) And (tMonthDay > lEnd)) Or ((tMonth = DstParm[lZone+4]) And (tMonthDay = lBegin) And (tHour < DstParm[lZone+6])) Or ((tMonth = DstParm[lZone+5]) And (tMonthDay = lEnd) And (tHour >= DstParm[lZone+7])) Then DSTState = 1 End If End If If (tMonth >= DstParm[lZone+4]) Or (tMonth <= DstParm[lZone+5]) Then If ((tMonth = DstParm[lZone+4]) And (tMonthDay > lBegin)) Or ((tMonth = DstParm[lZone+5]) And (tMonthDay < lEnd)) Or ((tMonth = DstParm[lZone+4]) And (tMonthDay = lBegin) And (tHour >= DstParm[lZone+6])) Or ((tMonth = DstParm[lZone+5]) And (tMonthDay = lEnd) And (tHour < DstParm[lZone+7]-1)) Then DSTState = 2 End If End If If DSTState = 0 Then If tMonth = DstParm[lZone+4] Then DSTState = 2 Else DSTState = 1 End If End If If DstState = 2 Then Result.0 = 1 End If If DstState = 1 Then Result.0 = 0 End If If OldDSTState <> DSTState Then Result.1 = 1 OldDSTState = DSTState Else Result.1 = 0 End If End If End Sub
Dus dacht ik dat dit zou moeten werken
pic basic code:
Const DSTParm As Byte[16] = (31,5,31,2,3,10,2,3,14,2,7,2,3,11,2,2)
Dim DSTState As Byte
OldDSTState As Byte
tyear As word
tmonth As byte
tmonthday As byte
thour As byte
Main:
lata.6 = 0
DSTState = 0
OldDststate = 0
thour = 02
tmonth = 01
tmonthday = 03
tyear = 2021
lata.6 = Is_Dst(1).0
Led aan zou zomertijd zijn, uit = wintertijd.
Maar het werkt niet. Alle Datums geven resultaat 0 (wintertijd).
Voor Tyear heb ik zowel 21 als 2021 geprobeerd (ik weet niet precies wat de routine verlangt).