Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Missing conversions in calendar #8160

Open
MarkoMin opened this issue Feb 20, 2024 · 4 comments
Open

Missing conversions in calendar #8160

MarkoMin opened this issue Feb 20, 2024 · 4 comments
Assignees
Labels
enhancement stalled waiting for input by the Erlang/OTP team team:VM Assigned to OTP team VM
Milestone

Comments

@MarkoMin
Copy link
Contributor

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.

@IngelaAndin IngelaAndin added the team:VM Assigned to OTP team VM label Feb 20, 2024
@paulo-ferraz-oliveira
Copy link
Contributor

👍 the other day we were also looking at this. Lemme add we feel the following is also missing: conversion from Gregorian seconds to Unix time and back.

There's this magic number, 62167219200, that is mentioned at least 6 times in 5 different files of the current OTP code base, for example. On the other hand, maybe it's not been included because it was not deemed generic enough (?)

@MarkoMin
Copy link
Contributor Author

MarkoMin commented Feb 22, 2024

LOL, so datetime->unixtime is significantly less generic than the other way around and only way to do this is to either datetime -> string -> unixtime or to reimplement logic from the conversion? The conversion is already implemented in rfc3339_to_system_time/1 and erlang:universaltime_to_posixtime/1 which is undocumented BIF and unfortunately returns in seconds...

EDIT: rfc3339_to_system_time/1 does the conversion by first parsing rfc3339 to datetime and then converts datetime to system time

@KunaPrime
Copy link

KunaPrime commented Feb 22, 2024

@MarkoMin i also want to point out magic OR mistake here:

  • magic: issue Missing conversions in calendar #8160 dealing with time that is ISO 8601 standardized (same digits)
  • mistake: you should have waited for 441 issues more, so that issue number would be the same as in ISO

@bjorng bjorng added the stalled waiting for input by the Erlang/OTP team label Feb 27, 2024
@bjorng bjorng added this to the OTP-28.0 milestone Feb 27, 2024
@bjorng
Copy link
Contributor

bjorng commented Feb 27, 2024

After the first release candidate, we generally focus on bug fixes and polishing of features already included or planned for the release. To ensure that Erlang/OTP 27 will be as good as it possibly can be, we need to minimize the time we spend on things not to be included in the release. Therefore, we will not investigate/consider this feature request until after OTP 27 has been released. If we have not came back to it before September, feel free to remind us.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement stalled waiting for input by the Erlang/OTP team team:VM Assigned to OTP team VM
Projects
None yet
Development

No branches or pull requests

5 participants