chicken-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Chicken-users] choosing right timezone for future date


From: John Cowan
Subject: Re: [Chicken-users] choosing right timezone for future date
Date: Mon, 28 Jan 2008 17:27:57 -0500
User-agent: Mutt/1.5.13 (2006-08-11)

Graham Fawcett scripsit:

> My TZ is set properly, and using strace I see that the correct
> zoneinfo file is being accessed. "date +%Z" works properly. Any ideas?

The problem with your test program is that tm is uninitialized, which
strptime does not alter (since there is no zone information in the input)
and which causes strftime to bomb.  Using memset(&tm, 0, sizeof(tm))
causes %z to be +0000 (wrong) and %Z to be "EST" (correct).  So that's
not a feasible approach.

Here's a demo program that does work:

#include <stdio.h>
#include <string.h>
#include <time.h>

int main() {
  struct tm * tm;
  char buf[1000];
  time_t t;

  buf[0] = 0;
  t = time(NULL);
  tm = localtime(&t);
  strptime("2008-11-12 18:31:01", "%Y-%m-%d %H:%M:%S", tm);
  strftime(buf, sizeof(buf), "%d %b %Y %H:%M %z %Z", tm);
  puts(buf);
  return 0;
}

However, this doesn't really solve your problem, because it sets
the offset and tzname to the current values, not to the values in
effect at the time.

I admit I don't know how to make progress here.  Let me think on it.

-- 
John Cowan  address@hidden   http://www.ccil.org/~cowan
O beautiful for patriot's dream that sees beyond the years
Thine alabaster cities gleam undimmed by human tears!
America! America!  God mend thine every flaw,
Confirm thy soul in self-control, thy liberty in law!
        -- one of the verses not usually taught in U.S. schools




reply via email to

[Prev in Thread] Current Thread [Next in Thread]