Debuggen met een lcd display is meestal onhandig, omdat je steeds moet wachten. (je moet tenslotte de tijd hebben om te lezen wat er staat voor het weer verdwijnt)
Voor zomer en wintertijd heb je geen tabel nodig, kun je simpel berekenen. Deze Mikrobasic functie geeft '1' terug bij DST (zomertijd), anders '0'.
De TS2 structure heeft de huidige tijd en datum.
pic basic code:
Structure TimeStruct
dim ss as byte ' seconds
dim mn as byte ' minutes
dim hh as byte ' hours
dim md as byte ' day in month, from 1 to 31
dim wd as byte ' day in week, monday=0, tuesday=1, .... sunday=6
dim mo as byte ' month number, from 1 to 12 (and not from 0 to 11 as with unix C time !)
dim yy as word ' year Y2K compliant, from 1892 to 2038
End structure
'==================================================================================================
Sub Function Is_DST() As Byte 'Tests if it is DST now
'==================================================================================================
Dim TS2 As TimeStruct
Dim DST_Begin As Byte
Dim DST_End As Byte
Result = 0
DST_Begin = ((TS2.yy-2001) + (TS2.yy-2001) /4) Mod 7 'Calculate begin and enddate of DST
DST_Begin = (7-DST_Begin) + 25 '
If TS2.yy Mod 4 = 0 Then Dec(DST_Begin) End If 'Leap Year correction
DST_End = DST_Begin - 4 '
If DST_End < 25 Then DST_End = DST_End + 7 End If '
If ((TS2.mo > 3) And (TS2.mo < 10)) Or 'See if DST applicable
((TS2.mo = 3) And (TS2.md >= DST_Begin)) Or '
((TS2.mo =10) And (TS2.md < DST_End)) Then '
Result = 1
End If
End Sub
'==================================================================================================
[edit]
LeapYear aangepast, veranderd in: If TS2.yy Mod 4 = 0 Then Dec(DST_Begin) End If.
Met dank aan @hadv voor zijn correctie...
[/edit]