Bug 439956 - "date -d last-month" doesn't show the correct result
Summary: "date -d last-month" doesn't show the correct result
Keywords:
Status: CLOSED NOTABUG
Alias: None
Product: Red Hat Enterprise Linux 5
Classification: Red Hat
Component: coreutils
Version: 5.0
Hardware: i386
OS: Linux
medium
low
Target Milestone: rc
: ---
Assignee: Ondrej Vasik
QA Contact:
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2008-04-01 03:17 UTC by Winston Li
Modified: 2008-04-01 05:58 UTC (History)
0 users

Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Clone Of:
Environment:
Last Closed: 2008-04-01 05:58:18 UTC
Target Upstream Version:
Embargoed:


Attachments (Terms of Use)

Description Winston Li 2008-04-01 03:17:40 UTC
Description of problem:
Command: 
date -d last-month +%Y%m 
date -d next-month +%Y%m
doesn't return the correct result on March 31, 2008


Version-Release number of selected component (if applicable):
coreutils-5.97-12.1.el5


How reproducible:
It can be reproduced.

Steps to Reproduce:
1.Change the system date to March 31, 2008
# date 0331010108
Mon Mar 31 01:01:00 CST 2008
2.run command: date -d last-month +%Y%m
result: 200803
3.run command: date -d next-month +%Y%m
result: 200805
  
Actual results:


Expected results:
200802
200804

Additional info:
Change the date to March 30, 2008, next-month reports the correct result, but
last-month doesn't.
Change the date to May 31, 2008, the results are incorrect either.

Comment 1 Ondrej Vasik 2008-04-01 05:58:18 UTC
Sorry, that's not a bug, but expected behaviour and in fact frequently asked
question. Last month works like: 2008 03 31 - 1 month = 2008 02 31 -> invalid
date -> change it to valid date -> 2008 03 02 -> that's the output
          Next month works like: 2008 03 31 + 1 month = 2008 04 31 -> invalid
date -> change it to valid date -> 2008 05 01 -> that's the output

This behaviour is expected and can't be changed. 

For details and way how to get correct month if you need, you could see
coreutils documentation , section 27.6, Relative items in date strings
(here is online version:
http://www.gnu.org/software/coreutils/manual/html_node/Relative-items-in-date-strings.html
)

Closing NOTABUG.


Note You need to log in before you can comment on or make changes to this bug.