Time is Hard (for computers & programmers)
Blue Shaman
11

Time isn’t hard, but the math isn’t fun

One thing that should be noted is that Unix time does not include leap seconds! When one occurs, it just stays on the same second for two seconds. That’s why we can create time functions that look like the following:

Notice how there is no adjustment needed for leap seconds

One thing that can be tricky however, is getting the year with exact precision. The average number of days in 400 Years is 365.2425, not including leap seconds. However, the number of years we divide by 356.2425 almost never has an average of 365.2425 days per year.

I have figured out my own means of calculating the year/month/day triple, but I eventually found some algorithms online that are much more efficient. Here is the Lua version of these algorithms:

These algorithms were implemented into the os.lua module in Nevermore Engine. Check it out for great modules with powerful and fast algorithms!

One clap, two clap, three clap, forty?

By clapping more or less, you can signal to us which stories really stand out.