 |
|
 |
|
|
 |
localtime isdst and timezone - what does isdst mean exactly? |
 |
 |
|
|
07-01-04 08:20 AM
If I call localtime(), it returns a tm struct. I have a question about
the returned timezone, and specifically isdst.
I am technically in Mountain time, which is GMT-7. Right now, it is in
daylight savings time, so tm.timezone( I know, it's not the actual name,
but I forget what it is, I would have to look it up, you know what I
mean, and it's not important.) ... anyway, tm.timezone contains GMT-6,
which reflects the fact that I am currently in DST. Also, tm.isdst=1.
The question: isdst=1 means that timezone has ALREADY been modified to
reflect daylight savings time, right?
Some people think it means:
if( isdst == 1 )
subtract another hour from timezone because we are in DST
I think it means:
if( isdst == 1 &&
we want the *actual* timezone and not the DST modified timezone)
add an hour to timezone
Which is correct?
Thanks!
David Logan
[ Post a follow-up to this message ]
|
|
|
 |
|
 |
|
 |
|
|
 |
Re: localtime isdst and timezone - what does isdst mean exactly? |
 |
 |
|
|
07-01-04 10:58 PM
David Logan <djlogan2@comcast.net> writes:
> If I call localtime(), it returns a tm struct. I have a question about
> the returned timezone, and specifically isdst.
>
> I am technically in Mountain time, which is GMT-7. Right now, it is in
> daylight savings time, so tm.timezone( I know, it's not the actual
> name, but I forget what it is, I would have to look it up, you know
> what I mean, and it's not important.) ... anyway, tm.timezone contains
> GMT-6, which reflects the fact that I am currently in DST. Also,
> tm.isdst=1.
>
> The question: isdst=1 means that timezone has ALREADY been modified to
> reflect daylight savings time, right?
>
> Some people think it means:
> if( isdst == 1 )
> subtract another hour from timezone because we are in DST
>
> I think it means:
> if( isdst == 1 &&
> we want the *actual* timezone and not the DST modified timezone)
> add an hour to timezone
I don't know what you mean by this. The *timezone* is MST7MDT. That
means that, when DST isn't in effect the *offset* is GMT-7, and when
it is in effect the offset is GMT-6.
> Which is correct?
Neither (use the man page, Luke...)
tm_isdst
A flag that indicates whether daylight saving time is in
effect at the time described. The value is positive if
daylight saving time is in effect, zero if it is not,
and negative if the information is not available.
You don't add or subtract anything, it just tells you if DST is in
effect.
Joe
--
Folks who don't know why America is the Land of Promise should be here
during an election campaign.
-- Milton Berle
[ Post a follow-up to this message ]
|
|
|
 |
|
 |
|
 |
|
|
 |
Re: localtime isdst and timezone - what does isdst mean exactly? |
 |
 |
|
|
07-01-04 10:58 PM
joe@invalid.address wrote:
> David Logan <djlogan2@comcast.net> writes:
>
>
>
>
> I don't know what you mean by this. The *timezone* is MST7MDT. That
> means that, when DST isn't in effect the *offset* is GMT-7, and when
> it is in effect the offset is GMT-6.
>
>
>
>
> Neither (use the man page, Luke...)
>
> tm_isdst
> A flag that indicates whether daylight saving time is in
> effect at the time described. The value is positive if
> daylight saving time is in effect, zero if it is not,
> and negative if the information is not available.
>
> You don't add or subtract anything, it just tells you if DST is in
> effect.
>
> Joe
I did read the man page. I understand it says "true if DST is in
effect." What is NOT clear is what the timezone value returns when isdst=1.
You obviously are not understanding my question. Let me see if I can
make it a bit more concrete. I am using a piece of software that
contains this code:
time_t temp = time(0);
struct tm *tms = localtime(&temp);
timezone = -(tms->tm_gmtoff);
isdst = tms->tm_isdst;
return (timezone - (isdst ? 3600 : 0));
The author of this code assumes is that tm_gmtoff will always be GMT-7,
because that is my timezone. This means that tm_gmtoff=25200 (seconds
from UTC.) What the author also assumes is that when tm_isdst==1 that he
must adjust tm_gmtoff by another hour (timezone-3600) in order to get
the correct GMT-6 (21600) offset returned.
I believe that tm_gmtoff already contains the correct number of seconds
different from UTC (GMT-6, or 21600). I believe that isdst==1 means that
tm_gmtoff does NOT return the the timezone, but instead returns the
DST MODIFIED timezone.
So, as I tried to explain the first time. Which version is correct?
Version 1)
Actual timezone: GMT-7
Actual offset seconds in non DST: 25200
Timezone during DST: GMT-6
Actual offset seconds during DST: 21600
During non-DST, tm_gmtoff returns: 25200
During DST, tm_gmtoff returns: 25200
Version 2)
Actual timezone: GMT-7
Actual offset seconds in non DST: 25200
Timezone during DST: GMT-6
Actual offset seconds during DST: 21600
During non-DST, tm_gmtoff returns: 25200
During DST, tm_gmtoff returns: 21600
So basically, will tm_gmtoff return a different value depending upon
isdst==1 or not?
David Logan
[ Post a follow-up to this message ]
|
|
|
 |
|
 |
|
 |
|
|
 |
Re: localtime isdst and timezone - what does isdst mean exactly? |
 |
 |
|
|
07-01-04 10:58 PM
David logan <david_logan@g1.com> writes:
> joe@invalid.address wrote:
[vbcol=seagreen]
> I did read the man page. I understand it says "true if DST is in
> effect." What is NOT clear is what the timezone value returns when
> isdst=1.
>
> You obviously are not understanding my question. Let me see if I can
> make it a bit more concrete. I am using a piece of software that
> contains this code:
>
> time_t temp = time(0);
> struct tm *tms = localtime(&temp);
> timezone = -(tms->tm_gmtoff);
> isdst = tms->tm_isdst;
> return (timezone - (isdst ? 3600 : 0));
The tm_gmtoff field isn't standard, so I'm a little unsure about what
it's supposed to mean on your system. The only system I have access to
at the moment which has that is FreeBSD 4.10-RELEASE. I'll work on the
assumption that's what you're using.
> The author of this code assumes is that tm_gmtoff will always be
> GMT-7, because that is my timezone.
Again, GMT-7 is an *offset*, not a timezone. See
[url]http://www.opengroup.org/onlinepubs/009695399/basedefs/xbd_chap08.html#tag_08_03[/
url]
for the POSIX definition of timezone strings.
Assuming what you mean is that you want to know what the current
offset from GMT is, the tm_gmtoff field should give it to you with no
manipulation. I don't see how you would know how much to subtract or
add anyway. The DST offset change isn't always an hour, it can be
anything the local government decides it should be. For example,
here's an excerpt from the Solaris tzset() man page:
An example of a southern hemisphere setting such as the Cook
Islands could be
KDT9:30KST10:00,63/5:00,302/20:00
Which means (allowing for the typo in the man page) that the
difference in offset between STD and DST is 30 minutes, not an hour.
> This means that tm_gmtoff=25200
> (seconds from UTC.) What the author also assumes is that when
> tm_isdst==1 that he must adjust tm_gmtoff by another hour
> (timezone-3600) in order to get the correct GMT-6 (21600) offset
> returned.
I don't think that's right, since you can't know what the offset
should be. The only thing that makes sense to me is that it's telling
you what the current offset is, which means you don't have to do
anything with it.
> I believe that tm_gmtoff already contains the correct number of
> seconds different from UTC (GMT-6, or 21600). I believe that isdst==1
> means that tm_gmtoff does NOT return the the timezone, but instead
> returns the DST MODIFIED timezone.
I guess I'm still confused about what you're trying to do because
you're using the word timezone incorrectly. If what you're trying to
do is determine what the standard time offset would be when DST is in
effect, then I don't know how you'd do that offhand, since the struct
only gives you the current offset, and the difference between the
current offset and the standard offset could be pretty much anything
(although it's usually an hour). You don't have enough information
there.
> So basically, will tm_gmtoff return a different value depending upon
> isdst==1 or not?
Try it.
#include <stdio.h>
#include <time.h>
int main()
{
time_t temp = time(0);
struct tm *tms = localtime(&temp);
printf("tm_isdst = %d\n", tms->tm_isdst);
printf("tm_gmtoff = %d\n", tms->tm_gmtoff);
}
fbsd$ TZ=MST7DST ./a.out
tm_isdst = 1
tm_gmtoff = -21600
fbsd$ TZ=MST7 ./a.out
tm_isdst = 0
tm_gmtoff = -25200
Looks like it gives the current offset to me.
Joe
--
Folks who don't know why America is the Land of Promise should be here
during an election campaign.
-- Milton Berle
[ Post a follow-up to this message ]
|
|
|
 |
|
 |
|
 |
|
|
 |
Re: localtime isdst and timezone - what does isdst mean exactly? |
 |
 |
|
|
07-01-04 10:58 PM
joe@invalid.address wrote:
> David logan <david_logan@g1.com> writes:
>
>
>
>
>
>
> The tm_gmtoff field isn't standard, so I'm a little unsure about what
> it's supposed to mean on your system. The only system I have access to
> at the moment which has that is FreeBSD 4.10-RELEASE. I'll work on the
> assumption that's what you're using.
>
>
>
>
> Again, GMT-7 is an *offset*, not a timezone. See
Yes, I know. I am using timezone and GMT offset interchangeably, which
technically is not true, but true enough in my head to use them that
way. Sorry about that.
> http://www.opengroup.org/onlinepubs...g_08_03
> for the POSIX definition of timezone strings.
>
> Assuming what you mean is that you want to know what the current
> offset from GMT is, the tm_gmtoff field should give it to you with no
> manipulation. I don't see how you would know how much to subtract or
> add anyway. The DST offset change isn't always an hour, it can be
> anything the local government decides it should be.
Sure enough, you hit it right on the head. It can be 15 minutes to god
knows what. So tm_gmtoff would always need to return the offset
regardless. That also means that the authors code is incorrect in two
ways. It assumes a one hour difference, and also assumes that tm_gmtoff
is inaccurate if isdst==1.
> For example,
> here's an excerpt from the Solaris tzset() man page:
>
> An example of a southern hemisphere setting such as the Cook
> Islands could be
>
> KDT9:30KST10:00,63/5:00,302/20:00
>
> Which means (allowing for the typo in the man page) that the
> difference in offset between STD and DST is 30 minutes, not an hour.
>
>
>
>
> I don't think that's right, since you can't know what the offset
> should be. The only thing that makes sense to me is that it's telling
> you what the current offset is, which means you don't have to do
> anything with it.
>
>
>
>
> I guess I'm still confused about what you're trying to do because
> you're using the word timezone incorrectly. If what you're trying to
> do is determine what the standard time offset would be when DST is in
> effect, then I don't know how you'd do that offhand, since the struct
> only gives you the current offset, and the difference between the
> current offset and the standard offset could be pretty much anything
> (although it's usually an hour). You don't have enough information
> there.
>
>
>
>
> Try it.
>
> #include <stdio.h>
> #include <time.h>
> int main()
> {
> time_t temp = time(0);
> struct tm *tms = localtime(&temp);
> printf("tm_isdst = %d\n", tms->tm_isdst);
> printf("tm_gmtoff = %d\n", tms->tm_gmtoff);
> }
>
> fbsd$ TZ=MST7DST ./a.out
> tm_isdst = 1
> tm_gmtoff = -21600
> fbsd$ TZ=MST7 ./a.out
> tm_isdst = 0
> tm_gmtoff = -25200
>
> Looks like it gives the current offset to me.
>
> Joe
Thanks! I'll submit a bug.
David Logan
[ Post a follow-up to this message ]
|
|
|
 |
|
 |
|
 |
|
|
|
Sponsored Links |
 |
 |
|
|
 |
All times are GMT. The time now is 09:14 AM. |
 |
|
|
 |
|
 |
|
|
 |
|
Forum Rules:
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
|
HTML code is OFF
vB code is ON
Smilies are ON
[IMG] code is OFF
|
|
|
|
Medical and Health forum | Computer Games Reviews | Graphics design forum
|
 |
|
 |
|