Calculate from GPS date if BST or GMT timezone? need day of week
is it possible from a GPS date, to calculate if the current timezone is BST ot GMT?
as BST and GMT change at the following times "the period beginning at one o'clock, Greenwich mean time, in the morning of the last Sunday in March and ending at one o'clock, Greenwich mean time, in the morning of the last Sunday in October."
in vbscript it is possible like below, but i would need to calculate the last Sunday's somehow in spin from only the ddmmyyyy supplied from the GPS
as BST and GMT change at the following times "the period beginning at one o'clock, Greenwich mean time, in the morning of the last Sunday in March and ending at one o'clock, Greenwich mean time, in the morning of the last Sunday in October."
in vbscript it is possible like below, but i would need to calculate the last Sunday's somehow in spin from only the ddmmyyyy supplied from the GPS
Public Function BSTstarts(ByVal TheYear As Integer) As String
BSTstarts = "March " _
& 31 - (Weekday("#March 31, " & TheYear & "#", 2) Mod 7) _
& ", " & TheYear & " 01:00:00"
End Function
Public Function GMTstarts(ByVal TheYear As Integer) As String
GMTstarts = "October " _
& 31 - (Weekday("#October 31, " & TheYear & "#", 2) Mod 7) _
& ", " & TheYear & " 01:00:00"
End Function

Comments
and looks like this in C:
int dow(int y, int m, int d) { static int t[] = {0, 3, 2, 5, 0, 3, 5, 1, 4, 6, 2, 4}; y -= m < 3; return (y + y/4 - y/100 + y/400 + t[m-1] + d) % 7; }Easy enough to rewrite in Spin
' Day of week. ' Algorithm by Tomohiko Sakamoto, accurate for any Gregorian date. ' Returns Sunday as 0, Monday as 1 etc PUB dayOfWeek(y, m, d) y -= ((m < 3) & 1) return (y + y/4 - y/100 + y/400 + dowTable[m-1] + d) // 7 DAT dowTable long 0, 3, 2, 5, 0, 3, 5, 1, 4, 6, 2, 4Spin version untested as I am Propless at the moment.
Would the best way to find the last Sunday in the month, just feed the PUB with dayOfWeek(2012,03,31) and if return value not 0 ( Sunday ) then subtract 1 from day and try again. keep extracting 1 until return value = 0 ? or is that a long way round to do it?
The last day of March 2012 is dayOfWeek(2012, 3, 31) which returns 6 for Saturday.
Subtract that 6 from the day of the last day of month, 31 - 6, gives us 25 which happens to be the required date of the last Sunday in March.
We can check, dayOfWeek(2012, 3, 25) returns 0 for Sunday.
So:
lastSundayMarch := 31 - dayOfWeek(2012, 3, 31)
lastSundayOctober := 31 - dayOfWeek(2012, 10, 31)
Many Thanks
Thanks
' Return TRUE if BST pub isBST (month, dayOfMonth) if (month == 3) and (dayOfMonth >= lastSundayMarch) 'In the tail end of March ? return true if (month == 10) and (dayOfMonth < lastSundayOctober) 'In the beginning of October? return true if (month > 3) and (month < 10) 'Between March and October? return true return false 'No, must be GMTI'm tired so you had better check those comparisons. It could be simplified further but these tests should make it clear.
to