Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c > #74199

Re: strftime(3) and TZ

From Ben Bacarisse <ben.usenet@bsb.me.uk>
Newsgroups comp.lang.c
Subject Re: strftime(3) and TZ
Date 2015-10-29 19:53 +0000
Organization A noiseless patient Spider
Message-ID <87bnbhh2nv.fsf@bsb.me.uk> (permalink)
References <fac11cd6-ef06-4481-8e80-ab8a0a686628@googlegroups.com>

Show all headers | View raw


Francis Moreau <francis.moro@gmail.com> writes:

> I'm probably missing something but can'f find what.
>
> So my question is: strftime(3) isnt supposed to read TZ and to display
> time according to its value ?
>
> From the manpage:
>
>    ENVIRONMENT
>           The environment variables TZ and LC_TIME are used.

But does it say that they will override an explicit setting?  I would
hope they would not (and they don't).

> But I cant verify it with my dumb prog:
>
> $ cat strftime.c
> #include <time.h>
> #include <stdio.h>
> #include <stdlib.h>
>
> int
> main(int argc, char *argv[])
> {
>     char outstr[200];
>     time_t t;
>     struct tm tmp = {
> 	    .tm_sec = 2,
> 	    .tm_min = 54,
> 	    .tm_hour = 19,
> 	    .tm_mday = 29,
> 	    .tm_mon = 9,
> 	    .tm_year = 115,
> 	    .tm_wday = 4,
> 	    .tm_yday = 301,
> 	    .tm_isdst = 0,
> 	    .tm_gmtoff = 3600,
> 	    .tm_zone = "CET",

These last two are not standard C, and they don't even seem to be
standard POSIX extensions (I've not checked all versions) but they are,
I think, the root of the problem.  If you don't set them, the code works
as you want.

>     };
>
>     if (strftime(outstr, sizeof(outstr), argv[1], &tmp) == 0) {
>         fprintf(stderr, "strftime returned 0");
>         exit(EXIT_FAILURE);
>     }
>
>     printf("Result string is \"%s\"\n", outstr);
>     exit(EXIT_SUCCESS);
> }

<snip>
-- 
Ben.

Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

strftime(3) and TZ Francis Moreau <francis.moro@gmail.com> - 2015-10-29 12:10 -0700
  Re: strftime(3) and TZ Ben Bacarisse <ben.usenet@bsb.me.uk> - 2015-10-29 19:53 +0000
    Re: strftime(3) and TZ Francis Moreau <francis.moro@gmail.com> - 2015-10-30 00:26 -0700
      Re: strftime(3) and TZ Ben Bacarisse <ben.usenet@bsb.me.uk> - 2015-10-30 11:19 +0000
        Re: strftime(3) and TZ Francis Moreau <francis.moro@gmail.com> - 2015-10-30 09:06 -0700

csiph-web