Skip to content

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

Closed

Description

@shoaibkhanz

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"

Activity

  1. vspinu commented on May 23, 2016

    @vspinu
    Member

    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?

  2. shoaibkhanz commented on May 24, 2016

    @shoaibkhanz
    Author

    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?

  3. vspinu commented on May 24, 2016

    @vspinu
    Member

    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?

  4. shoaibkhanz commented on May 25, 2016

    @shoaibkhanz
    Author

    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.

  5. vspinu commented on May 26, 2016

    @vspinu
    Member

    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.

  6. vspinu commented on Aug 17, 2016

    @vspinu
    Member

    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions