Skip to content

Support hms objects in the secs arg #159

@moodymudskipper

Description

@moodymudskipper

The round_hms() and trunk_hms() functions have a secs argument used to round or truncate to the closest multiple.
This expects an atomic number, but it would be great if we could provide a hms object to this argument, to easily round to the minute or hour.
In fact it would come for free if a pesky difftime method didn't get in the way.

library(hms)
t <- hms(100 * 1:5)

t
#> 00:01:40
#> 00:03:20
#> 00:05:00
#> 00:06:40
#> 00:08:20

round_hms(t, hms(minutes = 1))
#> Error in `/.difftime`(as.numeric(x), secs): second argument of / cannot be a "difftime" object

round_hms(t, as.numeric(hms(minutes = 1)))
#> 00:02:00
#> 00:03:00
#> 00:05:00
#> 00:07:00
#> 00:08:00

Should we vctrs::vec_cast(secs, numeric()) and document the feature ?

Defining /.hms would solve this too, and I see this is in progress in #120

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