Calculate from GPS date if BST or GMT timezone? need day of week
Dwayne Dibbley
Posts: 63
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:
Easy enough to rewrite in Spin
Spin 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
I'm tired so you had better check those comparisons. It could be simplified further but these tests should make it clear.
to