Time Zone and CF v2.0

J

John Roberts

Another summer begins and yet again, my code for handling daylight saving
time didn't work. I only get twice a year to test this in the field!
Anyway,...

Is DST broken in Compact Framework v2.0?

I have TimeZoneInformation set correctly in the registry:

[HKEY_LOCAL_MACHINE\Time]
"TimeZoneInformation"=hex:\
00,00,00,00,47,00,4d,00,54,00,20,00,53,00,74,00,61,00,6e,00,64,00,61,00,72,\
00,64,00,20,00,54,00,69,00,6d,00,65,00,00,00,00,00,00,00,00,00,00,00,00,00,\
00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,0a,00,00,00,05,\
00,02,00,00,00,00,00,00,00,00,00,00,00,47,00,4d,00,54,00,20,00,44,00,61,00,\
79,00,6c,00,69,00,67,00,68,00,74,00,20,00,54,00,69,00,6d,00,65,00,00,00,00,\
00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,\
00,00,00,00,03,00,00,00,05,00,01,00,00,00,00,00,00,00,c4,ff,ff,ff

It is set for GMT Standard Time/Daylight Time. However,

i) TimeZone.CurrentTimeZone returns 'false' for IsDaylightTime(DateTime.Now)

ii) TimeZone.CurrentTimeZone.GetDaylightChanges(2006) returns an invalid
date

iii) TimeZone.CurrentTimeZone.DaylightName is 'GMT Standard Time' - it
should be 'GMT Daylight Time'

iv) DateTime.Now returns GMT, not BST

It is as though CF is ignoring the time zone setting in the registry...

I get the same results regardless of what SetDaylightTime() has been set to,
although in general I don't use this 'feature' of Windows CE and keep it
off. BTW, the platform is Windows CE v5.0...

Everything worked last summer when I was using Compact Framework v1.0. I
can't think what else might be wrong other than a problem with CF v2.0...
does anybody have it working correctly?

TIA,
- John
 
P

Paul G. Tobey [eMVP]

I think that we need higher-level information than this. On the Date/Time
control panel applet, what time zone is selected (literally GMT Dublin or
Casablanca and which one, if so)? Is the applet setting for automatic
adjustment of time for DST set?

By the way, you can change the time any time you want and see what's going
to happen next March, say, or this October. You don't literally have to
wait for the real date to roll around.

Paul T.
 
J

John Roberts

"Paul G. Tobey [eMVP]" <p space tobey no spam AT no instrument no spam DOT
com> wrote in message news:[email protected]...
I think that we need higher-level information than this. On the Date/Time
control panel applet, what time zone is selected (literally GMT Dublin or
Casablanca and which one, if so)? Is the applet setting for automatic
adjustment of time for DST set?

The platform is a custom Windows CE 5.0 build with the shell removed. There
is therefore no access to the control panel and clock. I set the time and
time zone using the API calls SetTimeZoneInformation and SetSystemTime. I
know that the time zone information set in the registry after the call is
correct (as posted below). The registry setting that the clock uses for
automatic adjustment of time is not present. I also see the same bug when
using other time zones, specifically PST although I know daylight time there
doesn't start until Sunday (which gives me 5 days to find a fix or
workaround for this problem!).

I also use SetDaylightTime(false) always but from my investigations, it
doesn't matter whether this flag is on or off, the TimeZone.CurrentTimeZone
object always gets its answers wrong.
By the way, you can change the time any time you want and see what's going
to happen next March, say, or this October. You don't literally have to
wait for the real date to roll around.

I know ;-), although it isn't always that simple. We use data that has not
yet been generated and is time sensitive.

TIA,
- John
Paul T.

John Roberts said:
Another summer begins and yet again, my code for handling daylight saving
time didn't work. I only get twice a year to test this in the field!
Anyway,...

Is DST broken in Compact Framework v2.0?

I have TimeZoneInformation set correctly in the registry:

[HKEY_LOCAL_MACHINE\Time]
"TimeZoneInformation"=hex:\

00,00,00,00,47,00,4d,00,54,00,20,00,53,00,74,00,61,00,6e,00,64,00,61,00,72,\

00,64,00,20,00,54,00,69,00,6d,00,65,00,00,00,00,00,00,00,00,00,00,00,00,00,\

00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,0a,00,00,00,05,\

00,02,00,00,00,00,00,00,00,00,00,00,00,47,00,4d,00,54,00,20,00,44,00,61,00,\

79,00,6c,00,69,00,67,00,68,00,74,00,20,00,54,00,69,00,6d,00,65,00,00,00,00,\

00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,\
00,00,00,00,03,00,00,00,05,00,01,00,00,00,00,00,00,00,c4,ff,ff,ff

It is set for GMT Standard Time/Daylight Time. However,

i) TimeZone.CurrentTimeZone returns 'false' for
IsDaylightTime(DateTime.Now)

ii) TimeZone.CurrentTimeZone.GetDaylightChanges(2006) returns an invalid
date

iii) TimeZone.CurrentTimeZone.DaylightName is 'GMT Standard Time' - it
should be 'GMT Daylight Time'

iv) DateTime.Now returns GMT, not BST

It is as though CF is ignoring the time zone setting in the registry...

I get the same results regardless of what SetDaylightTime() has been set
to, although in general I don't use this 'feature' of Windows CE and keep
it off. BTW, the platform is Windows CE v5.0...

Everything worked last summer when I was using Compact Framework v1.0. I
can't think what else might be wrong other than a problem with CF v2.0...
does anybody have it working correctly?

TIA,
- John
 
J

John Roberts

Hi Paul,

Thank you, setting the clock's registry setting made all the difference:

[HKEY_LOCAL_MACHINE\Software\Microsoft\Clock]
"AutoDST"=dword:1

To recap, this registry setting needs to be present to make the API calls:

TimeZone.CurrentTimeZone.DaylightTime and friends work as expected. If it is
not set, DaylightTime returns a copy of StandardTime and the date when DST
is applied is empty.

I also note the US rules for DST change in 2007:
http://webexhibits.org/daylightsaving/b.html

Cheers,
- John
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top