Bug 17623

Summary: date(1) -v doesn't handle time changes (DST) correctly
Product: Base System Reporter: Paul.Hernaus <paul.hernaus>
Component: binAssignee: freebsd-bugs (Nobody) <bugs>
Status: Closed FIXED    
Severity: Affects Only Me    
Priority: Normal    
Version: 5.0-CURRENT   
Hardware: Any   
OS: Any   

Description Paul.Hernaus 2000-03-27 16:50:01 UTC
Date adjustments with -v can result in an error because Daylight Savings
Time is handled incorrectly.

Fix: 

First convert the start date to UTC, then do the math, then convert
back to the desired time zone, just like GNU date does. The correct
result in this case would have been:

[~] paul@itchy> date -v-39H
Sun Mar 26 01:42:59 CET 2000
How-To-Repeat: 
[~] paul@itchy> date
Mon Mar 27 17:42:55 CEST 2000
[~] paul@itchy> date -v-38H
Sun Mar 26 03:42:59 CEST 2000
[~] paul@itchy> date -v-39H
-39H: Cannot apply date adjustment
usage: date [-nu] [-d dst] [-r seconds] [-t west] [-v[+|-]val[ymwdHMS]] ... 
            [-f fmt date | [[[[[cc]yy]mm]dd]HH]MM[.ss]] [+format]
Comment 1 gil 2002-10-26 21:47:47 UTC
Additional information:

The documentation for the date command is also wrong because
of this bug.  It says:

   When a date is adjusted to a specific value or in units greater
   than hours, daylight savings time considerations are ignored.
   Adjustments in units of hours or less honor daylight saving time.
   So, assuming the current date is March 26, 0:30 and that the DST
   adjustment means that the clock goes forward at 01:00 to 02:00,
   using -v +1H will adjust the date to March 26, 2:30.  Likewise,
   if the date is October 29, 0:30 and the DST adjustment means that
   the clock goes back at 02:00 to 01:00, using -v +3H will be nec-
   essary to reach October 29, 2:30.

Looking at the code, it is obvious why the above is not the case.  Hours
are modified in the tm structure from localtime, instead of using the
seconds-since-epoch and then converting it to printable time (as the
bug originator pointed out).

Another example of this bug in action:

   csdlap3$ date ; date -v+16H
   Sat Oct 26 15:44:58 CDT 2002
   Sun Oct 27 07:44:58 CST 2002

This is also wrong (the second time should be 06:44:58 CST).
Comment 2 Marc Olzheim 2010-03-16 15:45:12 UTC
I believe this was fixed in the set of commits of april 2000 on
bin/date/vary.c

Marc
Comment 3 Eitan Adler freebsd_committer freebsd_triage 2011-03-05 18:39:58 UTC
State Changed
From-To: open->closed

seemingly fixed in r59175; I can't reproduce