How to get Unix Timestamp?
I noticed that DateTime doesn't support Unix Timestamp (seconds since 1/1/1970 UTC).
mbed has function time (example) but it's not working as time(NULL) only returns -1.
Also trying to use related function set_time from mbed gives error 'set_time' was not declared in this scope.
I will look at what it takes to implement the mbed (Clib style) time functions.
DateTime is a calendar based timestamp, that counts years, days etc. It implements the Gregorian calendar standard. Therefore I have postponed to implementing conversion to and from UNIX style time stamps.
It seems that converting from Gregorian calendar to Unix Time is easiest to do by first converting to JDN (Julian day number).
Wikipedia article https://en.wikipedia.org/wiki/Julian_day has needed formulas, from Gregorian year/month/date to JDN and then from JDN to Unix Time.
I can try to write this in C++ shortly.
I think it would be a good thing to replace the date / time manipulation implementations with libc's functions.
We can use localtime or gmtime for UTC time zones. These take a time_t and returns broken-down date and time components. The reverse can be done by timelocal or timegm.
The reverse can be done by timelocal or timegm.
I just realized the timelocal-like functions are missing from newlib-nano. And that is what we use on Mono.
EDIT: In newlib-nano (and newlib) the timelocal is called: mktime.
ok, I added pull request.
As for libc functions, timegm doesn't seem to be available and it seems to be a non-standard function. But as it seems to do basically same what I just added as DateTime::toUnixTime, I'm not sure if that is really needed.
UTC is somewhat simple to handle even without library functions, but localtime and especially daylight saving time is definitely not.