Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re^3: Adding Days To YYYYMMDD Date Format

by tobyink (Abbot)
on May 18, 2012 at 23:01 UTC ( #971372=note: print w/ replies, xml ) Need Help??


in reply to Re^2: Adding Days To YYYYMMDD Date Format
in thread Adding Days To YYYYMMDD Date Format

I meant to add... I've uploaded a new version of DateTimeX::Auto so now it's possible to just do:

use DateTimeX::Auto qw(:auto); my $future = '2012-05-19' + 'P3Y4M2D'; # says '2015-09-21' say $future;

The duration format isn't the most readable, but it's an ISO standard (ISO 8601 duration), so fairly well documented if you Google for it.

perl -E'sub Monkey::do{say$_,for@_,do{($monkey=[caller(0)]->[3])=~s{::}{ }and$monkey}}"Monkey say"->Monkey::do'


Comment on Re^3: Adding Days To YYYYMMDD Date Format
Download Code
Replies are listed 'Best First'.
Re^4: Adding Days To YYYYMMDD Date Format
by parv (Priest) on May 19, 2012 at 00:39 UTC
    That *::Auto has more magic than *::Easy! And, MooseX::Types::DateTimeX lists the caveat about *::Easy that it has too much DWIMery.
Re^4: Adding Days To YYYYMMDD Date Format
by justin423 (Initiate) on Aug 10, 2012 at 16:49 UTC
    I have a similar issue. Is there a way to construct a for loop that will generate dates in format YYYMMDD starting on the first business date of the year and skip Saturdays and Sundays?

    Example, 20120103 20120104 20120105 20120106 20120109 20120110 20120111 20120112 etc.

      Sounds like a job for Date::Manip, which is kind of the "kitchen sink" of date modules.

      Date::Manip::Date::is_business_day would probably do the trick. It also has a 'holiday' method which could let you skip holidays as well, if you wanted to.

      Otherwise, search cpan for other possibilities.

      use 5.010; use strict; use warnings FATAL => qw(all); use DateTimeX::Auto qw(:auto); { # slightly evil, but works... package DateTime; use overload '~~', sub { $_[0]->ymd eq $_[1]->ymd } } my $not_business_days = [ sub { $_[0]->day_abbr =~ /^S/ }, # weekends qw( 2012-01-02 2012-04-06 2012-04-09 2012-05-07 2012-06-04 2012-06-05 2012-08-27 2012-12-25 2012-12-26 ), ]; my $date = '2012-01-01'; my $end = '2013-01-01'; while ($date < $end) { say $date->ymd("") unless $date ~~ $not_business_days; $date->add(days => 1); }
      perl -E'sub Monkey::do{say$_,for@_,do{($monkey=[caller(0)]->[3])=~s{::}{ }and$monkey}}"Monkey say"->Monkey::do'

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://971372]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (7)
As of 2015-07-31 23:51 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (282 votes), past polls