Re:Things I learned while developing a billing system
by dirkt on Tuesday April 06, 2021 @12:41AM
(#26707994)
> My personal favorite: how long is a month?
One solution is to distinguish between a "datetime" and a "duration". You cannot convert a duration to days (or really anything). You can add or subtract a duration from a datetime, and you can convert the difference between two concrete datetimes into days.
And that's actually how some libraries already implement it.
So the answer to "how long is a month" is "it depends, and I can only say if you apply this duration to a concrete time".
One solution is to distinguish between a "datetime" and a "duration". You cannot convert a duration to days (or really anything). You can add or subtract a duration from a datetime, and you can convert the difference between two concrete datetimes into days.
And that's actually how some libraries already implement it.
So the answer to "how long is a month" is "it depends, and I can only say if you apply this duration to a concrete time".