Double March

The date is now Monday, March 366th, 2020.

Sorry, you don't get a new March until you've finished the last one.

If you see anyone claiming that today is March 365th, congratulate them on fucking up their leap year math.

perl -e 'use Date::Parse; use POSIX; my @t = localtime; print strftime ("%a Mar ", @t) . int (1 + 0.5 + ((str2time (strftime ("%Y-%m-%d 3:00", @t)) - str2time ("2020-03-01 3:00")) /(60*60*24))) . strftime (" %X %Z 2020\n", @t);'

Mon Mar 366 09:14:24 PST 2020

Previously, previously, previously, previously, previously, previously, previously, previously, previously.

Tags: , , , ,

15 Responses:

  1. Chas. Owens says:

    Date::Parse isn't part of core perl, so that might not work on some people's machines, this should work everywhere with at least Perl 5.0.0:

    perl -MPOSIX -MTime::Local -e '@t = localtime; $d = int(1 + .5 + (timelocal(0,0,3,@t[3..5]) - timelocal(0,0,3,1,2,120))/(60*60*24)); print strftime "%a Mar $d %X %Z 2020n", @t'

    • Chas. Owens says:

      Huh, that are the backslash near the end, trying again:

      perl -e 'use Date::Parse; use POSIX; my @t = localtime; print strftime ("%a Mar ", @t) . int (1 + 0.5 + ((str2time (strftime ("%Y-%m-%d 3:00", @t)) - str2time ("2020-03-01 3:00")) /(60*60*24))) . strftime (" %X %Z 2020n", @t);'

      • Chas. Owens says:

        Okay, so I wasn't crazy, it did eat the backslash, trying one last time:

        perl -MPOSIX -MTime::Local -e '@t = localtime; $d = int(1 + .5 + (timelocal(0,0,3,@t[3..5])-timelocal(0,0,3,1,2,120))/(60*60*24)); print strftime "%a Mar $d %X %Z 2020\n", @t'

  2. Steve Downey says:

    It's not leap year math, it's just math. 1 + 365. We didn't cross a leap year day, it's just that there isn't a day 0. If Monday is the 1st and there are 7 days in a week, the next Monday is the 8th.
    I admit to having screwed this up this morning. But I'm blaming long march and monday.

  3. Mozai says:

    Why resort to str2time when you could use seconds since the epoch?
    echo $(( ($(date --utc +%s) - $(date --utc -d "2020-03-01T15:00" +%s) ) / 86400 ))
    1 day after March 1st is March 2nd.
    365 days after March 1st is March 366th.
    What's an example of someone doing it wrongly?

    • jwz says:

      Well, you've introduced two unnecessary unportable dependencies, first on bash, second on the Linux-specific syntax of 'date'. And third but most importantly, some days have 23 hours and some have 25.

      Please don't write any more time-related code.

      • Mozai says:

        I did not know software portability was a requirement; easily fixed if I know what I'm expected to target. I wanted to avoid string-to-date parsing and just use seconds-since-the-epoch... but using '/usr/bin/date -d' is just that. Damnit. Without string parsing I'll have to do something dumb like #define STARTOFPLAGUE 1583092800; which is not portable if not every machine has the same start-of-epoch. Portability is hard.

  4. jwz says:

    Probably time to post this again...

  5. Leonardo Herrera says:

    When I was young and full of hope and dreams, right at the beginning of this millenium, I wrote a date calculation routine in Perl. From it I quickly learned that there are lots of stuff that you should not even attempt to do: parsing HTML, do "simple" date arithmetic, write PDF, parse people's names, parse email, use SMTP, write your own database or custom file system, and oh so many more.

    From reading this blog I also stay the fuck away from writing screensavers.

  6. Moofie says:

    Probably time for this XKCD again

  7. Shervin says:

    So I was wondering; what's the criteria for when we can leave this double March timeline and go back to the the old one from before times? DNA Lounge re-opening festivities?

Leave a Reply

Your email address will not be published. But if you provide a fake email address, I will likely assume that you are a troll, and not publish your comment.

You may use these HTML tags and attributes: <a href="" title=""> <b> <blockquote cite=""> <code> <em> <i> <s> <strike> <strong> <img src="" width="" height="" style=""> <iframe src="" class=""> <video src="" class="" controls="" loop="" muted="" autoplay="" playsinline=""> <div class=""> <blink> <tt> <u>, or *italics*.

  • Previously