I'm forwarding this message from Zhenqiang Fan, who is not on the time zone mailing list. Those of you who are on the time zone mailing list should direct replies appropriately. --ado -----Original Message----- From: Fan_Zhenqiang@emc.com [mailto:Fan_Zhenqiang@emc.com] Sent: Tuesday, April 03, 2007 3:21 PM To: tz@lecserver.nci.nih.gov Cc: Fan_Zhenqiang@emc.com Subject: Questions Hi Could any body kindly answer my question below: Is there a function (in any of these source files) that takes a date/time value and tells whether the date/time is daylight saving time? Thanks so much in advance, Zhenqiang Fan
From: Fan_Zhenqiang@emc.com [mailto:Fan_Zhenqiang@emc.com] Sent: Tuesday, April 03, 2007 3:21 PM
Is there a function (in any of these source files) that takes a date/time value and tells whether the date/time is daylight saving time?
If T is a time_t value, and if localtime(&T) returns non-null, then localtime(&T)->tm_isdst should tell you what you want to know (about T). If the date/time value is some string like "2007-11-04 01:30" then you're out of luck, because that time stamp is ambiguous in most of North America: it might be DST, and it might be standard time.
Hi Paul, Thank you so much for replying my mail. What if a time zone is specified together with the date/time value? For instance, is there any function that call whether "2007-11-04 01:30 PST" is DST? My current project needs to do conversions between local time and UTC. For date/time between 1970 and 2038, converting local time (in struct tm) to UTC can be done by calling mktime() and then gmtime(). But converting UTC to local time is not that straight forward. In addition, for date/time falling outside of (1970, 2038), we have no way to determine whether the given data/time value is DST or not and thus cannot do conversion correctly. That's why I was asking the original question. Any ideas would be sincerely appreciated. Zhenqiang Fan -----Original Message----- From: Paul Eggert [mailto:eggert@CS.UCLA.EDU] Sent: Tuesday, April 03, 2007 4:30 PM To: Fan, Zhenqiang Cc: tz@elsie.nci.nih.gov Subject: Re: FW: Questions
From: Fan_Zhenqiang@emc.com [mailto:Fan_Zhenqiang@emc.com] Sent: Tuesday, April 03, 2007 3:21 PM
Is there a function (in any of these source files) that takes a date/time value and tells whether the date/time is daylight saving time?
If T is a time_t value, and if localtime(&T) returns non-null, then localtime(&T)->tm_isdst should tell you what you want to know (about T). If the date/time value is some string like "2007-11-04 01:30" then you're out of luck, because that time stamp is ambiguous in most of North America: it might be DST, and it might be standard time.
Fan_Zhenqiang@emc.com writes:
What if a time zone is specified together with the date/time value? For instance, is there any function that call whether "2007-11-04 01:30 PST" is DST?
Sorry, no; in general that's not possible, as in some locations the same abbreviation is used for both standard and daylight time. One could do a reasonable job in most cases, as in the other problems you mentioned; it shouldn't be that hard, but the functions aren't there now.
2007-04-04T13:41:01 Paul Eggert:
Fan_Zhenqiang@emc.com writes:
What if a time zone is specified together with the date/time value? For instance, is there any function that call whether "2007-11-04 01:30 PST" is DST?
Sorry, no; in general that's not possible, as in some locations the same abbreviation is used for both standard and daylight time.
Not to mention, by PST do you mean Pacific Standard time or Pitcairn Standard Time? The short abbreviations are now where near unique distinguishers. -Bennett
On Wed, 2007-04-04 at 10:41 -0700, Paul Eggert wrote:
Fan_Zhenqiang@emc.com writes:
What if a time zone is specified together with the date/time value? For instance, is there any function that call whether "2007-11-04 01:30 PST" is DST?
Sorry, no; in general that's not possible, as in some locations the same abbreviation is used for both standard and daylight time. One could do a reasonable job in most cases, as in the other problems you mentioned; it shouldn't be that hard, but the functions aren't there now.
Bottom line, you need to know the *context*( the geographic location ) of the date, hence the Country/City TZ value information, and not the abbreviation ( DST, PST, WAT, ... ). Then, as explained earlier, use localtime() returned 'struct tm'->tm_isdst value. Unfortunately, the %Z format still gives the abbreviation, not the time zone itself. Briefly. To compute isdst, you need date and TZ( not its abbreviation ). -- ----------------------------- Me: If I can , I want. Not me: If I want, I can. A boss: If I want, you can. -----------------------------
Hi Michael, Thank you for your reply. Sorry that I used ambiguous example. What I really asked is: Is there a function that takes a time zone, say America/Los_Angles, and a date value such as "2007-11-04 01:30", and tells whether the given date/time value is a DST in that time zone? If no, how easy is it to write such a function? Thanks again. Zhenqiang Fan -----Original Message----- From: Michel Bourget [mailto:michel@sgi.com] Sent: Wednesday, April 04, 2007 12:39 PM To: tz@elsie.nci.nih.gov Cc: Fan, Zhenqiang; tz@lecserver.nci.nih.gov Subject: Re: FW: Questions On Wed, 2007-04-04 at 10:41 -0700, Paul Eggert wrote:
Fan_Zhenqiang@emc.com writes:
What if a time zone is specified together with the date/time value? For instance, is there any function that call whether "2007-11-04 01:30 PST" is DST?
Sorry, no; in general that's not possible, as in some locations the same abbreviation is used for both standard and daylight time. One could do a reasonable job in most cases, as in the other problems you mentioned; it shouldn't be that hard, but the functions aren't there now.
Bottom line, you need to know the *context*( the geographic location ) of the date, hence the Country/City TZ value information, and not the abbreviation ( DST, PST, WAT, ... ). Then, as explained earlier, use localtime() returned 'struct tm'->tm_isdst value. Unfortunately, the %Z format still gives the abbreviation, not the time zone itself. Briefly. To compute isdst, you need date and TZ( not its abbreviation ). -- ----------------------------- Me: If I can , I want. Not me: If I want, I can. A boss: If I want, you can. -----------------------------
On Wed, 2007-04-04 at 18:00 -0400, Fan_Zhenqiang@emc.com wrote:
Hi Michael, Thank you for your reply. Sorry that I used ambiguous example. What I really asked is:
Is there a function that takes a time zone, say America/Los_Angles, and a date value such as "2007-11-04 01:30", and tells whether the given date/time value is a DST in that time zone? If no, how easy is it to write such a function?
No, the function is not available. Given a known format , you can convert any ascii date-time-whatnot to a 'struct tm' data with strptime(); then use localtime() recipe given previously. Also account for TZ and and print out tm_isdst. It looks easy. Good luck !
Thanks again.
Zhenqiang Fan
-----Original Message----- From: Michel Bourget [mailto:michel@sgi.com] Sent: Wednesday, April 04, 2007 12:39 PM To: tz@elsie.nci.nih.gov Cc: Fan, Zhenqiang; tz@lecserver.nci.nih.gov Subject: Re: FW: Questions
On Wed, 2007-04-04 at 10:41 -0700, Paul Eggert wrote:
Fan_Zhenqiang@emc.com writes:
What if a time zone is specified together with the date/time value? For instance, is there any function that call whether "2007-11-04 01:30 PST" is DST?
Sorry, no; in general that's not possible, as in some locations the same abbreviation is used for both standard and daylight time. One could do a reasonable job in most cases, as in the other problems you mentioned; it shouldn't be that hard, but the functions aren't there now.
Bottom line, you need to know the *context*( the geographic location ) of the date, hence the Country/City TZ value information, and not the abbreviation ( DST, PST, WAT, ... ). Then, as explained earlier, use localtime() returned 'struct tm'->tm_isdst value. Unfortunately, the %Z format still gives the abbreviation, not the time zone itself.
Briefly. To compute isdst, you need date and TZ( not its abbreviation ).
-- ----------------------------- Me: If I can , I want. Not me: If I want, I can. A boss: If I want, you can. -----------------------------
participants (5)
-
Bennett Todd -
Fan_Zhenqiang@emc.com -
Michel Bourget -
Olson, Arthur David (NIH/NCI) [E] -
Paul Eggert