tolu / ISO8601-duration

Node/Js-module for parsing and making sense of ISO8601-durations
92 stars 10 forks source link

Fractional Time Doesn't Seem Correct in all Cases #7

Closed cgianelle closed 2 years ago

cgianelle commented 7 years ago

Certain instances of fractional time don't seem to compute properly when minutes are involved, for instance:

$ node
> var iso8601Duration = require("iso8601-duration");
undefined
> iso8601Duration.toSeconds(iso8601Duration.parse("PT0.5M"))
0 ===> expected 30
> iso8601Duration.toSeconds(iso8601Duration.parse('PT1H30M10.5S'))
5410.5
> iso8601Duration.toSeconds(iso8601Duration.parse("PT0H5M1.5S"))
301.5
> iso8601Duration.toSeconds(iso8601Duration.parse("PT1.5S"))
1.5
> iso8601Duration.toSeconds(iso8601Duration.parse("PT1.67S"))
1.67
> iso8601Duration.toSeconds(iso8601Duration.parse("PT0.67S"))
0.67
> iso8601Duration.toSeconds(iso8601Duration.parse("PT1.5M"))
60 ===> expected 90

Are my expectations here correct?

WORMSS commented 3 years ago

Just to add to this

toSeconds(parse(`P0.5D`))

returns 0

but also

parse(`P0.5DT0.5M`)

returns an object that is

{
   days: 0.5,
   minutes: 0.5,
   ... others are zero
}

but the iso spec says only the least significant can have a decimal.

tolu commented 2 years ago

updated logic to work with fractions like proposal-temporal handles it

tolu commented 2 years ago

updated logic to work with fractions like proposal-temporal handles it