bug about date

2010-03-08 Thread gaosh
Hi, Dear Sir,

I use the command: date +%Y%m%d%H -d 1990-04-13 12 36 hours
But I get the result: 1990041501 ! The correct one should be 1990041500.

date +%Y%m%d%H -d 1990-04-13 12 118799 seconds
the result is:  1990041500.
But,
date +%Y%m%d%H -d 1990-04-13 12 118800 seconds
the result is:  1990041501.

My Linux is redhat ES V5.1. And I get the same result on Linux with ES5.4.

Thank you very much!

Gao.

 
  Dr. Gao Shanhong
 Institute of Physical Oceanography
 Ocean University of China
 Songling Road 238, Qingdao, 266100 
 P. R. China
  Email:ga...@ouc.edu.cn
  Homepage:  http://222.195.136.24
  Office Phone:
 086-532-82032659 (Yushan Campus)
 086-532-66781312 (Laoshan Campus)






Re: bug about date

2010-03-08 Thread Philip Rowlands

On Mon, 8 Mar 2010, gaosh wrote:


I use the command: date +%Y%m%d%H -d 1990-04-13 12 36 hours
But I get the result: 1990041501 ! The correct one should be 1990041500.


The result depends on your system's local timezone, which I assume is 
set to Asia/Shanghai or equivalent Chinese location. 1990-04-14 was a 
day when daylight saving time began, so you're seeing the extra hour 
gained. This is more obvious if you use the %z display option to see 
the UTC offset:


$ TZ=Asia/Shanghai date '+%Y%m%d%H %z' -d '1990-04-13 12 35 hours'
1990041423 +0800
$ TZ=Asia/Shanghai date '+%Y%m%d%H %z' -d '1990-04-13 12 36 hours'
1990041501 +0900

So this is not a bug, but a hazard of making precise date calculations 
around DST boundaries. Please read the FAQ discussion here:

http://www.gnu.org/software/coreutils/faq/coreutils-faq.html#The-date-command-is-not-working-right_002e


Cheers,
Phil