https://xkcd.com/2867

Alt text:

It’s not just time zones and leap seconds. SI seconds on Earth are slower because of relativity, so there are time standards for space stuff (TCB, TGC) that use faster SI seconds than UTC/Unix time. T2 - T1 = [God doesn’t know and the Devil isn’t telling.]

You are viewing a single thread.
View all comments View context
13 points

Using YearMonth.atEndOfMonth would have been the easier choice there, I think

permalink
report
parent
reply
15 points

holy shit, yeah it would have. tyvm, I’ll be putting in a PR first thing monday!

permalink
report
parent
reply
5 points

Would you mind trying to explain (ELI5 style) what you did before and why you are excited for this new method for those of us who dont understand code?

permalink
report
parent
reply
8 points

it does in a way that’s been reviewed, vetted and tested by a lot of people the thing that I’m trying to do with code that’s only ever been seen by me and one other guy and has been tested to this best of my ability, which i hope is quite good but one person can easily miss edge cases and weird coincidences.

permalink
report
parent
reply
5 points
*

To break it down a bit further, the code that was provided is specifically trying to get the last day of a month, which I’ll call Month X since it will vary. The code is doing these things, in this order:

  1. Get the month after Month X
  2. If Month X is 12 (aka December) get Month 1 instead (aka January)
  3. Get the Date that is day 1 of the Month from step 2
  4. Get the Date that is one day before the Date from step 3

All this to get the last day of the month from Month X. The reason they did it this way is so they didn’t have to say “Is this February? Then get day 28. Is this January/March/etc? then get day 31.” and so on.

The code that the other user provided will instead get the last day of Month X without having to do all those steps. It’s doing something in the background to get the same data, but the coder doesn’t have to worry about exactly how because they can trust it will work as expected.

It ultimately boils down to the user carving out a round piece of wood, fitting it on an axle and bolting it on, then to find someone already has cheap wheels for sale that are more stable than what they just made.

permalink
report
parent
reply

xkcd

!xkcd@lemmy.world

Create post

A community for a webcomic of romance, sarcasm, math, and language.

Community stats

  • 1.9K

    Monthly active users

  • 234

    Posts

  • 5.6K

    Comments

Community moderators