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

Wrong offset documentation for calendar:system_time_to_rfc3339/2 #9081

Open
eproxus opened this issue Nov 18, 2024 · 1 comment
Open

Wrong offset documentation for calendar:system_time_to_rfc3339/2 #9081

eproxus opened this issue Nov 18, 2024 · 1 comment
Assignees
Labels
bug Issue is reported as a bug team:VM Assigned to OTP team VM

Comments

@eproxus
Copy link
Contributor

eproxus commented Nov 18, 2024

Describe the bug
The type offset() is defined as:

[byte()] | (Time :: integer()).

The documentation for calendar:system_time_to_rfc3339/2 states:

{offset, Offset} - The offset, either a string or an integer, to be included in the formatted string. An empty string, which is the default, is interpreted as local time. A non-empty string is included as is. The time unit of the integer is the same as the one of Time.

(my emphasis)

However, only the value "Z" is allowed.

To Reproduce

1> calendar:system_time_to_rfc3339(erlang:system_time(), [{unit, nanosecond}, {offset, "Foobar"}]).
** exception error: bad argument
     in function  list_to_integer/1
        called as list_to_integer("oo")
        *** argument 1: not a textual representation of an integer
     in call from calendar:offset_string_adjustment/3 (calendar.erl, line 975)
     in call from calendar:system_time_to_rfc3339_do/4 (calendar.erl, line 698)
2> calendar:system_time_to_rfc3339(erlang:system_time(), [{unit, nanosecond}, {offset, "A"}]).
** exception error: no match of right hand side value "A"
     in function  calendar:offset_string_adjustment/3 (calendar.erl, line 974)
     in call from calendar:system_time_to_rfc3339_do/4 (calendar.erl, line 698)

Expected behavior
Either the documentation (and type) should say only "Z" is allowed, or the function should allow any string as documented.

Affected versions
27.1.2

Additional context
The RFC's grammar only allows Z as a letter, so the documentation and type should probably be fixed instead. If that is the desired outcome, I can make a PR for that.

@eproxus eproxus added the bug Issue is reported as a bug label Nov 18, 2024
@eproxus eproxus changed the title Wrong offset documentation for calendar:system_time_to_rfc3339 Wrong offset documentation for calendar:system_time_to_rfc3339/2 Nov 18, 2024
@IngelaAndin IngelaAndin added the team:VM Assigned to OTP team VM label Nov 19, 2024
@garazdawi
Copy link
Contributor

Hello! Yes, the documentation should be updated to only specify "Z" / "z" / "+HH:MM" / "-HH:MM". I don't think we can make the type any more precise as the closest we get is [$Z,$z,$+,$-,$0,$1,$2,$3,$4,$5,$6,$7,$8,$9,$:] which is not a lot more helpful versus the current type.

@garazdawi garazdawi self-assigned this Nov 19, 2024
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

No branches or pull requests

3 participants