Daylight saving time DST and timestamp handling
Daylight saving time DST and timestamp handling
am 29.11.2007 15:15:34 von Alvin SIU
Hi all,
I am living in a city without DST.
So far, I do not need to care about DST in the computer systems.
I write this just for curiosity.
I want to know:
1.
For example, if at 03:00 am, the clock is adjust back to 02:00 am due
to DST adjustment.
Then, (today is 2007-11-29) the date +"%Y%m%d%H" will show 2007112902
`again`
If I use this command to create a file name like
echo hello > myfile.`date +"%Y%m%d%H"`.txt
then, the first hour-2 and the second hour-2 will give the same
filename.
This is really a trouble.
2.
Similarly, if I use that date command to form a timestamp
having YYYY-MM-DD-HH:mm:ss
and then store the timestamp as a database records.
Then, the number of records having timestamp hour-2 r
will double those with hour-1 and hour-3.
If I need the records in sequence, e.g.
record-1 is job start at 2007-11-29-02:59:00
record-2 is job end at 2007-11-29-02:01:01
(actually, record-2's timestamp should be hour-3-01:01 if without DST)
This seems having trouble.
because the records are not in sequence
Could anyone having some DST experience with system design
discuss on this topic.
This is my curiosity, hope that it does not kill a cat.
Thanks
Alvin SIU
Re: Daylight saving time DST and timestamp handling
am 29.11.2007 15:40:04 von Joachim Schmitz
"Alvin SIU" schrieb im Newsbeitrag
news:5f8c17e2-45a4-43fb-a617-77cd2924b4a6@i29g2000prf.google groups.com...
> Hi all,
>
> I am living in a city without DST.
> So far, I do not need to care about DST in the computer systems.
>
> I write this just for curiosity.
>
> I want to know:
>
> 1.
> For example, if at 03:00 am, the clock is adjust back to 02:00 am due
> to DST adjustment.
>
> Then, (today is 2007-11-29) the date +"%Y%m%d%H" will show 2007112902
> `again`
>
> If I use this command to create a file name like
> echo hello > myfile.`date +"%Y%m%d%H"`.txt
>
> then, the first hour-2 and the second hour-2 will give the same
> filename.
>
> This is really a trouble.
>
>
> 2.
> Similarly, if I use that date command to form a timestamp
> having YYYY-MM-DD-HH:mm:ss
> and then store the timestamp as a database records.
>
> Then, the number of records having timestamp hour-2 r
> will double those with hour-1 and hour-3.
>
> If I need the records in sequence, e.g.
> record-1 is job start at 2007-11-29-02:59:00
> record-2 is job end at 2007-11-29-02:01:01
> (actually, record-2's timestamp should be hour-3-01:01 if without DST)
>
> This seems having trouble.
> because the records are not in sequence
>
>
> Could anyone having some DST experience with system design
> discuss on this topic.
>
> This is my curiosity, hope that it does not kill a cat.
Just use UTC (AKA GMT) for these purposes.
Bye, Jojo
Re: Daylight saving time DST and timestamp handling
am 29.11.2007 15:49:59 von Joachim Schmitz
"Joachim Schmitz" schrieb im Newsbeitrag
news:fimj09$4ct$1@online.de...
> "Alvin SIU" schrieb im Newsbeitrag
> news:5f8c17e2-45a4-43fb-a617-77cd2924b4a6@i29g2000prf.google groups.com...
>> Hi all,
>>
>> I am living in a city without DST.
>> So far, I do not need to care about DST in the computer systems.
>>
>> I write this just for curiosity.
>>
>> I want to know:
>>
>> 1.
>> For example, if at 03:00 am, the clock is adjust back to 02:00 am due
>> to DST adjustment.
>>
>> Then, (today is 2007-11-29) the date +"%Y%m%d%H" will show 2007112902
>> `again`
>>
>> If I use this command to create a file name like
>> echo hello > myfile.`date +"%Y%m%d%H"`.txt
>>
>> then, the first hour-2 and the second hour-2 will give the same
>> filename.
>>
>> This is really a trouble.
>>
>>
>> 2.
>> Similarly, if I use that date command to form a timestamp
>> having YYYY-MM-DD-HH:mm:ss
>> and then store the timestamp as a database records.
>>
>> Then, the number of records having timestamp hour-2 r
>> will double those with hour-1 and hour-3.
>>
>> If I need the records in sequence, e.g.
>> record-1 is job start at 2007-11-29-02:59:00
>> record-2 is job end at 2007-11-29-02:01:01
>> (actually, record-2's timestamp should be hour-3-01:01 if without DST)
>>
>> This seems having trouble.
>> because the records are not in sequence
>>
>>
>> Could anyone having some DST experience with system design
>> discuss on this topic.
>>
>> This is my curiosity, hope that it does not kill a cat.
> Just use UTC (AKA GMT) for these purposes.
date -u +"%Y%m%d%H"
Or add the timezone, to make it unique
date +"%Y%m%d%H%Z"
Bye, Jojo
Re: Daylight saving time DST and timestamp handling
am 29.11.2007 22:44:22 von cfajohnson
On 2007-11-29, Alvin SIU wrote:
>
> I am living in a city without DST.
> So far, I do not need to care about DST in the computer systems.
>
> I write this just for curiosity.
>
> I want to know:
>
> 1.
> For example, if at 03:00 am, the clock is adjust back to 02:00 am due
> to DST adjustment.
On a *NIX system the clock is normally not adjusted. It is set to
Universal Co-ordinated Time (UTC). How the time is displayed is
determined by your timezone (the TZ environment variable).
If your locale doesn't use DST, then your TZ should be set to the
correct value, i.e., a timezone which does not use DST.
--
Chris F.A. Johnson, author
Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress)
===== My code in this post, if any, assumes the POSIX locale
===== and is released under the GNU General Public Licence
Re: Daylight saving time DST and timestamp handling
am 30.11.2007 10:20:00 von Casper.Dik
Alvin SIU writes:
>If I use this command to create a file name like
>echo hello > myfile.`date +"%Y%m%d%H"`.txt
>then, the first hour-2 and the second hour-2 will give the same
>filename.
>This is really a trouble.
Yes. DST is bad, what else is new?
To make the timestamp unique it must include the timezone name.
>2.
>Similarly, if I use that date command to form a timestamp
>having YYYY-MM-DD-HH:mm:ss
>and then store the timestamp as a database records.
You don't store enough information; add the timestamp name.
>Then, the number of records having timestamp hour-2 r
>will double those with hour-1 and hour-3.
>If I need the records in sequence, e.g.
>record-1 is job start at 2007-11-29-02:59:00
>record-2 is job end at 2007-11-29-02:01:01
>(actually, record-2's timestamp should be hour-3-01:01 if without DST)
>This seems having trouble.
>because the records are not in sequence
>Could anyone having some DST experience with system design
>discuss on this topic.
Use th tmestamps in GMT or in "seconds since the epoch" and you will have
a unique and monotonically increasing time.
Casper
--
Expressed in this posting are my opinions. They are in no way related
to opinions held by my employer, Sun Microsystems.
Statements on Sun products included here are not gospel and may
be fiction rather than truth.
Re: Daylight saving time DST and timestamp handling
am 30.11.2007 14:36:40 von Geoff Clare
Casper H.S. Dik wrote:
> Alvin SIU writes:
>
>>If I use this command to create a file name like
>>echo hello > myfile.`date +"%Y%m%d%H"`.txt
>
>>then, the first hour-2 and the second hour-2 will give the same
>>filename.
> To make the timestamp unique it must include the timezone name.
There would still be a problem if somebody set TZ to, say, XYZ0XYZ
The other solution (date -u) is more robust.
--
Geoff Clare
Re: Daylight saving time DST and timestamp handling
am 30.11.2007 16:54:41 von Alvin SIU
Thanks everybody for your advice.
After reading this invaluable information,
although I do not have DST experience,
I think I still get some idea.
1.
TZ variable is used to 'construct' the local time to 'display'
for human being to use in everyday life.
Internally, the computer use "seconds since the epoch" as the 'time'
So, the 'time' is always unique.
2.
If I want to have a 'time' sequence of records
(just in my example),
I have to store the 'time' as GMT format
or 'second since the epoch' format
or date -u format.
Since these formats are not the TZ adjusted,
the human being will not feel comfortable with them.
3.
If DST comes to play, the string YYYY-MM-DD-HH:mm:ss
cannot form a unique key.
I have to add the timezone (date +"%Z") to make it unique.
(Maybe, after adding the timezone to get a unique key,
I have to find a way to make it in ascending order in order
to get a chronological order key.)
Is my understanding correct ?
This DST issue is really interesting to me.
Alvin SIU
Re: Daylight saving time DST and timestamp handling
am 01.12.2007 19:09:27 von Icarus Sparry
On Fri, 30 Nov 2007 07:54:41 -0800, Alvin SIU wrote:
> Thanks everybody for your advice.
>
> After reading this invaluable information, although I do not have DST
> experience, I think I still get some idea.
>
>
> 1.
> TZ variable is used to 'construct' the local time to 'display' for human
> being to use in everyday life. Internally, the computer use "seconds
> since the epoch" as the 'time' So, the 'time' is always unique.
>
>
> 2.
> If I want to have a 'time' sequence of records (just in my example),
> I have to store the 'time' as GMT format or 'second since the epoch'
> format
> or date -u format.
> Since these formats are not the TZ adjusted, the human being will not
> feel comfortable with them.
Write a program to convert from the internal format to an external
format. This is a good idea anyway if your program might be used on a
networked computer where the users of the system might be in different
timezones. For log files I typically use a format of @123456789.012 where
the @ is a literal, 123456789 is seconds since epoch and 012 is
milliseconds. A simple perl script
#!/usr/bin/perl -p
s/@(\d{9,10})(\.\d{3})/localtime($1).$2/e;
is all that is needed to convert it to a more human friendly format
> 3.
> If DST comes to play, the string YYYY-MM-DD-HH:mm:ss cannot form a
> unique key.
> I have to add the timezone (date +"%Z") to make it unique. (Maybe, after
> adding the timezone to get a unique key, I have to find a way to make it
> in ascending order in order to get a chronological order key.)
>
>
>
>
> Is my understanding correct ?
Yes.