Skip to content

duration ignores class of first argument #462

@klmr

Description

@klmr

See 🔗 Stack Overflow question.

In a nutshell, the following code

time = now()
five_sec = interval(time, time + 5)
duration(five_sec)
# [1] "5s"
duration(five_sec, units = 'days')
# [1] "432000s (~5 days)"

Yields an unexpected output for the last line because the class of five_sec is ignored, and its unit is overridden to be interpreted as days. This makes sense for a unitless num argument — but five_sec isn’t unitless by virtue of being an Interval.

The expected behaviour is that this should be disallowed — i.e. throw an error, or at least signal a stern warning that the interval’s unit is being ignored.

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