Intercepting user Date Time change

T

Tom Shelton

Armin Zingler formulated on Sunday :
Am 14.02.2011 03:03, schrieb Tom Shelton:

If updating the application internal base datetime from the external
source is done in intervals in the background, latency shouldn't
be an issue.

now = datetime from last ntp update + ticks since last update

Any pitfalls?

interesting... it actually might be workable.
The only one I can think of is standby/hibernation. But if
this can be reliably handled by handling
Microsoft.Win32.SystemEvents.PowerModeChanged, this shouldn't be an issue,
too. Well, there's still a small chance that the event occurs a little too
"late". I mean, between waking up from hibernation and the occurrance of the
PowerModeChanged, our new "Now" function could have been called, and it would
return a too small value. But, a) the situation is VERY rare,
b) all datetimes are still in order and thus shouldn't harm anything.

(Is environment.tickcount reset after hibernation? :) )

I don't really know... I've never had to take it into account before
:) My guess would be no.
 
P

pamela fluente

hmm thanks a lot! Very helpful discussion :)

Well yes accessing and relying on an external source would probably
pose a lot of problems, like latency, availability, etc.
Probably a little too dangerous (tickdata is very frequent).

I was not really aware of the tickcount wrap up. I guess that would
be even a bigger threat than an user as that would occur certainly
and the effects can probably be a disaster (?)

I cant restrict the user because he is actually running the app on his
computer (run as administrator with full rights) and i have no power
on him.

The big damage is caused by time going backward (like when a user
wants to bypass the expiration date of another program). If time is
shifted a little ahead it would not be a real big deal.

After all, so far it seems that blocking the charting and data
processing and asking the user to correct time when the time goes
backward
may be the most practical (but a little ugly) solution. I have the
impression that the other solutions might worsen the situation
(unavailability of external time, tickcount wrapup, etc.)

I guess that ideally it would be nice to be able to block and undo
time changes on the local machine, informing the user. But the fact
that nobody has code for that may mean
that is not so straightforward to do ...


-Pam
 
T

Tom Shelton

pamela fluente formulated the question :
hmm thanks a lot! Very helpful discussion :)

Well yes accessing and relying on an external source would probably
pose a lot of problems, like latency, availability, etc.
Probably a little too dangerous (tickdata is very frequent).

I was not really aware of the tickcount wrap up. I guess that would
be even a bigger threat than an user as that would occur certainly
and the effects can probably be a disaster (?)

I cant restrict the user because he is actually running the app on his
computer (run as administrator with full rights) and i have no power
on him.

The big damage is caused by time going backward (like when a user
wants to bypass the expiration date of another program). If time is
shifted a little ahead it would not be a real big deal.

After all, so far it seems that blocking the charting and data
processing and asking the user to correct time when the time goes
backward
may be the most practical (but a little ugly) solution. I have the
impression that the other solutions might worsen the situation
(unavailability of external time, tickcount wrapup, etc.)

I guess that ideally it would be nice to be able to block and undo
time changes on the local machine, informing the user. But the fact
that nobody has code for that may mean
that is not so straightforward to do ...


-Pam

Pam...

You could query a time server (you might want more than one - just like
windows does, in fact, you could probably get the list of timeservers
the os uses from the registry) on startup and see if the system time is
correct. If it is not - you could warn the user.

I've shown you how to know if the system time changes while the app is
running - you just need to handle the WM_TIMECHANGE method. You can
use the opertunity to query the time server again and see what the time
should be and warn the suer that they are about to fowl things up :)
 
A

Armin Zingler

Am 14.02.2011 09:44, schrieb pamela fluente:
The big damage is caused by time going backward

Then you can just use

private shared lastNow as datetime

shared function getnow() as datetime

Dim result = Max(datetime.Now, lastNow + Offset) 'offset may be one second only to avoid duplicate datetimes

lastNow = result
return result

end function

for your current time.
 
P

pamela fluente

pamela fluente formulated the question :

















Pam...

You could query a time server (you might want more than one - just like
windows does, in fact, you could probably get the list of timeservers
the os uses from the registry) on startup and see if the system time is
correct.  If it is not - you could warn the user.

I've shown you how to know if the system time changes while the app is
running - you just need to handle the WM_TIMECHANGE method.  You can
use the opertunity to query the time server again and see what the time
should be and warn the suer that they are about to fowl things up :)

Very good idea Tom! Actually at that point, using your snippet, i
could take the opportunity to reset immediately
the time to the correct time. No ? :))

I am not sure i know how to get the time from a server and reset the
local time, though ...

Pam
 

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