×

Discussion Board

Results 1 to 9 of 9
  1. #1
    Registered User
    Join Date
    Sep 2003
    Posts
    77

    How to determine if daylight saving time is active?

    I want to determine if daylight saving time (DST) is active on a certain date.
    From my understanding of the Python documentation the last tupel element returned by time.localtime() should be '1' if DST is active and '0' if DST is not active. But I get '-1' all time.
    Any hints?

    TIA Martin

  2. #2
    Nokia Developer Champion
    Join Date
    Feb 2008
    Location
    Ahmedabad, Gujarat, India
    Posts
    3,852

    Re: How to determine if daylight saving time is active?

    hi dehlerm
    can u show the code plz.
    there can be a error in ur code.
    thanks

  3. #3
    Nokia Developer Moderator
    Join Date
    Oct 2007
    Location
    Deva, Romania
    Posts
    3,471

    Re: How to determine if daylight saving time is active?

    I too get -1 for time.localtime()'s last element on the phone, but on the PC it works. You can use time.daylight which will be 1 if DST is on and 0 if not. It works on the phone.

  4. #4
    Registered User
    Join Date
    Sep 2003
    Posts
    77

    Re: How to determine if daylight saving time is active?

    @gaba88
    code is rather simple:
    Code:
    import time
    time.localtime()
    @bogdan.galiceanu
    Do you mean S60 SDK emulator with 'on the PC', or Python on PC?
    My understanding of time.daylight is that it returns 1 if DST is valid for the actual timezone, but doesn't differentiate if DST is active on a given date. E.g. when the phone is set to a mid europe timezone time.daylight always returns 1 regardless if it's january (DST not active) or june (DST active).

  5. #5
    Nokia Developer Moderator
    Join Date
    Oct 2007
    Location
    Deva, Romania
    Posts
    3,471

    Re: How to determine if daylight saving time is active?

    Ah, I guess I misunderstood what you wanted. Sorry.
    And by "on the PC" I mean Python on the PC (the IDLE console).

  6. #6
    Regular Contributor
    Join Date
    Dec 2007
    Location
    India
    Posts
    133

    Re: How to determine if daylight saving time is active?

    Quote Originally Posted by dehlerm View Post
    I want to determine if daylight saving time (DST) is active on a certain date.
    From my understanding of the Python documentation the last tupel element returned by time.localtime() should be '1' if DST is active and '0' if DST is not active. But I get '-1' all time.
    Any hints?

    TIA Martin
    dehlem, last tupel element returned by time.localtime() is -1 for me too, I think the DST status is returned by and it depends on the timezone that is currently selected.

    Try it with other time zones, May be it will return an expected value.
    Kandyfloss

    V 7.0642.0
    18-10-06
    RH-51
    Nokia 7610

  7. #7
    Super Contributor
    Join Date
    Mar 2003
    Location
    Espoo, Finland
    Posts
    976

    Re: How to determine if daylight saving time is active?

    Quote Originally Posted by dehlerm View Post
    My understanding of time.daylight is that it returns 1 if DST is valid for the actual timezone, but doesn't differentiate if DST is active on a given date. E.g. when the phone is set to a mid europe timezone time.daylight always returns 1 regardless if it's january (DST not active) or june (DST active).
    Here's the documentation, maybe it helps:
    DST (Daylight Savings Time) flag (-1, 0 or 1)

    If the DST flag is 0, the time is given in the regular time zone;
    if it is 1, the time is given in the DST time zone;
    if it is -1, mktime() should guess based on the date and time.
    Returned date/time is automatically adjusted to DST and thus you get "correct" value all the time. But this was not what you were looking for? You wanted to know whether given date belongs to DST period or not?

    Cheers,

    --jouni

  8. #8
    Registered User
    Join Date
    Sep 2003
    Posts
    77

    Re: How to determine if daylight saving time is active?

    Quote Originally Posted by JOM View Post
    You wanted to know whether given date belongs to DST period or not?
    Indeed this is what I want to know ;-)
    I'm reading calls from the log with the logs modul. The logs modul seems to give timestamps in UTC. Now I want to display them as correct local time and therefore have to add the offset from UTC to local time.

    As far as I understand time.timezone gives the offset to local time when DST is not active and time.altzone gives the offset when DST is active. What misses now is to know if DST is active on a given date. And there the ninth tupel element of time.localtime() is the only way -I'm aware of- to determine if DST is active on a given date. With Python 2.2 on the PC (IDLE console) everything works like expected.

    @kandyfloss
    I tried several time zones, but never got another return value for the ninth tupel element of time.localtime() than '-1'...

  9. #9
    Super Contributor
    Join Date
    Mar 2003
    Location
    Espoo, Finland
    Posts
    976

    Re: How to determine if daylight saving time is active?

    Quote Originally Posted by dehlerm View Post
    I'm reading calls from the log with the logs modul. The logs modul seems to give timestamps in UTC. Now I want to display them as correct local time and therefore have to add the offset from UTC to local time.
    I am so happy I have nothing to do with your project Calculating leap-year isn't too easy, when you go back to history, but it sure is peace of cake compared trying to guess when DST starts/stops! It depends on year and location, both at the same time. There are no rules and no algorithm, it's a chaos. Some background:

    http://www.timeanddate.com/time/aboutdst.html

    My advice: try to convince Powers That Be to forget the whole feature and focus on something which can actually be done.

    Sorry,

    --jouni

Similar Threads

  1. Replies: 4
    Last Post: 2007-11-26, 13:41
  2. Active Object do not Work
    By vitormcruz in forum Symbian C++
    Replies: 4
    Last Post: 2007-11-13, 15:21
  3. Replies: 2
    Last Post: 2007-10-05, 20:40
  4. Replies: 2
    Last Post: 2003-09-01, 22:15
  5. SMS time stamp format with time zone parameter?
    By turunhe in forum General Messaging
    Replies: 1
    Last Post: 2002-06-11, 07:00

Posting Permissions

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