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

Parsing/formatting ISO 8601 years less than zero or greater than 9999 #49

Open
trevorld opened this issue Dec 21, 2022 · 2 comments
Open
Milestone

Comments

@trevorld
Copy link

Not entirely sure if you should care about such years but I noticed while playing around that {parttime} doesn't always correctly parse/format ISO 8601 years less than zero or greater than 9999

According to Wikipedia years less than zero or greater than 9999 should be at least four digits wide and prependend with either a "+" or a "-" e.g.

+12345
-12345
-0004

I do observe that negative numbers strictly less than -999 seem to be formatted correctly.

@dgkf
Copy link
Owner

dgkf commented Dec 21, 2022

Thanks for reporting. I'm a bit embarrassed to say that it never crossed my mind to test this.

Seems like it would be a reasonably straightforward fix in the regex used for ISO-8601 parsing to allow years >4 digits.

- "(?<year>[\\+-]?\\d{4}(?!\\d{2}\\b))",
+ "(?<year>[\\+-]?\\d{4,}(?!\\d{2}\\b))",

@dgkf dgkf added this to the v0.1.1 milestone Dec 21, 2022
@dgkf
Copy link
Owner

dgkf commented Jan 3, 2023

Just documenting another artifact of this behavior, printing of negative parttime years uses the - as part of the four digits. Not strictly incorrect, but makes it harder to round-trip the data as a string:

as.parttime("-0003")
## <partial_time<YMDhms+tz>[1]> 
## [1] "-003" 

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants