You are browsing as a guest. Sign up (or log in) to start making projects!

2h 43m 53s logged

Darian Calendar C Library: ammarstime

Probably the hurdle that will be the second hardest part of the entire libspacetime library is ammarstime. It is the same as the C stdlib’s “gmtime”, which, from a timestamp, returns a broken down time structure (struct tm) of the date/time info of that timestamp (the human readable info like day, month, year, etc.)

This is actually difficult. Seconds just count up, and you have to go backwards. You can try to divide by the amount of seconds in a year, but what about leap years?

Honestly, the math is too weird, even for me. Some parts make sense, but the rest, eh…

I referred to musl’s “secs_to_tm” function for how it did the calculations. This is what mostly guided my work, with a few pieces of calculation and numbers help from Google AI search results.

I didn’t write a test suite for this function, because I think it will be easier to do once I knock down what will be the hardest kinds of functions: *string manipulation *(e.g. strftime)

But now that I have a way to convert seconds to a mars_tm struct, it should make everything else somewhat easier. Hopefully.

0
2

Comments 0

No comments yet. Be the first!