How tm_isdst affects "%Z" specifier in function strftime()?

H

Hill Pang

In some implementation if it is set to -1, the generated string would be empty; but in some implementation, it has no affection based on my test result, for example, the glibc.
My question is which is right? or it is decided by implementation?
I checked C89/C99 standards, they are both not clear about this.

Thanks in advance.
Baoshan
 
S

Shao Miller

In some implementation if it is set to -1, the generated string
would be empty; but in some implementation, it has no affection
based on my test result, for example, the glibc.
My question is which is right? or it is decided by implementation?
I checked C89/C99 standards, they are both not clear about this.

What is the difference between "the generated string would be empty" and
"it has no affection"? Can you please describe the contrast between the
two a bit more with two sample outputs?

- Shao Miller
 
S

Shao Miller

"%Z" is to get the string of the time zone, "it has no affection" means
no matter if "tm_isdst" is set to -1 or not, the result is same, a
string of time zone would be generated.

Oops. It seems that you chose to "reply" instead of to "followup" or to
post to the news-group.

If no information is available about Daylight Saving Time status, the
implementation might still have knowledge of the time zone. If no
information is available about the time zone whatsoever, I'd expect the
empty string.

- Shao Miller
 
J

James Kuyper

In some implementation if it is set to -1, the generated string would be empty; but in some implementation, it has no affection based on my test result, for example, the glibc.
My question is which is right? or it is decided by implementation?
I checked C89/C99 standards, they are both not clear about this.

"The local time zone and Daylight Saving Time are
implementation-defined." (7.27.1p1)

"The value of tm_isdst is positive if Daylight Saving Time is in effect,
zero if Daylight Saving Time is not in effect, and negative if the
information is not available." (7.27.1p4) Setting tm_isdst to -1 means
that you don't know whether DST is in effect, but the implementation
might be able to figure it out for you.

"%Z is replaced by the locale’s time zone name or abbreviation, or by no
characters if no time zone is determinable." (7.27.3.5p3)
Whether or not the time zone can be determined therefore depends upon
the locale and the implementation.
 
H

Hill Pang

The connection between DST and time zone is still unclear for me, for the implementation in NETBSD, it has such code:

case 'Z':
#ifdef TM_ZONE
if (t->TM_ZONE != NULL)
pt = _add(t->TM_ZONE, pt, ptlim);
else
#endif /* defined TM_ZONE */
if (t->tm_isdst >= 0)
pt = _add(tzname[t->tm_isdst != 0],
pt, ptlim);
/*
** C99 says that %Z must be replaced by the
** empty string if the time zone is not
** determinable.
*/
continue;

I don't understand why DST would affect if time zone is determinable.
 
I

Ike Naar

The connection between DST and time zone is still unclear for me, for
the implementation in NETBSD, it has such code:

case 'Z':
#ifdef TM_ZONE
if (t->TM_ZONE != NULL)
pt = _add(t->TM_ZONE, pt, ptlim);
else
#endif /* defined TM_ZONE */
if (t->tm_isdst >= 0)
pt = _add(tzname[t->tm_isdst != 0],
pt, ptlim);
/*
** C99 says that %Z must be replaced by the
** empty string if the time zone is not
** determinable.
*/
continue;

I don't understand why DST would affect if time zone is determinable.

Daylight saving time may be encoded in the time zone acronym, e.g.

Yakutsk Time -> YAKT
Yakutsk Summer Time -> YAKST
 

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

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top