Skip to content

Bugs in Duration edge cases #833

Description

@ariebovenberg
  • I am on the latest Pendulum version.
  • I have searched the issues of this repo and believe that this is not a duplicate.
  • OS version and name: MacOS 14.5
  • Pendulum version: 3.0

Issue

While tinkering with Duration, I found several bugs and edge cases that might be good to patch:

Parsing partially ignores long numbers

>>> parse ('PT999900000000000000000000000000000002S')
Duration(seconds=2)  # earlier digits get forgotten

Incorrectly duplicated components are parsed anyway, with inconsistent results

>>> parse("P12M4M")
Duration(months=4)  # should be an error, but takes the last one
>>> parse("PT12M3M1M")
Duration(minutes=16)  # should also be an error, but sums them

Values overflow

>>> parse("PT4294967297M")
Duration(minutes=1)

'empty' duration shouldn't be allowed

>>> parse('PT') 
Duration()  # should be an error, this isn't allowed in ISO8601

Strange month arithmetic

>>> parse("P1M") + Duration()
Duration(weeks=4, days=2)
>>> Duration(months=1) * 1.0
Duration()
>>> Duration(months=1) * 1
Duration(months=1)

Probably related to #799

Activity

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