General Purpose Date Script

UNIX for Beginners Questions & Answers

Kindly Note - This is a Single User Post by Forum Member Corona688 Regarding:
General Purpose Date Script.
Please Follow The Primary Link Above to View the Full Discussion.

Old 10-25-2013
Corona688 Corona688 is offline Forum Staff  
Mead Rotor
Join Date: Aug 2005
Last Activity: 20 July 2018, 3:26 PM EDT
Location: Saskatchewan
Posts: 22,727
Thanks: 1,194
Thanked 4,351 Times in 4,006 Posts
Bug noted, thank you a lot, I had --date "something" when I should have done --date="something".

Thanks for reminding me about the +syntax feature, which I'd planned but forgotten.

Date math is not hard here, I am letting mktime handle absolutely everything tricky. I do not need to know when the next leap year is, I subtract 1 from the 'year' value and let mktime decide what that is.

Yes yes I know that Perl has about 37 different date modules I could be using. But if I'm going to tell someone to install 'Perl::MyFavoriteDateModule' I might as well just tell them to install GNU date. The whole point is to not do that, (and to show elegant Perl code is possible without including the kitchen sink).

Some of those tests are just weird though. I have no idea how you got 23 hours from subtracting days, it certainly doesn't happen here. I may have done something odd with a last-minute fix when I posted. [edit] Now I know. It happened because of the --date vs --date= problem. Perl does strange things when you do arithmetic on strings.

Anyway, I'll incorporate your suggestions and repost. Thanks again. [edit] Version 2 is now in the OP.

Last edited by Corona688; 10-25-2013 at 05:57 PM..