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

Discussion in 'C Programming' started by Hill Pang, Dec 19, 2012.

  1. Hill Pang

    Hill Pang Guest

    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
    Hill Pang, Dec 19, 2012
    #1
    1. Advertising

  2. Hill Pang

    Shao Miller Guest

    On 12/19/2012 02:56, Hill Pang wrote:
    > 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
    Shao Miller, Dec 19, 2012
    #2
    1. Advertising

  3. Hill Pang

    Shao Miller Guest

    On 12/19/2012 04:45, Hill Pang wrote:
    > On Wednesday, December 19, 2012 5:04:59 PM UTC+8, Shao Miller wrote:
    >> On 12/19/2012 02:56, Hill Pang wrote:
    >>> 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?
    >>

    > "%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
    Shao Miller, Dec 19, 2012
    #3
  4. Hill Pang

    James Kuyper Guest

    On 12/19/2012 02:56 AM, Hill Pang wrote:
    > 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.
    --
    James Kuyper
    James Kuyper, Dec 19, 2012
    #4
  5. Hill Pang

    Hill Pang Guest

    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.

    On Wednesday, December 19, 2012 4:25:31 AM UTC-8, James Kuyper wrote:
    > On 12/19/2012 02:56 AM, Hill Pang wrote:
    >
    > > 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.
    >
    > --
    >
    > James Kuyper
    Hill Pang, Dec 19, 2012
    #5
  6. Hill Pang

    Ike Naar Guest

    On 2012-12-19, Hill Pang <> wrote:
    > 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
    Ike Naar, Dec 19, 2012
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Davide
    Replies:
    0
    Views:
    1,376
    Davide
    Oct 30, 2003
  2. =?Utf-8?B?anVubGlh?=
    Replies:
    2
    Views:
    576
    =?Utf-8?B?anVubGlh?=
    May 20, 2005
  3. milkyway

    Miminmize window affects the page

    milkyway, Sep 27, 2005, in forum: ASP .Net
    Replies:
    1
    Views:
    325
    David Ross
    Sep 27, 2005
  4. John Dalberg
    Replies:
    0
    Views:
    381
    John Dalberg
    Dec 20, 2005
  5. Robm
    Replies:
    6
    Views:
    2,497
    Rod Pemberton
    Mar 25, 2006
Loading...

Share This Page