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.