otp icon indicating copy to clipboard operation
otp copied to clipboard

Missing conversions in `calendar`

Open MarkoMin opened this issue 1 year ago • 6 comments

Is your feature request related to a problem? Please describe. The problem arises when you want to convert system time to datetime and vice versa. There are functions calendar:system_time_to_local_time/1 and calendar:system_time_to_local_time/1, but the inverse functions are missing (universal_time_to_system_time/1 and local_time_to_system_time/1).

Describe the solution you'd like I'd like those 2 functions introduced. Also, rfc3339_to_datetime/local_time/universal_time might be convenient, because currently you have to first transform it to system time and then to datetime/local/utc.

Describe alternatives you've considered Currently, I manually construct RFC3339 string from datetime and then call calendar:rfc3339_to_system_time/1, which is both hacky and inefficient.

Additional context These could be nicely property-tested: T = universal_time_to_system_time(system_time_to_universal_time(T)).

I'm willing to make a PR if anyone can confirm that those functions are suitable to be in calendar.

MarkoMin avatar Feb 20 '24 10:02 MarkoMin