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

Bug in calendar:rfc3339_to_system_time/2 with fractional seconds before the unix epoch #9279

Open
lpil opened this issue Jan 9, 2025 · 2 comments · May be fixed by #9280
Open

Bug in calendar:rfc3339_to_system_time/2 with fractional seconds before the unix epoch #9279

lpil opened this issue Jan 9, 2025 · 2 comments · May be fixed by #9280
Labels
bug Issue is reported as a bug team:VM Assigned to OTP team VM

Comments

@lpil
Copy link
Contributor

lpil commented Jan 9, 2025

Hello friends.

Ryan Moore has been working on RFC3339 timestamp parsing for Gleam and found a behaviour in calendar:rfc3339_to_system_time/2 that we don’t understand, and I’m worried it may be a bug. Our conversation can be read here on GitHub, and I’ll summarise here.

In Erlang, for negative timestamps, the fractional part of the timestamp appears to be representing a fraction into the previous second.

To Reproduce

8> calendar:rfc3339_to_system_time("1969-12-31T23:59:58.5Z", [{unit, millisecond}]).
-2500
9> calendar:rfc3339_to_system_time("1969-12-31T23:59:59.5Z", [{unit, millisecond}]).
-1500
10> calendar:rfc3339_to_system_time("1970-01-01T00:00:00.5Z", [{unit, millisecond}]).
500
11> calendar:rfc3339_to_system_time("1970-01-01T00:00:01.5Z", [{unit, millisecond}]).
1500

Expected behavior

This is different from the other languages which Ryan tested with: JavaScript, Rust, Python, Ruby, Java, and OCaml. They treat the fractional part of the timestamp as being a traction into the current second.

> d = new Date("1969-12-31T23:59:58.5Z"); d.getTime()
-1500
> d = new Date("1969-12-31T23:59:59.5Z"); d.getTime()
-500
> d = new Date("1970-01-01T00:00:00.5Z"); d.getTime()
500
> d = new Date("1970-01-01T00:00:01.5Z"); d.getTime()
1500

Affected versions

OTP27

Additional context
Prior discussion: https://erlangforums.com/t/possible-bug-in-calendar-rfc3339-to-system-time-2-with-fractional-seconds-before-the-unix-epoch/

@lpil lpil added the bug Issue is reported as a bug label Jan 9, 2025
@IngelaAndin IngelaAndin added the team:VM Assigned to OTP team VM label Jan 10, 2025
@Maria-12648430
Copy link
Contributor

The reverse function is also buggy:

> calendar:system_time_to_rfc3339(-500, [{unit, millisecond}, {offset, 0}]).
"1970-01-01T00:00:00.500+00:00"

@Maria-12648430
Copy link
Contributor

... and now also fixed in the linked PR 😺

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Issue is reported as a bug team:VM Assigned to OTP team VM
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants