×

Discussion Board

Results 1 to 15 of 15
  1. #1
    Regular Contributor
    Join Date
    Jul 2007
    Posts
    161

    Time change protection

    Hello, Symbian experts!
    My application stores events in memory, and periodically sends them to server.
    But there is small problem: if user change date and time on the phone - event times will become wrong.
    I send to server not event, but how much seconds ago it happend.
    Events are stored in memory in UTC.

    I can see a way to fix the things, but it is awful. To store in events in seconds_ago and increment them every second

    Can anyone suggest anything?
    Thanks!
    Last edited by StasV; 2009-02-10 at 10:48.

  2. #2
    Nokia Developer Moderator
    Join Date
    Mar 2003
    Location
    Lempäälä/Finland
    Posts
    29,167

    Re: Time change protection

    I don't think you should really go preventing users on changing the device time, anyway, you could monitor the time change events with RChangeNotifier.

  3. #3
    Super Contributor
    Join Date
    Nov 2004
    Location
    Wiltshire, UK
    Posts
    3,644

    Re: Time change protection

    You cannot prevent the user changing the time anyway as the OS will compensate for clock skew or the user could have network time enabled.

    http://wiki.forum.nokia.com/index.ph..._Nokia_devices
    Download Symbian OS now! [url]http://developer.symbian.org[/url]

  4. #4
    Regular Contributor
    Join Date
    Jul 2007
    Posts
    161

    Re: Time change protection

    I mean I have to protect my time and date variables from data changes
    Found an example:
    {
    ...
    RChangeNotifier the_notifier;
    TRequestStatus the_status;
    ...
    the_notifier.Create();
    the_notifier.Logon(the_status);
    User::WaitForRequest(the_status);
    ...
    ...// prepare for a long wait
    ...
    TInt changes = the_status.Int();
    if (changes & EChangesSystemTime)
    {
    // handle a change to system time
    }
    if (changes & EChanges EChangesLocale)
    {
    // handle a change to locale
    }
    ...
    the_notifier.Close();
    ...
    }

    This notifier can tell me, when time on device is changed. But it can't tell me how exactly.

    I have stored time values. When I send time to my server, I need to send seconds, passed since event happened.
    When user changeds time, my time values stored in UTC become invalid.
    I need to correct them, and I just don't have enough info to do this. When time chenged, I need to know both values: time before, and time after :/

  5. #5
    Super Contributor
    Join Date
    Nov 2004
    Location
    Wiltshire, UK
    Posts
    3,644

    Re: Time change protection

    I can't see why your values in UTC would be become invalid, or am I missing something.
    Download Symbian OS now! [url]http://developer.symbian.org[/url]

  6. #6
    Regular Contributor
    Join Date
    Jul 2007
    Posts
    161

    Re: Time change protection

    This can happen in two cases:
    1) When date was wrong before correction. In this case difference between
    utc time when event was recorded
    and
    utc time taken in exaclty moment of send
    will be different from actual number of seconds, when event was recorded. It will bi shifted on exactly number of seconds on which user had shifted phone time.
    2) When date becomes wrong after correction. This is a previous case vise-versa.
    3) The cases when data was wrong and remains unchanged work fine. And of cause when date is ok, and is not changed are also fine.

    If only I could get difference between last time value and new time value! But in this case even device tick counter doesnt work - it also changes with time change.

  7. #7
    Nokia Developer Moderator
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    28,672

    Re: Time change protection

    If you provide "your" UTC time to the server, it can track its possible changes, and modify timestamps of events accordingly (especially if you also upload if a given timestamp happened before the last time modification - so it has to be compared to the last "your UTC" time uploaded - or it has happened after - so it has to be compared to the currently uploaded "your UTC" time).

    In fact it is rather unclear what you are trying to achieve.

  8. #8
    Super Contributor
    Join Date
    Nov 2004
    Location
    Wiltshire, UK
    Posts
    3,644

    Re: Time change protection

    How would you know the date was wrong before the correction, unless you check it with some external source.
    I still believe the best thing to do is send down the UTC device time + all your data and then let the server compensate each entry
    You can also start by getting the utc time when the app first starts and remembering it and then keep a running track of UTC changes each time the time is reported as changed.

    From 9.4 there is new User::SetHomeTimeSecure but again it is not sufficient as it is still synchronized with an external source.
    Download Symbian OS now! [url]http://developer.symbian.org[/url]

  9. #9
    Regular Contributor
    Join Date
    Jul 2007
    Posts
    161

    Re: Time change protection

    If you provide "your" UTC time to the server
    I send not my utc value, but difference between time of event(device clock) and current time (device clock)
    That's why I don't need correct time on device at all.
    I just need to hadle time changes somehow.
    Because of the fact that I store time in UTC(device clock) in memory, this values is not changed when user changes time on cellular. That's why when I send date to server (seconds, passed after that event) it is incorrect.
    Last edited by StasV; 2009-02-12 at 11:39.

  10. #10
    Nokia Developer Moderator
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    28,672

    Re: Time change protection

    Quote Originally Posted by StasV View Post
    I send not my utc value, but difference between time of event(device clock) and current time (device clock)
    That's why I don't need correct time on device at all.
    If you do not need to correct anything, you are obviously ready.

    If you still feel that something goes bad, you might consider thinking about the suggestion of storing timestamps instead of time intervals. You can only get the "new now" only, more or less the moment of setting the new time. But you can not get the "old" time of changing the time - however the server could attempt to compensate the values using its own untampered clock.
    Viability depends on your task a lot, e.g. what kind of intervals you are tracking, what precision is required, how does the frequency of sending data to the server and the frequency of changing the local time relate to each other.

  11. #11
    Super Contributor
    Join Date
    Nov 2004
    Location
    Wiltshire, UK
    Posts
    3,644

    Re: Time change protection

    Ok, so I see the problem, you don't want UTC you want the number of seconds since a fixed point in time, irrespective of how the time changes on the device.

    The bad news is I don't think there is a way of doing this short of hacking around with NTickCount which does keep track even when the device is powered down.

    As I said from 5th edition, the secure time API might be good enough for you (I'm not sure how it handles drift or even if it cares. There is more documnetation on this in the SDN++ portal if you are a member
    Download Symbian OS now! [url]http://developer.symbian.org[/url]

  12. #12
    Regular Contributor
    Join Date
    Jul 2007
    Posts
    161

    Re: Time change protection

    I have already tried NTickCount count. It starts counting not from zero on device start and appears to be dependent from current time! I have to do something else! I am afraid that the only way to get correct time difference is to take time snapshots every second. How much will this affect performance of device?

  13. #13
    Super Contributor
    Join Date
    Nov 2004
    Location
    Wiltshire, UK
    Posts
    3,644

    Re: Time change protection

    I was proposing syncking the tickcount with the UTC time. Remember you need to consider the TickPeriod as well when calculating time.


    You are also going to significantly impact battery performance doing it this was and depending on the device, amount of data and processor load this may also impact usability.
    Download Symbian OS now! [url]http://developer.symbian.org[/url]

  14. #14
    Regular Contributor
    Join Date
    Jul 2007
    Posts
    161

    Re: Time change protection

    I was proposing syncking the tickcount with the UTC time. Remember you need to consider the TickPeriod as well when calculating time.
    I tried this thing before postin to this forum my question (with tick period, etc.), but unfortunately, I failed to get difference, because tick clock also affected by time change (at least for 2x, didin't checked 3x). Tick count also starts from non-zero value with device start. And that value is probably timestamp...

    Once a second... Is it enough to do significant impact? It looks like last chance! Is there any time-independant timers which can tell me how much seconds passed?
    Last edited by StasV; 2009-02-13 at 09:46.

  15. #15
    Super Contributor
    Join Date
    Nov 2004
    Location
    Wiltshire, UK
    Posts
    3,644

    Re: Time change protection

    As I said, Kernel side or from fifth edition only.

    Also remember user side time is going to get adjusted by the kernel anyway to account for clock skew.
    Chapter 5.5 of Symbian OS internals covers this in a lot of detail.
    Download Symbian OS now! [url]http://developer.symbian.org[/url]

Similar Threads

  1. get log local time ?
    By ali3635 in forum Symbian
    Replies: 10
    Last Post: 2008-10-21, 04:28
  2. CPU time and time execution of a function
    By olfasupcom in forum Symbian
    Replies: 5
    Last Post: 2007-06-12, 14:12
  3. how to change caption text in run time
    By kain64bt in forum Symbian
    Replies: 3
    Last Post: 2007-03-02, 07:26
  4. Bizarre calendar/time zone change handling in Nokia 9500
    By noetus in forum General Development Questions
    Replies: 0
    Last Post: 2005-09-19, 19:27
  5. How to get correct time.
    By dzaga in forum Mobile Java General
    Replies: 2
    Last Post: 2003-08-06, 22:03

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×