Unix time functions and timezones

Unix time functions and timezones

Post by Sylvain BENOIS » Thu, 19 Apr 2001 10:55:44



Hi,

I want to write the following C function under Unix :

This function has to convert a date according to a specific timezone.

The parameters have to be :
- A date ( Format : YYYYMMDDHHMISS ) given in a specific time zone.
- A timezone ( Ex : PSD8PDT) which has to be used to convert the date.

For example :

If the date in input is "20010417180010" ( given in PSD8PDT) and the
timezone which has to be used is UCT-5:30, the new date has to be converted
according to UCT-5:30.

I looked at different UNIX functions like ctime, localtime ... and thought
about modifying the TZ variable. But my problem is to handle the daylight
saving times.

For example, "20010117180010" was the local date and time in the USA in
january. It means that the daylight savings time wasn't in effect. How to
convert this date now (when the daylight savings time is in effect in the
USA) according to the UCT-5:30 timezone where the daylight savings time may
not exist ? I mean it isn't really usefull to modify the TZ variable in this
case.

Does anyone know a function or has a clue about this problem ?

Thanks.

Sylvain BENOIST
_________________________________________________________________
Get your FREE download of MSN Explorer at http://explorer.msn.com

--
Posted from [63.145.241.30] by way of f82.law14.hotmail.com [64.4.21.82]
via Mailgate.ORG Server - http://www.Mailgate.ORG

 
 
 

Unix time functions and timezones

Post by Andrew Giert » Thu, 19 Apr 2001 18:26:58


 Sylvain> If the date in input is "20010417180010" ( given in PSD8PDT)
 Sylvain> and the timezone which has to be used is UCT-5:30, the new
 Sylvain> date has to be converted according to UCT-5:30.

 Sylvain> I looked at different UNIX functions like ctime, localtime
 Sylvain> ... and thought about modifying the TZ variable. But my
 Sylvain> problem is to handle the daylight saving times.

 Sylvain> For example, "20010117180010" was the local date and time in
 Sylvain> the USA in january. It means that the daylight savings time
 Sylvain> wasn't in effect. How to convert this date now (when the
 Sylvain> daylight savings time is in effect in the USA) according to
 Sylvain> the UCT-5:30 timezone where the daylight savings time may
 Sylvain> not exist ? I mean it isn't really usefull to modify the TZ
 Sylvain> variable in this case.

TZ can be set to include the daylight savings info, e.g.
  TZ=GMT0BST,M3.5.0/01:00,M10.5.0/02:00
is the full specification for the current UK timezone.

This doesn't, however, work well for historical data (some parts of
the world insist on changing their DST practices on a fairly frequent
basis).

The other approach is the method that the Olsen timezone library (as
used in many Unix versions) uses: have a database of locations for
which detailed timezone info, including current and historical
daylight savings changes, are stored. Then TZ can be set to something
like Europe/London or America/Los_Angeles.

The Olsen code is public-domain, so if your system doesn't use it you
can grab the sources and the database info yourself.

--
Andrew.

comp.unix.programmer FAQ: see <URL: http://www.erlenstar.demon.co.uk/unix/>
                           or <URL: http://www.whitefang.com/unix/>

 
 
 

Unix time functions and timezones

Post by Michel Bardiau » Thu, 19 Apr 2001 19:04:36



> TZ can be set to include the daylight savings info, e.g.
>   TZ=GMT0BST,M3.5.0/01:00,M10.5.0/02:00
> is the full specification for the current UK timezone.

> This doesn't, however, work well for historical data (some parts of
> the world insist on changing their DST practices on a fairly frequent
> basis).

> The other approach is the method that the Olsen timezone library (as
> used in many Unix versions) uses: have a database of locations for
> which detailed timezone info, including current and historical
> daylight savings changes, are stored. Then TZ can be set to something
> like Europe/London or America/Los_Angeles.

> The Olsen code is public-domain, so if your system doesn't use it you
> can grab the sources and the database info yourself.

Andrew, do you know whether that library handles leap seconds?

--
Michel Bardiaux
Peaktime Belgium S.A.  Rue Margot, 37  B-1457 Nil St Vincent
Tel : +32 10 65.44.15  Fax : +32 10 65.44.10

 
 
 

Unix time functions and timezones

Post by Andrew Giert » Thu, 19 Apr 2001 20:00:59


 >> The Olsen code is public-domain, so if your system doesn't use it you
 >> can grab the sources and the database info yourself.

 Michel> Andrew, do you know whether that library handles leap seconds?

It's an option.

Though that depends perhaps on what you mean by "handling" leap seconds.
There is no obviously correct answer to what to do about them (though
there are religious wars between various factions who believe that their
answer is obviously correct).

--
Andrew.

comp.unix.programmer FAQ: see <URL: http://www.erlenstar.demon.co.uk/unix/>
                           or <URL: http://www.whitefang.com/unix/>

 
 
 

1. Converting a *future* time in another timezone to local time ...

I am developing some voice mail scripts for use under Linux.
One program schedules the delivery of voice messages.
To make this work properly across timezones I need to convert
a future (scheduled) time expressed in another zone into local time.

The only way I can see of doing this easily is to do something like:

        LOCAL_SAVE=`date`
        TZ=<remote zone> date -s <REMOTE_TIME>
        LOCAL_TIME=`TZ=localtime date +FORMAT`
        date -s <LOCAL_SAVE>

But this changes the system's time for an instant -- not at all nice.

My current method uses a fixed timzone offset calculated at the
current time.  This of course will make scheduling inaccurate around
time discontinuities.

Is there any way to do what I want without having to hack some C code;
and if I have to write some C, what is the best way to go about it.

Thanks for your help,


Basser Department of Computer Science, F09   |  PHONE : +61-2-692-4276   |
The University of Sydney NSW 2006 AUSTRALIA  |  FAX   : +61-2-692-3838   |

2. Linux on Apple Powerbook G3?

3. Convert local time to gmt time without using TimeZone Env variable

4. NT administrator prefers linux

5. X86 or PowerPC for Linux

6. time function in UNIX

7. x86 auto-boot?

8. leap seconds in Unix time functions

9. Unix time function

10. >1 second granularity unix time functions

11. C function execution time measurement under UNIX

12. time() function in time.h