[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: bug#13071: Date and month ago
From: |
Tom Roche |
Subject: |
Re: bug#13071: Date and month ago |
Date: |
Wed, 19 Jun 2013 18:48:22 -0400 |
User-agent: |
GNU Emacs 24.3.50.1 (x86_64-pc-linux-gnu, GTK+ Version 3.4.2) |
http://lists.gnu.org/archive/html/bug-coreutils/2012-12/msg00003.html (Bob
Proulx)
> it is often wise to adopt universal time by setting [`TZ=UTC0']
> before embarking on calendrical calculations.
> And also see the FAQ entry which also discusses this topic in some
> detail:
> http://www.gnu.org/software/coreutils/faq/#The-date-command-is-not-working-right_002e
> I am sure those docs answer your questions. But just the same we
> would appreciate a note from you saying that it did.
The above helped me to diagnose/fix the incorrect last day in Nov 2008
(below).
> Or suggesting improvements! :-)
A --verbose switch on `date` that would do something like
MODEL_YEAR='2008'
for M in {1..12} ; do
MM="$(printf '%02d' ${M})"
FIRST_DAY_OF_MONTH="$(date --verbose -d "${MODEL_YEAR}-${MM}-01")"
echo -e "first day of month=${FIRST_DAY_OF_MONTH}"
LAST_DAY_OF_MONTH="$(date --verbose -d "${FIRST_DAY_OF_MONTH} + 1 month - 1
day")"
echo -e " last day of month=${LAST_DAY_OF_MONTH}"
echo # newline
done
> first day of month=Tue Jan 1 00:00:00 EST 2008
> last day of month=Thu Jan 31 00:00:00 EST 2008
> first day of month=Fri Feb 1 00:00:00 EST 2008
* date: <something about leap year/>
> last day of month=Fri Feb 29 00:00:00 EST 2008
> first day of month=Sat Mar 1 00:00:00 EST 2008
* date: weirdness happened when calculating <whatever/>: <explanation/>
> last day of month=Mon Mar 31 01:00:00 EDT 2008
> first day of month=Tue Apr 1 00:00:00 EDT 2008
> last day of month=Wed Apr 30 00:00:00 EDT 2008
> first day of month=Thu May 1 00:00:00 EDT 2008
> last day of month=Sat May 31 00:00:00 EDT 2008
> first day of month=Sun Jun 1 00:00:00 EDT 2008
> last day of month=Mon Jun 30 00:00:00 EDT 2008
> first day of month=Tue Jul 1 00:00:00 EDT 2008
> last day of month=Thu Jul 31 00:00:00 EDT 2008
> first day of month=Fri Aug 1 00:00:00 EDT 2008
> last day of month=Sun Aug 31 00:00:00 EDT 2008
> first day of month=Mon Sep 1 00:00:00 EDT 2008
> last day of month=Tue Sep 30 00:00:00 EDT 2008
> first day of month=Wed Oct 1 00:00:00 EDT 2008
> last day of month=Fri Oct 31 00:00:00 EDT 2008
> first day of month=Sat Nov 1 00:00:00 EDT 2008
* date: weirdness happened when calculating <whatever/>: <explanation/>
> last day of month=Sat Nov 29 23:00:00 EST 2008
> first day of month=Mon Dec 1 00:00:00 EST 2008
> last day of month=Wed Dec 31 00:00:00 EST 2008
might help users debug. Note my fix (per your suggestions) was
MODEL_YEAR='2008'
for M in {1..12} ; do
MM="$(printf '%02d' ${M})"
FIRST_DAY_OF_MONTH="$(TZ='UTC0' date -d "${MODEL_YEAR}-${MM}-01")"
echo -e "first day of month=${FIRST_DAY_OF_MONTH}"
LAST_DAY_OF_MONTH="$(TZ='UTC0' date -d "${FIRST_DAY_OF_MONTH} + 1 month - 1
day")"
echo -e " last day of month=${LAST_DAY_OF_MONTH}"
echo # newline
done
FWIW, Tom Roche <address@hidden>
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- Re: bug#13071: Date and month ago,
Tom Roche <=