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

lubridate hms function doesn't Roll hrs, min and secs correctly when added. #417

Closed
shoaibkhanz opened this Issue May 22, 2016 · 6 comments

Comments

Projects
None yet
2 participants
@shoaibkhanz

shoaibkhanz commented May 22, 2016

Lubridate hms function

hms("34:45:12") + hms("05:16:48") ; expected out is"40H 02M 00S"

However, the result looks like this

"39H 61M 60S"

@vspinu

This comment has been minimized.

Member

vspinu commented May 23, 2016

There is no automatic normalization of period components in lubridate. Components could be whatever and should give same result when used with date-times.

While normalization of hms would make sense, how would you you normalize periods that contain days months and years?

@shoaibkhanz

This comment has been minimized.

shoaibkhanz commented May 24, 2016

I believe the principle should be the same. In hms we need roll minutes and seconds and normalise hours accordingly
and in periods such as you describe it is days and months; years need normalising.
However, I currently do not have a solutions to it.

Do you agree to this?

@vspinu

This comment has been minimized.

Member

vspinu commented May 24, 2016

and in periods such as you describe it is days and months; years need normalising.

I don't understand this.

hms produces a period; so does period(year=1,month=20,m=100,s=1). If we roll in hms then we should roll in period as well and that's not possible because you cannot roll higher units.

What's your use case more concretely? Why do you need hms to roll up? If it does roll, when do you propose it to stop rolling, hours or days?

@shoaibkhanz

This comment has been minimized.

shoaibkhanz commented May 25, 2016

The case is , If i have a csv file that contain two columns of hours (hh:mm:ss) and i wish to know the total hours; a result such as this 40H 70M 70S isn't exactly right.

I am not concerned with periods including month or year. I am just concerned with (hh:mm:ss)

So I now have begun to think if its at all possible in R or perhaps I am too inclined to think in a csv(excel) way of storing hours.

Hope this explains my use case and the thought that i present.

@vspinu

This comment has been minimized.

Member

vspinu commented May 26, 2016

We should probably have normalize_period, or roll_period function to deal with such normalization. We can also add an optional argument to hms to automatically normalize the output. Doing it in arithmetic operations is tricky because there is no clear cut definition of rolling and it would add computational burden with not so clear benefits.

@vspinu vspinu added the enhancement label Jun 25, 2016

@vspinu vspinu closed this in acd775c Aug 17, 2016

@vspinu

This comment has been minimized.

Member

vspinu commented Aug 17, 2016

I have added roll=TRUE argument which rolls up to hours. There is no much point in rolling towards days.

I am still thinking if I should make that argument TRUE by default.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment