News for hackers. Stuff that matters.
Re:Day.js Fast 2kB alternative to Moment.js with the same mo... by forty on Sunday October 09, 2022 @03:46AM (#33138963)
Any operation like adding/substracting months from a date is very messy to implement yourself.

What is one month ago when you are March, 31st?

We have to deal with monthly subscriptions and it's not fun.

Re:Day.js Fast 2kB alternative to Moment.js with the same mo... by TekMol on Sunday October 09, 2022 @03:50AM (#33138970)
First you have to define what you mean by "one month ago". Is it 30 days ago? Or last month? Or a certain number of milliseconds ago?

No library can help you with that. You have to define what you actually want to calculate.

Re:Day.js Fast 2kB alternative to Moment.js with the same mo... by 9wzYQbTYsAIc on Sunday October 09, 2022 @04:05AM (#33139015)
At some point you will need to calculate how many leap years to account for and whether or not a leap second was introduced in between two arbitrary times.

Time libraries can help you with that.

Re:Day.js Fast 2kB alternative to Moment.js with the same mo... by forty on Sunday October 09, 2022 @06:01AM (#33139535)
Exactly there is the same problem, to a lesser extend, when adding/subtracting years which is not trivial to do properly.
Re:Day.js Fast 2kB alternative to Moment.js with the same mo... by 9wzYQbTYsAIc on Sunday October 09, 2022 @06:10AM (#33139575)
Let alone determining requirements for thresholds.

This discussion reminds me of this bug report: https://bugzilla.mozilla.org/show_bug.cgi?id=1715455

Re:Day.js Fast 2kB alternative to Moment.js with the same mo... by ponyous on Sunday October 09, 2022 @08:31AM (#33140397)
Why can’t you use Date.getFullYear with setFullYear?
Re:Day.js Fast 2kB alternative to Moment.js with the same mo... by forty on Sunday October 09, 2022 @05:56AM (#33139511)
Absolutely. moment has a definition of that and compute it in a consistent way, which is useful. But if you want to come up with a different definition then it cannot help you indeed.
Re:Day.js Fast 2kB alternative to Moment.js with the same mo... by throwaway0x7E6 on Sunday October 09, 2022 @05:33AM (#33139394)
>What is one month ago when you are March, 31st?

"one month ago" is between "a few weeks ago" and "a few months ago".

>We have to deal with monthly subscriptions and it's not fun.

it is a lot less unfun if you define a month as N calendar days in your terms of service, like virtually everyone does

Re:Day.js Fast 2kB alternative to Moment.js with the same mo... by forty on Sunday October 09, 2022 @05:58AM (#33139520)
Yes, that's what we do mostly, except to track external subscriptions that actually use months (I believe the Google playstore does that but I could be mistaken with another service)
Re:Day.js Fast 2kB alternative to Moment.js with the same mo... by inopinatus on Sunday October 09, 2022 @07:20AM (#33139978)
And they would be guilty of misleading the consumer when doing so, and possibly accounting fraud as well because neither GAAP nor IFRS recognise such a calendar; the closest available is the 4-4-5 standard.

This is why we don’t let engineers write contracts. Many seem to think that law is a programming language in which they can redefine reality. It ain’t.