wavebitscientific / datetime-fortran

Date and time manipulation for modern Fortran
MIT License
137 stars 50 forks source link

Processing of `secondsSinceEpoch` and its reverse processing routine. #80

Closed sakamoti closed 1 year ago

sakamoti commented 1 year ago

Added reverse processing of secondsSinceEpoch

This PR is related to the Issue #79.

sakamoti commented 1 year ago

It seems failed on windows OS because undefined reference to "gmtime_r" and "localtime_r". I use gmtime_r and localtime_r routine because of thread safety. Is anyone know thread safe routine which can be used any OS? Or should I write some pure fortran code to get same results? And I will now investigate why Cmake's ctest failed.

milancurcic commented 1 year ago

I think gmtime_r and localtime_r are POSIX only. We could use them on Linux and macOS and fall back to gmtime and localtime on Windows only.

sakamoti commented 1 year ago

Thank you, I didn't know it was a POSIX function. I feel that "datetime-fortran" defines a lot of "pure elemental" functions and it is not good to fall back to thread-unsafe functions here. I would like the library to be usable for large scale parallel computing, so I have rewritten codes to make it independent of C functions.

milancurcic commented 1 year ago

Thank you, I like your approach. One quick question for now: where in multiple places you have epoc in variable and procedure names, should that not be epoch?

sakamoti commented 1 year ago

That is my misspelling. Thank you for pointing that out. And of the parts I added as C-dependent parts, c_mktime was left unremoved, so I'll comment it out. I will revise and push it later.

In addition, I want to make localtime becomes "pure elemental", so I may make some modifications.

One candidate I am considering

type(datetime), allocatable :: day(:)
integer(int64) ::epoch(100)
day = localtime(epoch,tz=[hour,minute])
sakamoti commented 1 year ago

Finish! The code has been corrected. Documentation has also been added.