Re: What time is it? Issues with Local time, system time, DST
- From: "Paul G. Tobey [eMVP]" <p space tobey no spam AT no instrument no spam DOT com>
- Date: Wed, 15 Apr 2009 08:14:35 -0700
Hi,
We are having difficulty figuring out what time it is when our board
restarts. Does someone have some wisdom about figuring out actual
system time following a reboot?
Apparently CE (at least CE 5.0) stores time in local time, not system
time. Apparently (based on suggestions I found in newsgroups) this was
done for speed, on the assumption that most requests to get time would
be for local time, not UTC.
So OEMSetRealTime receives, and OEMGetRealTime is expected to return,
a local time. I think (yes?) a further assumption is that the result
of an OEMSetRealTime call is that a 32 or 64 bit value representing
the current time is stored in an (internal or external) battery backed
RTC, so that when processor is asleep or off, onboard batteries
continue to power the clock and when board reboots, we determine
current time based on contents of battery backed RTC. Is this correct
so far?
No. I'm not sure where you got that information about OEMSetRealTime
returning some big number. It returns BOOL, as documented in the help.
OEMGetRealTime returns the current time in a SYSTEMTIME structure. Where
you get it from, a battery-backed real-time clock, from clock registers in
the processing, which might not be battery backed, or from a satellite, is
not specified by Windows CE (it doesn't care; do whatever you want).
Since CE stores local time, I think this means that when you reboot
you can't know the UTC unless you also have, in some non-volatile
storage, the time zone *and* whether we are currently in DST or not.
So is the standard way to handle this to store time zone and DST state
to non-volatile storage? Are there standard API calls people use for
this?
The time zone which is set for the device is stored in the registry by
calling SetTimeZoneInformation. The Date/Time control panel applet does
this under user control and there is, of course, a default value. If your
registry is not persistent, yes, finding out UTC will not be possible on
startup, until the user has told you where he's located. The setting of the
DST flag is also stored in the registry. If that persists, you're fine.
A simpler solutions seems to be to just store the UTC, not local time,
at the cost of an extra conversion to satisfy CE. In this case
OEMSetRealTime would convert to UTC before storing in the non-volatile
RTC, and OEMGetRealTime would convert to local time before returning
contents of the RTC. Then to set the time on start up the board would
have to do nothing other than verify the RTC had valid non-garbage
contents. This value could be extracted directly from RTC using an
IOCTL. The time zone would still have to be stored in a non-volatile
way (so user doesn't have to reset it), but it wouldn't have to be
accessible to low-level startup code, and DST wouldn't have to be
stored non-volatile at all. I tried to implement this, but the obvious
functions to do the conversion from UTC to local time don't seem to be
linked in the kernel. Am I not using the right functions?
What would this do for you? Seems totally useless to me. Windows CE, at
least anything running the standard shell, is going to ask for the local
time, to display in the system tray, very frequently. I don't see any valid
reason why you'd want to make that process slower. So, the question is,
"WHY?!?!" Why would you want to try to make Windows CE work in a different
way? You get NO VALUE from doing this unless you are constantly calling
GetSystemTime() in some application, to get UTC, which requires a conversion
from the local time that Windows CE expects to store. If you're not doing
that, forget about doing this. If you *are* doing that, tell us what you're
doing, how often, from what sort of code, and why; maybe we can point you in
a direction that makes sense.
Paul T.
.
- Follow-Ups:
- Re: What time is it? Issues with Local time, system time, DST
- From: Andrew Schweitzer
- Re: What time is it? Issues with Local time, system time, DST
- References:
- What time is it? Issues with Local time, system time, DST
- From: Andrew Schweitzer
- What time is it? Issues with Local time, system time, DST
- Prev by Date: Re: What time is it? Issues with Local time, system time, DST
- Next by Date: Re: Debugging DAT file failures
- Previous by thread: Re: What time is it? Issues with Local time, system time, DST
- Next by thread: Re: What time is it? Issues with Local time, system time, DST
- Index(es):
Relevant Pages
|