dealing with timestamped data collected in one zone and reportedin another

M

Mark Seger

I'm surprised I can't find what I'm trying to do in existing modules or
maybe I'm just not looking in the right places. :cool:

I'm creating some time based logs (recording the UTC as reported by
gettimeofday()) in one timezone and I want to play them back in another,
showing the times on the system where they were initially recorded. In
other words, if I record a file in stockholm which is GMT +2 and play it
back in Boston which is GMT -4, data recorded at midnight in stockholm
shows up 6 hours earlier because of the time difference.

The simple solution, and this is too simple as I'll get to in a minute,
is to just record the timezone where the data was recorded. That way
when I go to play it back I can tell there is a 6 hour difference and
simply adjust the times accordingly before calling localtime() to
convert them. This works like a champ, but...

Although many countries around the world support daylight savings time,
they do not do it on the same date! In other words, if I use my simple
algorithm above it will break when one country has adjusted its clocks
and the other hasn't. The one simple solution I can think of that will
make this all work is that if I were do know my offset from GMT not for
the current date, but for the date of the data I wish to process. But I
can't seem to find any such function.

Can someone help? Does someone have a better way to solve this problem?

-mark
 
J

J. Gleixner

Mark Seger wrote:
[...]
Although many countries around the world support daylight savings time,
they do not do it on the same date! In other words, if I use my simple
algorithm above it will break when one country has adjusted its clocks
and the other hasn't. The one simple solution I can think of that will
make this all work is that if I were do know my offset from GMT not for
the current date, but for the date of the data I wish to process. But I
can't seem to find any such function.

Can someone help? Does someone have a better way to solve this problem?

-mark

For dealing with timezones, try the modules available under DateTime.
See CPAN or http://datetime.perl.org/ for more information.
 
B

Big and Blue

Mark said:
Although many countries around the world support daylight savings time,
they do not do it on the same date! In other words, if I use my simple
algorithm above it will break when one country has adjusted its clocks
and the other hasn't.

This is OS dependent. Most Unix systems (using Olson's time code)
would handle this correctly.
Can someone help? Does someone have a better way to solve this problem?

Which OS are you using? Which OS is the final user going to be using?
 

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,982
Messages
2,570,186
Members
46,740
Latest member
JudsonFrie

Latest Threads

Top