Bug 457370 - date -d 'last month' returns this month
Summary: date -d 'last month' returns this month
Keywords:
Status: CLOSED NOTABUG
Alias: None
Product: Red Hat Enterprise Linux 5
Classification: Red Hat
Component: coreutils
Version: 5.2
Hardware: All
OS: Linux
low
low
Target Milestone: rc
: ---
Assignee: Ondrej Vasik
QA Contact:
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2008-07-31 08:13 UTC by Rafal Wijata
Modified: 2008-08-04 10:15 UTC (History)
0 users

Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Clone Of:
Environment:
Last Closed: 2008-08-04 10:15:24 UTC
Target Upstream Version:
Embargoed:


Attachments (Terms of Use)

Description Rafal Wijata 2008-07-31 08:13:22 UTC
Description of problem:
# LANG=C date
Thu Jul 31 10:00:21 CEST 2008
# LANG=C date -d 'last month'
Tue Jul  1 10:00:27 CEST 2008

Version-Release number of selected component (if applicable):
All, F8 as well.

Actual results:
30 days before today

Expected results:
last month, like in perl
# perl -e 'use DateTime; print DateTime->now;'
2008-07-31T08:05:35
# perl -e 'use DateTime; print DateTime->now->subtract(months => 1);'
2008-06-30T08:05:38

or pgsql
template1=# select now();
 2008-07-31 10:12:21.004549+02

template1=# select now() - interval '1 month';
 2008-06-30 10:12:22.249536+02

PS: I know it's not directly RH related, but I don;t know where else to post it.

Comment 1 Ondrej Vasik 2008-08-04 10:15:24 UTC
Thanks for report, that fuzzy behaviour was already reported few times... However - that's not a bug, but documented behaviour which is expected. "Last month" is relative time offset which represents -1 month. For Jul 31, it substracts one month from the date - so the result should be Jun 31. That date is invalid, so it is intentionally interpreted as Jul 1. It is documented in RHEL-5 coreutils (date) info documentation, section 27.6 Relative items in date strings. Solution for scripts is also available in that documentation. Closing NOTABUG.


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