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

Implement comparaison with character and -/+ #79

Closed
statquant opened this issue Nov 21, 2019 · 3 comments
Closed

Implement comparaison with character and -/+ #79

statquant opened this issue Nov 21, 2019 · 3 comments

Comments

@statquant
Copy link

Hello, that would be great if hms could implement comparaison with character like Date or nanotime, right now it does not throw and the result is wrong

as_hms("16:00:00") < "16:30:00"
[1] FALSE

That would also be great if we could use operators - and +

# class is lost
as_hms("16:00:00") - 1
Time difference of 57599 secs
# class is lost
as_hms("16:00:00") - as_hms("00:00:01")
Time difference of 57599 secs
# I'd expect this result
as_hms(as_hms("16:00:00") - 1)
15:59:59
@krlmlr
Copy link
Member

krlmlr commented Dec 31, 2019

Thanks.

I don't think that comparison with a string is a good idea, can you parse before comparing to make it explicit?

library(hms)
as_hms("16:00:00") < as_hms("16:30:00")
#> [1] TRUE
as_hms("17:00:00") < as_hms("16:30:00")
#> [1] FALSE

Created on 2019-12-31 by the reprex package (v0.3.0)

Unfortunately, the current design makes it very difficult to preserve the "hms" class after arithmetic operations, again you need to coerce with as_hms(). Original issue: #18.

@krlmlr krlmlr closed this as completed Dec 31, 2019
@statquant
Copy link
Author

Hello, I can definitely make it explicit but truth is I do not really want to. I guess you're afraid people start silently to use comparison on 1000000s of items, maybe we can check for right end side to be of lenghth 1 ?

@github-actions
Copy link

github-actions bot commented Jan 2, 2021

This old thread has been automatically locked. If you think you have found something related to this, please open a new issue and link to this old issue if necessary.

@github-actions github-actions bot locked and limited conversation to collaborators Jan 2, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants