An interesting bit of date relevance

Was working with a colleague today and he asked a great question. Why do some of these not exist, and is this a bug?

Q: month of (current date - 0 * month) as string
A: March
Q: month of (current date - 1 * month) as string
E: Singular expression refers to nonexistent object.
Q: month of (current date - 2 * month) as string
A: January
Q: month of (current date - 3 * month) as string
A: December
Q: month of (current date - 4 * month) as string
E: Singular expression refers to nonexistent object.
Q: month of (current date - 5 * month) as string

It turns out that when you take March 31, 2025 (a date) and subtract a month… well… there is no February 31 (another date) so the month of the non-existent date also does not exist.

Fortunately, there was an easy solve this. Simply do the Month Math vs the Month of the date instead of the day.

q: current month - month * 0
A: March
q: current month - month * 1
A: February
q: current month - month * 2
A: January
q: current month - month * 3
A: December
q: current month - month * 4
A: November
q: current month - month * 5
A: October
2 Likes

Note that current date will not be accurate if you leave your Fixlet Debugger running more than 1 day:

Q: current date
A: Fri, 14 Mar 2025
T: 0.069 ms
I: singular date

Q: now
A: Mon, 31 Mar 2025 13:41:09 -0600
T: 0.041 ms
I: singular time
1 Like

Update on the relevance. my colleague came back with a twist, because he wanted to get the Year of 4 months ago and was hitting existence again.

Solved with

q: year of (current month_and_year - (4 * month))
A: 2024

Generally, you can add months to “month like objects” where you do not have to know “how many days in a month”. As soon as you get a date like object, to add a month, you have to know how many days to add. You can add a specific month to a date, but not a general month object.

@itsmpro92 good times indeed! I have only hit that once in my years of BigFixing with a student doing a 3 day class. It was very puzzling when we came across it, but super rare, so it has never bubbled to the top of the urgent pile.

You’ve had your Fixlet Debugger open for 17 days?

:exploding_head:

It’s my lab environment :man_shrugging:. @brolly33’s comment reminded me that I had run into this issue while doing some content development around current date.

Not a bug! The language and date math are correctly erroring that no “2025-02-31” exists.

In the world of calendar interoperability, there is no “right” way to do this. In implementation, however…

  • Some systems appear to choke, as relevance does here.

    • This is generally regarded as bad.
  • Some systems error on “the prior month has 28 days and you’re on the 31st so we’ll punt and give you the last day of the prior month”: 2025-02-28.

    • This is more common.
    • Extra fun on leap years!
  • Some systems error on “the prior month is 3 shorter than this one, so we’ll punt and give you that month plus 3 days.” : 2025-03-03

    • This is less common.
    • The school of thought here emphasizes that “days” and “months” are different things. Best to give you all the days.
    • Extra super fun on leap years!

Fundamentally, however, it’s an implementation choice. The language should do exactly what it’s doing: report an error. The coder needs decide what you probably “meant”, know date math and date edge cases, and decide how to handle them.

As always, I point to this very amusing site.
https://yourcalendricalfallacyis.com

2 Likes

Regarding the Debugger issue, I found recently that current date may not be what you had in mind, but now as local date probably is.

2 Likes