Hacker News new | ask | show | jobs
by sylware 521 days ago
Until you understand that the core of unix time is the "day", in the end, you only need to know the first leap year (If I recall properly it is 1972), then you have to handle the "rules" of leap years, and you will be ok (wikipedia I think, don't use google anymore since they now force javascript upon new web engines).

I did write such code in RISC-V assembly (for a custom command line on linux to output the statx syscall output). Then, don't be scared, with a bit of motivation, you'll figure it out.

1 comments

The core of the UNIX time is seconds since epoch, nothing else. 'Day' has no special place at all. There are calendars for converting to and from dates, including Western-style, but the days in those calendars vary in length because of daylight saving switches and leap seconds for example.
UNIX time ignores leap seconds, so every day is exactly 86400 seconds, and every year is either 365*86400 or 366*86400 seconds. This makes converting from yyyy-mm-dd to UNIX time quite easy, as you can just do `365*86400*(yyyy-1970) + leap_years*86400` to get to yyyy-01-01.
Yeap, this is why I said it is kind of easy.

Until you know properly the leap years. Leap year rules on the long run are are bit funky. Just have a look at wikipedia.

(do not use gogol search since they are now forcing javascript by default)

Well yes, in the sense that not all Unix epoch seconds are equally long...
You are perfectly wrong, the day is the main calendar object related to the epoch seconds.

I wrote conversion code, I know what I am talking about.