Subject: bug#11057: closed (Re: bug#11057: Having an issue with the date program)

From: [email-masked] (GNU bug Tracking System)
Date: Wed, 21 Mar 2012 19:28:02 +0000

Your bug report

#11057: Having an issue with the date program

which was filed against the coreutils package, has been closed.

The explanation is attached below, along with your original report.
If you require more details, please reply to [email-masked].

-- 
11057: http://debbugs.gnu.org/cgi/bugreport.cgi?bug=11057
GNU Bug Tracking System
Contact [email-masked] with problems

Subject: Re: bug#11057: Having an issue with the date program
From: Eric Blake <[email-masked]>
To: "Morin, Rick" <[email-masked]>
Cc: [email-masked]
Date: Wed, 21 Mar 2012 12:10:43 -0600
List-Id: <debbugs-submit.debbugs.gnu.org>

tag 11057 notabug
thanks

On 03/21/2012 11:26 AM, Morin, Rick wrote:
> Hello,
> 
> I'm having an interesting time trying to get the following code to work using your coreutils date program.  I'm trying to get the date for Wednesday of the current week.  This is running in a Korn shell on an AIX 5.3 (AIX 64) platform.
> 
> MDOW1=$(${SBIN}/date +%w)

Why are you basing things on %w (0-6, 1 is Monday), when you could
instead be using %u (1-7, 1 is Monday)?

Your script snippet didn't show what $manYY and friends were set to, but
I suspect you were manually setting things to various dates to see how
your script behaved.

> 
> Any assistance you can provide would be greatly appreciated.  The target date is day 3 of the current week, with Monday being the 1.  Just to clarify, on Sunday, I am looking for the previous Wednesday date.

If I understand what you are asking, you want:

On Sunday, generate the date of the prior Wednesday (previous week).
On Monday-Tuesday, generate the date of the next Wednesday (current week).
On Wednesday, generate the current date.
On Thursday-Saturday, generate the date of the prior Wednesday (current
week).

More concretely, it sounds like using March 1-7, 2012 as our sample
inputs, you want the following outputs:

Mar 1 (Thu) => Feb 29
Mar 2 (Fri) => Feb 29
Mar 3 (Sat) => Feb 29
Mar 4 (Sun) => Feb 29
Mar 5 (Mon) => Mar 7
Mar 6 (Tue) => Mar 7
Mar 7 (Wed) => Mar 7

Also, you should remember that when adding or subtracting days, you must
take into account daylight savings transitions.  I'd recommend basing
your computations off of noon, rather than midnight, so that even if you
end up at 11am or 1pm due to your calculations changing by multiples of
24 hours but crossing a day with 23 or 25 hours, you still get the right
date.

$ for i in `seq 7`; do
 offset=$(date -d"Mar $i, 2012" +%u)
 date -d"12pm Mar $i, 2012 +3 days -$offset day"
done
Wed Feb 29 12:00:00 MST 2012
Wed Feb 29 12:00:00 MST 2012
Wed Feb 29 12:00:00 MST 2012
Wed Feb 29 12:00:00 MST 2012
Wed Mar  7 12:00:00 MST 2012
Wed Mar  7 12:00:00 MST 2012
Wed Mar  7 12:00:00 MST 2012

Since it looks like I can generate what you asked for, I'm closing this
as not a bug.  You can continue to ask further questions on this thread,
but I don't see anything broken in the current coreutils implementation.

> This message w/attachments (message) is intended solely for the use of the intended recipient(s)

Disclaimers like this are unenforceable on publicly-archived lists.  It
is considered better netiquette to send from a personal account, rather
than an employer's account.

-- 
Eric Blake   [email-masked]    +1-919-301-3266
Libvirt virtualization library http://libvirt.org

Subject: Having an issue with the date program
From: "Morin, Rick" <[email-masked]>
To: "[email-masked]" <[email-masked]>
Date: Wed, 21 Mar 2012 13:26:19 -0400
List-Id: <debbugs-submit.debbugs.gnu.org>

Hello,

I'm having an interesting time trying to get the following code to work using your coreutils date program.  I'm trying to get the date for Wednesday of the current week.  This is running in a Korn shell on an AIX 5.3 (AIX 64) platform.

MDOW1=$(${SBIN}/date +%w)
let MDOW=$MDOW1-1
let WDOW=$MDOW-2
MONYYYYMMDD=$(${SBIN}/date -d"${manYY}-${manMM}-${manDD} -$MDOW day" +%Y-%m-%d)
MONMMDDYYYY=$(${SBIN}/date -d"${manYY}-${manMM}-${manDD} -$MDOW day" +%m%d%Y)
MONDAYDDMMMYYYY=$(${SBIN}/date -d"${manYY}-${manMM}-${manDD} -$MDOW day" +%d%b%Y)
WEDYYYYMMDD=$(${SBIN}/date -d"${manYY}-${manMM}-${manDD} -($WDOW) day" +%Y%m%d)
WEDMMDDYYYY=$(${SBIN}/date -d"${manYY}-${manMM}-${manDD} -($WDOW) day" +%m%d%Y)
WEDDAYDDMMMYYYY=$(${SBIN}/date -d"${manYY}-${manMM}-${manDD} -($WDOW) day" +%d%b%Y)

The 3 MONxxx and 3 WEDxxx variables are all exported.  I'm having trouble with the WED dates.  On Monday and Tuesday, the WEDxxx variables correctly displayed Mar 21, 2012, in their various formats.  But today on Wed, the 21st, they are displaying the Mar 22nd.

WAP:/opt/freeware/bin> echo $MDOW1 $MDOW $WDOW
3 2 0
WAP:/opt/freeware/bin> echo $MONYYYYMMDD $MONMMDDYYYY $MONDAYDDMMMYYYY
2012-03-19 03192012 19Mar2012
WAP:/opt/freeware/bin> echo $WEDYYYYMMDD $WEDMMDDYYYY $WEDDAYDDMMMYYYY
20120322 03222012 22Mar2012
WAP:/opt/freeware/bin>

Any assistance you can provide would be greatly appreciated.  The target date is day 3 of the current week, with Monday being the 1.  Just to clarify, on Sunday, I am looking for the previous Wednesday date.

Thank you!

Richard (Rick) Morin
Bank of America
VP, Market Information Mgr I
GCSBB Marketing - Global Strategy & Marketing
DIRECT RESPONSE / ANALYTICAL MARKETING
904.783.1727
FL8-054-01-01

Instant recognition is a very powerful motivator.
Please recognize our associates by following the link below.
Global Recognition Program<http://flagscape.bankofamerica.com/portal/site/flagscape/menuitem.fae9b47594eab28f211649ede3cc5cba/?vgnextoid=c890a845526a4210VgnVCM10000038ccc5abRCRD&vgnextfmt=default&mname=flagscape_e9cec66651923210VgnVCM2000003cccc5abRCRD_876818063>

----------------------------------------------------------------------
This message w/attachments (message) is intended solely for the use of the intended recipient(s) and may contain information that is privileged, confidential or proprietary. If you are not an intended recipient, please notify the sender, and then please delete and destroy all copies and attachments, and be advised that any review or dissemination of, or the taking of any action in reliance on, the information contained in or attached to this message is prohibited. 
Unless specifically indicated, this message is not an offer to sell or a solicitation of any investment products or other financial product or service, an official confirmation of any transaction, or an official statement of Sender. Subject to applicable law, Sender may intercept, monitor, review and retain e-communications (EC) traveling through its networks/systems and may produce any such EC to regulators, law enforcement, in litigation and as required by law. 
The laws of the country of each sender/recipient may impact the handling of EC, and EC may be archived, supervised and produced in countries other than the country in which you are located. This message cannot be guaranteed to be secure or free of errors or viruses. 

References to "Sender" are references to any subsidiary of Bank of America Corporation. Securities and Insurance Products: * Are Not FDIC Insured * Are Not Bank Guaranteed * May Lose Value * Are Not a Bank Deposit * Are Not a Condition to Any Banking Service or Activity * Are Not Insured by Any Federal Government Agency. Attachments that are part of this EC may have additional important disclosures and disclaimers, which you should read. This message is subject to terms available at the following link: 
http://www.bankofamerica.com/emaildisclaimer. By messaging with Sender you consent to the foregoing.