Code Monkey home page Code Monkey logo

isoduration's People

Contributors

bolsote avatar hugovk avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

isoduration's Issues

Implement repeating intervals

Once durations are properly parsed and arithmetic operations with them implemented, the next step would be to support ISO 8601 repeating intervals. These would be string such as this one:

R5/2008-03-01T13:00:00Z/P1Y2M10DT2H30M

This means we repeat the interval P1Y2M10DT2H30M 5 times, starting at 2008-03-01T13:00:00Z.

Recurring intervals are described in great detail in the standard ISO 8601, part 1.

Deprecation warning trigered in tests with Python3.12

I just want to let you know that Python3.12 newly triggers following warning:

================================================== warnings summary ===================================================
../../../../../../../usr/lib/python3.12/site-packages/dateutil/tz/tz.py:37
  /usr/lib/python3.12/site-packages/dateutil/tz/tz.py:37: DeprecationWarning: datetime.utcfromtimestamp() is deprecated and scheduled for removal in a future version. Use timezone-aware objects to represent datetimes in UTC: datetime.fromtimestamp(timestamp, datetime.UTC).
    EPOCH = datetime.datetime.utcfromtimestamp(0)

-- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html
=========================================== 263 passed, 1 warning in 3.63s ============================================
>>> Completed testing dev-python/isoduration-20.11.0-r1

Pin development dependencies

Right now, we have a fairly relaxed development requirements file. We should really pin all those versions, so we have a consistent environment everywhere. A pip-tools-based approach seems appropriate.

Durations without units aren't valid durations

Hi! (Thanks for the library).

I believe the below isn't valid under the spec:

isoduration.parse_duration("P1")

which should be invalid, as it has no unit, but instead returns:

Duration(DateDuration(years=Decimal('0'), months=Decimal('0'), days=Decimal('0'), weeks=Decimal('0')), TimeDuration(hours=Decimal('0'), minutes=Decimal('0'), seconds=Decimal('0')))

#21 is possibly related.

Basic technical documentation

We should create some basic documentation covering the most fundamental aspects of the library. We could start with:

  • The Duration type and what it provides.
  • str <-> Duration conversions (parsing/formatting).
  • Exception hierarchy.
  • How the test suite is organised.

unable to install the package

When running pip install isoduration==20.11.0 or pip install isoduration
I get the following error:

Could not find a version that satisfies the requirement isoduration (from versions: )
No matching distribution found for isoduration

This happens to me in multiple environments

isoduration ignores trailing garbage when parsing.

I was experimenting with the alternative duration format, and discovered some weird behavior:

>>> # Silently ignores alternate format when time is not provided
>>> isoduration.parse_duration('P0000-01-00')
Duration(DateDuration(years=Decimal('0'), months=Decimal('0'), days=Decimal('0'), weeks=Decimal('0')), TimeDuration(hours=Decimal('0'), minutes=Decimal('0'), seconds=Decimal('0')))
>>> # Doesn't handle alternate format duration with any of year/month/day being zero
>>> isoduration.parse_duration('P0000-00-00T00:00')
isoduration.parser.exceptions.UnparseableValue: Value could not be parsed as datetime: 0000-00-00T00:00
>>> # Ignores trailing numbers
>>> isoduration.parse_duration('P1MT1')
Duration(DateDuration(years=Decimal('0'), months=Decimal('1'), days=Decimal('0'), weeks=Decimal('0')), TimeDuration(hours=Decimal('0'), minutes=Decimal('0'), seconds=Decimal('0')))
>>> # Alternative format duration parsing accepts to many formats (e.g. YYYY-DDD)
>>> isoduration.parse_duration("P2020-123T00:00")
Duration(DateDuration(years=2020, months=5, days=2, weeks=Decimal('0')), TimeDuration(hours=0, minutes=0, seconds=0))
>>> # (note that this format causes the length in years to affect the number of days)
>>> isoduration.parse_duration("P2021-123T00:00")
Duration(DateDuration(years=2020, months=5, days=2, weeks=Decimal('0')), TimeDuration(hours=0, minutes=0, seconds=0))

0.5 values in date durations are considered valid but interpreted as 1

When 0.5 is used in a value, it ends up as 0.5 in the DateDuration but appears to actually increment a datetime by 1. This behaviour also seems to apply to YMD and HMS but W seems to work in an incomplete way.

from datetime import datetime
from isoduration import parse_duration
datetime(2023, 1, 1) + parse_duration('P0.5M')
# datetime.datetime(2023, 2, 1, 0, 0)
parse_duration('P0.5M')
# Duration(DateDuration(years=Decimal('0'), months=Decimal('0.5'), days=Decimal('0'), weeks=Decimal('0')), TimeDuration(hours=Decimal('0'), minutes=Decimal('0'), seconds=Decimal('0')))

inconsistent comparison

Is this a bug?

>>> from isoduration import parse_duration
>>> from datetime import datetime
>>> now = datetime.now()
>>> d1 = parse_duration('P4W')
>>> d2 = parse_duration('P28D')
>>> d1 == d2
False
>>> now + d1 == now + d2
True
>>> now + d1 - now == now + d2 - now
True

Solve all isodate issues

Given one of the main motivations of this library was to improve the approach taken by isodate, we should trawl their issue tracker, and make sure we actually solve the most important problems found there.

Properly support decimal points

We currently support decimal points at any point in the duration. In principle, this should only be allowed in the smallest value.

As a side effect, this would make it easier to properly manipulate the milliseconds part of the datetime in arithmetic operations.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.