Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re: RFC: List of first day of each month

by 1nickt (Canon)
on Jan 31, 2020 at 15:53 UTC ( [id://11112186]=note: print w/replies, xml ) Need Help??


in reply to RFC: List of first day of each month

Hi,

I eschew Time::Piece for date math. It has some weird internal issues with constants and overloading, which I don't completely understand, but people I trust including some wiser and more experienced Monks than I, recommend against it. (See e.g. comments in this discussion.)

Alternate solution using Time::Moment which IIUC is as accurate as DateTime but considerably lighter-weight:

use v5.10; use Time::Moment; my $tm1 = Time::Moment->new(year => '2019', month => '6', day => '1'); my $tm2 = Time::Moment->now; $tm1 = (say $tm1->strftime('%c') and $tm1->plus_months(1)) while $tm1 +<= $tm2;
Output:
Mon Jul 1 00:00:00 2019 Thu Aug 1 00:00:00 2019 Sun Sep 1 00:00:00 2019 Tue Oct 1 00:00:00 2019 Fri Nov 1 00:00:00 2019 Sun Dec 1 00:00:00 2019 Wed Jan 1 00:00:00 2020

Hope this helps!


The way forward always starts with a minimal test.

Replies are listed 'Best First'.
Re^2: RFC: List of first day of each month
by Your Mother (Archbishop) on Jan 31, 2020 at 17:07 UTC

    ++ Thank you very much for bringing this up. I had somehow missed this package and it’s exactly what I need for something right now. I love DateTime for its pedantic correctness and flexibility but it’s untenable for situations when you want to be creating thousands or millions of objects a second. I had backed up to using raw Date::Calc but it’s harder to mentally track and debug and pass around in a consistent way.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others sharing their wisdom with the Monastery: (3)
As of 2024-04-24 06:05 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found