timezone programming

  • Thread starter Larry W. Virden
  • Start date
L

Larry W. Virden

I have a need to printf the time, date and daylight savings time
indicator for a series of countries (and states when there is more
than one timezone in the country), given a specific date and time.

Does anyone have a pointer to an example of how to make proper use of
the time zone databases to find the right time, given a location? I
suspect that I will have to hand code the mapping of the locations to
timezones, and then just convert the time to the various timezones,
right?
 
T

Thomas Schulz

I have a need to printf the time, date and daylight savings time
indicator for a series of countries (and states when there is more
than one timezone in the country), given a specific date and time.

Does anyone have a pointer to an example of how to make proper use of
the time zone databases to find the right time, given a location? I
suspect that I will have to hand code the mapping of the locations to
timezones, and then just convert the time to the various timezones,
right?


Not quite the format you are asking for, but the zdump utility should
get you the information you need. For instance, 'zdump -v US/Eastern'
will show all or the daylight savings time start and stop times along
with the offset from UTC from 1918 to current. You can see what
timezones are available by looking in /usr/share/lib/zoneinfo.
 
T

Thomas Schulz

Not quite the format you are asking for, but the zdump utility should
get you the information you need. For instance, 'zdump -v US/Eastern'
will show all or the daylight savings time start and stop times along
with the offset from UTC from 1918 to current. You can see what
timezones are available by looking in /usr/share/lib/zoneinfo.
--

Also, if you get the Olson timecode source, you will have the source for
the zdump utility. You could modify it to do what you want.
 
U

user923005

I have a need to printf the time, date and daylight savings time
indicator for a series of countries (and states when there is more
than one timezone in the country), given a specific date and time.

Does anyone have a pointer to an example of how to make proper use of
the time zone databases to find the right time, given a location? I
suspect that I will have to hand code the mapping of the locations to
timezones, and then just convert the time to the various timezones,
right?


The PostgreSQL database has portable C timezone stuff in it.
 
K

Keith Thompson

Larry W. Virden said:
I have a need to printf the time, date and daylight savings time
indicator for a series of countries (and states when there is more
than one timezone in the country), given a specific date and time.

Does anyone have a pointer to an example of how to make proper use of
the time zone databases to find the right time, given a location? I
suspect that I will have to hand code the mapping of the locations to
timezones, and then just convert the time to the various timezones,
right?

Standard C has little or no support for timezones, so this isn't
really a question for comp.lang.c. Followups redirected.
 
C

CBFalconer

Thomas said:
.... snip ...

Not quite the format you are asking for, but the zdump utility
should get you the information you need. For instance, 'zdump -v
US/Eastern' will show all or the daylight savings time start and
stop times along with the offset from UTC from 1918 to current.
You can see what timezones are available by looking in
/usr/share/lib/zoneinfo.

Doesn't work here for some reason. I have no such program
available as "zdump", and no such directory as "/usr/share/lib",
which effectively prevents that directory from containing a file
"zoneinfo". Do you think that might have anything to do with the
lack of definition of these things in the C standard? Is it
remotely possible that you have supplied off-topic and non-portable
information in a newsgroup (namely c.l.c) dedicated to the C
language?

Around here zdump needs to be followed by fflush(stdout).

--
<http://www.cs.auckland.ac.nz/~pgut001/pubs/vista_cost.txt>
<http://www.securityfocus.com/columnists/423>

"A man who is right every time is not likely to do very much."
-- Francis Crick, co-discover of DNA
"There is nothing more amazing than stupidity in action."
-- Thomas Matthews
 
R

Richard Tobin

CBFalconer said:
Doesn't work here for some reason. I have no such program
available as "zdump", and no such directory as "/usr/share/lib",
which effectively prevents that directory from containing a file
"zoneinfo". Do you think that might have anything to do with the
lack of definition of these things in the C standard? Is it
remotely possible that you have supplied off-topic and non-portable
information in a newsgroup (namely c.l.c) dedicated to the C
language?

Perhaps you didn't notice that the article you were replying to - and
your reply - were cross-posted to comp.unix.solaris?

-- Richard
 
G

Glenn

I have a need to printf the time, date and daylight savings time
indicator for a series of countries (and states when there is more
than one timezone in the country), given a specific date and time.

Does anyone have a pointer to an example of how to make proper use of
the time zone databases to find the right time, given a location? I
suspect that I will have to hand code the mapping of the locations to
timezones, and then just convert the time to the various timezones,
right?

I've asked a couple of times in this forum, without success, looking
for a package that will allow concurrent access to different timezones
in multiple threads. The ordinary system routines won't do, because
of their dependency on the shared global TZ environment. The lack
of response tells me that a full understanding of this issue is not
widespread.

I went looking for such a package. There don't seem to be
many, and there are still outstanding proposals to improve the
next revision of the C language standard. But as for practical
implementations one can use today ...

Boost::Date_Time is one such and its documentation is
extensive, but it's also impenetrable. I reject that package
until such time as there is enough readable tutorial material
that one is not stuck with essentially reverse engineering
the code.

It looks like I've found the solution by properly generalizing.
Timezone handling is a subset of the larger issue of i18n.
And the "International Components for Unicode" package
(http://icu.sourceforge.net/) is designed to cover that ground.
It has proper support for the Olson timezones, for concurrent
access to the same or different timezones by the same or
different threads, and support for the usual parsing and
formatting tasks.

It might not help you if you think you've already solved
your issue with the standard routines, but I thought I should
leave this breadcrumb behind for the next person to travel
this road.

Glenn
 

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,582
Members
45,065
Latest member
OrderGreenAcreCBD

Latest Threads

Top