Skip to content
New issue

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

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

Already on GitHub? # to your account

hms parsers: negative components vs negative period #511

Closed
alchenist opened this issue Jan 25, 2017 · 6 comments
Closed

hms parsers: negative components vs negative period #511

alchenist opened this issue Jan 25, 2017 · 6 comments

Comments

@alchenist
Copy link

The ability to handle negative components in the hms parsers (from commit a8ade12 fixing #333) is welcome. However, I commonly encounter periods where the #dicated at the beginning applies to the entire period, where we would expect_that(hms("-01:30:00"), equals(hours(-1) + minutes(-30) + seconds(0))). Current behavior would pass this instead: expect_that(hms("-01:30:00"), equals(hours(-1) + minutes(30) + seconds(0)))

Should there be support for cases where individual components take the initial sign, in addition to cases where each component is signed?

@vspinu
Copy link
Member

vspinu commented Jan 29, 2017

Where do you encounter such format? Is there a standardized rule for such format somewhere?

The only option I see is to add an extra argument to hms for this case.

@alchenist
Copy link
Author

alchenist commented Feb 2, 2017

Not quite; I don't think there's a standard for either representation of negative durations, but leading negatives for multi-part durations do have precedent: see the interpretation of ISO 8601 durations in the W3C XML schema datatype spec, which allows for a preceding minus # front of the entire duration to indicate a negative duration and only allows unsigned components.

An optional preceding minus sign ('-') is allowed, to indicate a negative duration. If the sign is omitted a positive duration is indicated.
...
P-1347M is not allowed although -P1347M is allowed.

Other parsers, like Moment.js, also only allow mixed signs within a single duration.

As of 2.13.0, mixed negative and positive signs are supported when parsing durations.
moment.duration('PT-6H3M')

@vspinu
Copy link
Member

vspinu commented Feb 2, 2017

So what would you suggest in terms of UI? We actually need to implement ISO 8601 anyways, so maybe just go that way?

@vspinu
Copy link
Member

vspinu commented May 7, 2017

I am inclined to have mixed signs within durations. Making negative duration is easy by unary - after the parsing.

@vspinu
Copy link
Member

vspinu commented Oct 4, 2017

I decided not to take any action on this. Preprocessing leading - in a string is trivial, and negating the whole duration is immideate with unary - after parsing. It's just not worth the implementation complexity, especially that the compatibility preserving UI is not obvious.

Something to consider for potential lubridate's rewrite though.

@vspinu vspinu closed this as completed Oct 4, 2017
@vspinu vspinu added the wontfix label Oct 4, 2017
@bbolker
Copy link

bbolker commented Dec 6, 2023

This came up again: https://stackoverflow.com/questions/77614470/r-hms-converts-negative-values-to-positive-but-shouldnt/77614817#77614817

Would a pull request for a change to the documentation that clarifies this point be considered ... ?

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

No branches or pull requests

3 participants