Skip to content

unexpected results of as.duration() with negative periods #1187

@unDocUMeantIt

Description

@unDocUMeantIt

i was trying to sum up some positive and negative durations made from character strings via hm() and noticed odd results. i assume this is not supposed to happen, or am i getting something wrong:

> library(lubridate)

Attaching package:lubridateThe following objects are masked frompackage:base:

    date, intersect, setdiff, union

> x <- hm("-01:30")
> x
[1] "-1H 30M 0S"
> as.duration(x)
[1] "-1800s (~-30 minutes)"
> x <- hm("-02:30")
> x
[1] "-2H 30M 0S"
> as.duration(x)
[1] "-5400s (~-1.5 hours)"

i'm missing an hour here. this is not happening with positive periods:

> x <- hm("01:30")
> x
[1] "1H 30M 0S"
> as.duration(x)
[1] "5400s (~1.5 hours)"

i'm using lubridate version 1.9.3 with R version 4.4.3 on kubuntu 24.04.

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