RelativeTimeBuilder
===================
aniso8601 builder for dateutil relativedeltas
---------------------------------------------
Features
========
* Provides :code:`RelativeTimeBuilder` compatible with `aniso8601 <https://bitbucket.org/nielsenb/aniso8601>`_
* Returns `dateutil <https://dateutil.readthedocs.io/en/stable/relativedelta.html>`_ :code:`relativedelta` objects for durations
Installation
============
The recommended installation method is to use pip::
$ pip install relativetimebuilder
Alternatively, you can download the source (git repository hosted at `Bitbucket <https://bitbucket.org/nielsenb/relativetimebuilder>`_) and install directly::
$ python setup.py install
Use
===
Parsing datetimes
-----------------
To parse a typical ISO 8601 datetime string::
>>> import aniso8601
>>> from relativetimebuilder import RelativeTimeBuilder
>>> aniso8601.parse_datetime('1977-06-10T12:00:00', builder=RelativeTimeBuilder)
datetime.datetime(1977, 6, 10, 12, 0)
Alternative delimiters can be specified, for example, a space::
>>> aniso8601.parse_datetime('1977-06-10 12:00:00', delimiter=' ', builder=RelativeTimeBuilder)
datetime.datetime(1977, 6, 10, 12, 0)
Both UTC (Z) and UTC offsets for timezones are supported::
>>> aniso8601.parse_datetime('1977-06-10T12:00:00Z', builder=RelativeTimeBuilder)
datetime.datetime(1977, 6, 10, 12, 0, tzinfo=+0:00:00 UTC)
>>> aniso8601.parse_datetime('1979-06-05T08:00:00-08:00', builder=RelativeTimeBuilder)
datetime.datetime(1979, 6, 5, 8, 0, tzinfo=-8:00:00 UTC)
Leap seconds are explicitly not supported::
>>> aniso8601.parse_datetime('2018-03-06T23:59:60', builder=RelativeTimeBuilder)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/nielsenb/Jetfuse/aniso8601/aniso8601/aniso8601/time.py", line 132, in parse_datetime
return builder.build_datetime(datepart, timepart)
File "/home/nielsenb/Jetfuse/aniso8601/aniso8601/aniso8601/builders/python.py", line 181, in build_datetime
cls._build_object(time))
File "/home/nielsenb/Jetfuse/aniso8601/aniso8601/aniso8601/builders/__init__.py", line 64, in _build_object
ss=parsetuple[2], tz=parsetuple[3])
File "/home/nielsenb/Jetfuse/aniso8601/aniso8601/aniso8601/builders/python.py", line 141, in build_time
raise LeapSecondError('Leap seconds are not supported.')
aniso8601.exceptions.LeapSecondError: Leap seconds are not supported.
Parsing dates
-------------
To parse a date represented in an ISO 8601 string::
>>> import aniso8601
>>> from relativetimebuilder import RelativeTimeBuilder
>>> aniso8601.parse_date('1984-04-23', builder=RelativeTimeBuilder)
datetime.date(1984, 4, 23)
Basic format is supported as well::
>>> aniso8601.parse_date('19840423', builder=RelativeTimeBuilder)
datetime.date(1984, 4, 23)
To parse a date using the ISO 8601 week date format::
>>> aniso8601.parse_date('1986-W38-1', builder=RelativeTimeBuilder)
datetime.date(1986, 9, 15)
To parse an ISO 8601 ordinal date::
>>> aniso8601.parse_date('1988-132', builder=RelativeTimeBuilder)
datetime.date(1988, 5, 11)
Parsing times
-------------
To parse a time formatted as an ISO 8601 string::
>>> import aniso8601
>>> from relativetimebuilder import RelativeTimeBuilder
>>> aniso8601.parse_time('11:31:14', builder=RelativeTimeBuilder)
datetime.time(11, 31, 14)
As with all of the above, basic format is supported::
>>> aniso8601.parse_time('113114', builder=RelativeTimeBuilder)
datetime.time(11, 31, 14)
A UTC offset can be specified for times::
>>> aniso8601.parse_time('17:18:19-02:30', builder=RelativeTimeBuilder)
datetime.time(17, 18, 19, tzinfo=-2:30:00 UTC)
>>> aniso8601.parse_time('171819Z', builder=RelativeTimeBuilder)
datetime.time(17, 18, 19, tzinfo=+0:00:00 UTC)
Reduced accuracy is supported::
>>> aniso8601.parse_time('21:42', builder=RelativeTimeBuilder)
datetime.time(21, 42)
>>> aniso8601.parse_time('22', builder=RelativeTimeBuilder)
datetime.time(22, 0)
A decimal fraction is always allowed on the lowest order element of an ISO 8601 formatted time::
>>> aniso8601.parse_time('22:33.5', builder=RelativeTimeBuilder)
datetime.time(22, 33, 30)
>>> aniso8601.parse_time('23.75', builder=RelativeTimeBuilder)
datetime.time(23, 45)
Leap seconds are explicitly not supported and attempting to parse one raises a :code:`LeapSecondError`::
>>> aniso8601.parse_time('23:59:60', builder=RelativeTimeBuilder)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/nielsenb/Jetfuse/aniso8601/aniso8601/aniso8601/time.py", line 117, in parse_time
return _RESOLUTION_MAP[get_time_resolution(timestr)](timestr, tz, builder)
File "/home/nielsenb/Jetfuse/aniso8601/aniso8601/aniso8601/time.py", line 166, in _parse_second_time
return builder.build_time(hh=hourstr, mm=minutestr, ss=secondstr, tz=tz)
File "/home/nielsenb/Jetfuse/aniso8601/aniso8601/aniso8601/builders/python.py", line 141, in build_time
raise LeapSecondError('Leap seconds are not supported.')
aniso8601.exceptions.LeapSecondError: Leap seconds are not supported.
Parsing durations
-----------------
Parsing durations returns :code:`relativedelta` objects from `dateutil <https://dateutil.readthedocs.io/en/stable/relativedelta.html>`_ for calendar level accuracy.
To parse a duration formatted as an ISO 8601 string::
>>> import aniso8601
>>> from relativetimebuilder import RelativeTimeBuilder
>>> aniso8601.parse_duration('P1Y2M3DT4H54M6S', builder=RelativeTimeBuilder)
relativedelta(years=+1, months=+2, days=+3, hours=+4, minutes=+54, seconds=+6)
Reduced accuracy is supported::
>>> aniso8601.parse_duration('P1Y', builder=RelativeTimeBuilder)
relativedelta(years=+1)
A decimal fraction is allowed on the lowest order element::
>>> aniso8601.parse_duration('P1YT3.5M', builder=RelativeTimeBuilder)
relativedelta(years=+1, minutes=+3.5)
The decimal fraction can be specified with a comma instead of a full-stop::
>>> aniso8601.parse_duration('P1YT3,5M', builder=RelativeTimeBuilder)
relativedelta(years=+1, minutes=+3.5)
Decimal fractions are not supported for years or months as calendar level accuracy would not be guaranteed::
>>> aniso8601.parse_duration('P1Y2.5M', builder=RelativeTimeBuilder)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/nielsenb/Jetfuse/aniso8601/aniso8601/aniso8601/duration.py", line 30, in parse_duration
return _parse_duration_prescribed(isodurationstr, builder)
File "/home/nielsenb/Jetfuse/aniso8601/aniso8601/aniso8601/duration.py", line 75, in _parse_duration_prescribed
return _parse_duration_prescribed_notime(durationstr, builder)
File "/home/nielsenb/Jetfuse/aniso8601/aniso8601/aniso8601/duration.py", line 119, in _parse_duration_prescribed_notime
PnW=weekstr, PnD=daystr)
File "relativetimebuilder/__init__.py", line 24, in build_duration
raise RelativeValueError('Fractional months and years are not '
relativetimebuilder.RelativeValueError: Fractional months and years are not defined for relative durations.
>>> aniso8601.parse_duration('P1.5Y', builder=RelativeTimeBuilder)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/nielsenb/Jetfuse/aniso8601/aniso8601/aniso8601/duration.py", line 30, in parse_duration
return _parse_duration_prescribed(isodurationstr, builder)
File "/home/nielsenb/Jetfuse/aniso8601/aniso8601/aniso8601/duration.py", line 75, in _parse_duration_prescribed
return _parse_duration_prescribed_notime(durationstr, builder)
File "/home/nielsenb/Jetfuse/aniso8601/aniso8601/aniso8601/duration.py", line 119, in _parse_duration_prescribed_notime
PnW=weekstr, PnD=daystr)
File "relativetimebuilder/__init__.py", line 24, in build_duration
raise RelativeValueError('Fractional months and years are not '
relativetimebuilder.RelativeValueError: Fractional months and years are not defined for relative durations.
Parsing a duration from a combined date and time is supported as well::
>>> aniso8601.parse_duration('P0001-01-02T01:30:5', builder=RelativeTimeBuilder)
relativedelta(years=+1, months=+1, days=+2, hours=+1, minutes=+30, seconds=+5)
Parsing intervals
-----------------
Intervals are built using :code:`relativedelta` objects from `dateutil <https://dateutil.readthedocs.io/en/stable/relativedelta.html>`_ for calendar level accuracy.
To parse an interval specified by a start and end::
>>> import aniso8601
>>> from relativetimebuilder import RelativeTimeBuilder
>>> aniso8601.parse_interval('2007-03-01T13:00:00/2008-05-11T15:30:00', builder=RelativeTimeBuilder)
(datetime.datetime(2007, 3, 1, 13, 0), datetime.datetime(2008, 5, 11, 15, 30))
Intervals specified by a start time and a duration are supported::
>>> aniso8601.parse_interval('2007-03-01T13:00:00/P1Y2M10DT2H30M', builder=RelativeTimeBuilder)
(datetime.datetime(2007, 3, 1, 13, 0), datetime.datetime(2008, 5, 11, 15, 30))
A duration can also be specified by a duration and end time::
>>> aniso8601.parse_interval('P1M/1981-04-05', builder=RelativeTimeBuilder)
(datetime.date(1981, 4, 5), datetime.date(1981, 3, 5))
Notice that the result of the above parse is not in order from earliest to latest. If sorted intervals are required, simply use the :code:`sorted` keyword as shown below::
>>> sorted(aniso8601.parse_interval('P1M/1981-04-05', builder=RelativeTimeBuilder))
[datetime.date(1981, 3, 5), datetime.date(1981, 4, 5)]
The end of an interval is returned as a :code:`datetime` when required to maintain the resolution specified by a duration, even if the duration start is given as a date::
>>> aniso8601.parse_interval('2014-11-12/PT4H54M6.5S', builder=RelativeTimeBuilder)
(datetime.date(2014, 11, 12), datetime.datetime(2014, 11, 12, 4, 54, 6, 500000))
>>> aniso8601.parse_interval('2007-03-01/P1.5D', builder=RelativeTimeBuilder)
(datetime.date(2007, 3, 1), datetime.datetime(2007, 3, 2, 12, 0))
Repeating intervals are supported as well, and return a generator::
>>> aniso8601.parse_repeating_interval('R3/1981-04-05/P1D', builder=RelativeTimeBuilder)
<generator object _date_generator at 0x7f0862919fa0>
>>> list(aniso8601.parse_repeating_interval('R3/1981-04-05/P1D', builder=RelativeTimeBuilder))
[datetime.date(1981, 4, 5), datetime.date(1981, 4, 6), datetime.date(1981, 4, 7)]
Repeating intervals are allowed to go in the reverse direction::
>>> list(aniso8601.parse_repeating_interval('R2/PT1H2M/1980-03-05T01:01:00', builder=RelativeTimeBuilder))
[datetime.datetime(1980, 3, 5, 1, 1), datetime.datetime(1980, 3, 4, 23, 59)]
Unbounded intervals are also allowed (Python 2)::
>>> result = aniso8601.parse_repeating_interval('R/PT1H2M/1980-03-05T01:01:00', builder=RelativeTimeBuilder)
>>> result.next()
datetime.datetime(1980, 3, 5, 1, 1)
>>> result.next()
datetime.datetime(1980, 3, 4, 23, 59)
or for Python 3::
>>> result = aniso8601.parse_repeating_interval('R/PT1H2M/1980-03-05T01:01:00', builder=RelativeTimeBuilder)
>>> next(result)
datetime.datetime(1980, 3, 5, 1, 1)
>>> next(result)
datetime.datetime(1980, 3, 4, 23, 59)
Intervals are calculated with calendar level accuracy::
>>> aniso8601.parse_interval('2003-01-27/P1M', builder=RelativeTimeBuilder)
(datetime.date(2003, 1, 27), datetime.date(2003, 2, 27))
>>> aniso8601.parse_interval('2003-01-31/P1M', builder=RelativeTimeBuilder)
(datetime.date(2003, 1, 31), datetime.date(2003, 2, 28))
>>> aniso8601.parse_interval('P1Y/2001-02-28', builder=RelativeTimeBuilder)
(datetime.date(2001, 2, 28), datetime.date(2000, 2, 28))
Fractional years and months do not make sense for relative intervals::
>>> aniso8601.parse_interval('P1.1Y/2001-02-28', builder=RelativeTimeBuilder)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/nielsenb/Jetfuse/aniso8601/aniso8601/aniso8601/interval.py", line 40, in parse_interval
intervaldelimiter, datetimedelimiter)
File "/home/nielsenb/Jetfuse/aniso8601/aniso8601/aniso8601/interval.py", line 98, in _parse_interval
return builder.build_interval(end=enddate, duration=duration)
File "/home/nielsenb/Jetfuse/aniso8601/aniso8601/aniso8601/builders/python.py", line 311, in build_interval
durationobject = cls._build_object(duration)
File "/home/nielsenb/Jetfuse/aniso8601/aniso8601/aniso8601/builders/__init__.py", line 71, in _build_object
TnS=parsetuple[6])
File "relativetimebuilder/__init__.py", line 24, in build_duration
raise RelativeValueError('Fractional months and years are not '
relativetimebuilder.RelativeValueError: Fractional months and years are not defined for relative durations.
Development
===========
Setup
-----
It is recommended to develop using a `virtualenv <https://virtualenv.pypa.io/en/stable/>`_.
Inside a virtualenv, development dependencies can be installed automatically::
$ pip install -e .[dev]
`pre-commit <https://pre-commit.com/>`_ is used for managing pre-commit hooks::
$ pre-commit install
To run the pre-commit hooks manually::
$ pre-commit run --all-files
Tests
-----
Tests can be run using the `unittest testing framework <https://docs.python.org/3/library/unittest.html>`_::
$ python -m unittest discover relativetimebuilder
Contributing
============
RelativeTimeBuilder is an open source project hosted on `Bitbucket <https://bitbucket.org/nielsenb/relativetimebuilder>`_.
Any and all bugs are welcome on our `issue tracker <https://bitbucket.org/nielsenb/relativetimebuilder/issues>`_.
Raw data
{
"_id": null,
"home_page": "https://bitbucket.org/nielsenb/relativetimebuilder",
"name": "relativetimebuilder",
"maintainer": null,
"docs_url": null,
"requires_python": null,
"maintainer_email": null,
"keywords": "iso8601 dateutil aniso8601 datetime",
"author": "Brandon Nielsen",
"author_email": "nielsenb@jetfuse.net",
"download_url": "https://files.pythonhosted.org/packages/f0/29/5b29c98a56cf264eee16e52ba86a2e8b7439ec1843449a53997d4479edeb/relativetimebuilder-3.0.1.tar.gz",
"platform": null,
"description": "RelativeTimeBuilder\n===================\n\naniso8601 builder for dateutil relativedeltas\n---------------------------------------------\n\nFeatures\n========\n* Provides :code:`RelativeTimeBuilder` compatible with `aniso8601 <https://bitbucket.org/nielsenb/aniso8601>`_\n* Returns `dateutil <https://dateutil.readthedocs.io/en/stable/relativedelta.html>`_ :code:`relativedelta` objects for durations\n\nInstallation\n============\n\nThe recommended installation method is to use pip::\n\n $ pip install relativetimebuilder\n\nAlternatively, you can download the source (git repository hosted at `Bitbucket <https://bitbucket.org/nielsenb/relativetimebuilder>`_) and install directly::\n\n $ python setup.py install\n\nUse\n===\n\nParsing datetimes\n-----------------\n\nTo parse a typical ISO 8601 datetime string::\n\n >>> import aniso8601\n >>> from relativetimebuilder import RelativeTimeBuilder\n >>> aniso8601.parse_datetime('1977-06-10T12:00:00', builder=RelativeTimeBuilder)\n datetime.datetime(1977, 6, 10, 12, 0)\n\nAlternative delimiters can be specified, for example, a space::\n\n >>> aniso8601.parse_datetime('1977-06-10 12:00:00', delimiter=' ', builder=RelativeTimeBuilder)\n datetime.datetime(1977, 6, 10, 12, 0)\n\nBoth UTC (Z) and UTC offsets for timezones are supported::\n\n >>> aniso8601.parse_datetime('1977-06-10T12:00:00Z', builder=RelativeTimeBuilder)\n datetime.datetime(1977, 6, 10, 12, 0, tzinfo=+0:00:00 UTC)\n >>> aniso8601.parse_datetime('1979-06-05T08:00:00-08:00', builder=RelativeTimeBuilder)\n datetime.datetime(1979, 6, 5, 8, 0, tzinfo=-8:00:00 UTC)\n\nLeap seconds are explicitly not supported::\n\n >>> aniso8601.parse_datetime('2018-03-06T23:59:60', builder=RelativeTimeBuilder)\n Traceback (most recent call last):\n File \"<stdin>\", line 1, in <module>\n File \"/home/nielsenb/Jetfuse/aniso8601/aniso8601/aniso8601/time.py\", line 132, in parse_datetime\n return builder.build_datetime(datepart, timepart)\n File \"/home/nielsenb/Jetfuse/aniso8601/aniso8601/aniso8601/builders/python.py\", line 181, in build_datetime\n cls._build_object(time))\n File \"/home/nielsenb/Jetfuse/aniso8601/aniso8601/aniso8601/builders/__init__.py\", line 64, in _build_object\n ss=parsetuple[2], tz=parsetuple[3])\n File \"/home/nielsenb/Jetfuse/aniso8601/aniso8601/aniso8601/builders/python.py\", line 141, in build_time\n raise LeapSecondError('Leap seconds are not supported.')\n aniso8601.exceptions.LeapSecondError: Leap seconds are not supported.\n\nParsing dates\n-------------\n\nTo parse a date represented in an ISO 8601 string::\n\n >>> import aniso8601\n >>> from relativetimebuilder import RelativeTimeBuilder\n >>> aniso8601.parse_date('1984-04-23', builder=RelativeTimeBuilder)\n datetime.date(1984, 4, 23)\n\nBasic format is supported as well::\n\n >>> aniso8601.parse_date('19840423', builder=RelativeTimeBuilder)\n datetime.date(1984, 4, 23)\n\nTo parse a date using the ISO 8601 week date format::\n\n >>> aniso8601.parse_date('1986-W38-1', builder=RelativeTimeBuilder)\n datetime.date(1986, 9, 15)\n\nTo parse an ISO 8601 ordinal date::\n\n >>> aniso8601.parse_date('1988-132', builder=RelativeTimeBuilder)\n datetime.date(1988, 5, 11)\n\nParsing times\n-------------\n\nTo parse a time formatted as an ISO 8601 string::\n\n >>> import aniso8601\n >>> from relativetimebuilder import RelativeTimeBuilder\n >>> aniso8601.parse_time('11:31:14', builder=RelativeTimeBuilder)\n datetime.time(11, 31, 14)\n\nAs with all of the above, basic format is supported::\n\n >>> aniso8601.parse_time('113114', builder=RelativeTimeBuilder)\n datetime.time(11, 31, 14)\n\nA UTC offset can be specified for times::\n\n >>> aniso8601.parse_time('17:18:19-02:30', builder=RelativeTimeBuilder)\n datetime.time(17, 18, 19, tzinfo=-2:30:00 UTC)\n >>> aniso8601.parse_time('171819Z', builder=RelativeTimeBuilder)\n datetime.time(17, 18, 19, tzinfo=+0:00:00 UTC)\n\nReduced accuracy is supported::\n\n >>> aniso8601.parse_time('21:42', builder=RelativeTimeBuilder)\n datetime.time(21, 42)\n >>> aniso8601.parse_time('22', builder=RelativeTimeBuilder)\n datetime.time(22, 0)\n\nA decimal fraction is always allowed on the lowest order element of an ISO 8601 formatted time::\n\n >>> aniso8601.parse_time('22:33.5', builder=RelativeTimeBuilder)\n datetime.time(22, 33, 30)\n >>> aniso8601.parse_time('23.75', builder=RelativeTimeBuilder)\n datetime.time(23, 45)\n\nLeap seconds are explicitly not supported and attempting to parse one raises a :code:`LeapSecondError`::\n\n >>> aniso8601.parse_time('23:59:60', builder=RelativeTimeBuilder)\n Traceback (most recent call last):\n File \"<stdin>\", line 1, in <module>\n File \"/home/nielsenb/Jetfuse/aniso8601/aniso8601/aniso8601/time.py\", line 117, in parse_time\n return _RESOLUTION_MAP[get_time_resolution(timestr)](timestr, tz, builder)\n File \"/home/nielsenb/Jetfuse/aniso8601/aniso8601/aniso8601/time.py\", line 166, in _parse_second_time\n return builder.build_time(hh=hourstr, mm=minutestr, ss=secondstr, tz=tz)\n File \"/home/nielsenb/Jetfuse/aniso8601/aniso8601/aniso8601/builders/python.py\", line 141, in build_time\n raise LeapSecondError('Leap seconds are not supported.')\n aniso8601.exceptions.LeapSecondError: Leap seconds are not supported.\n\nParsing durations\n-----------------\n\nParsing durations returns :code:`relativedelta` objects from `dateutil <https://dateutil.readthedocs.io/en/stable/relativedelta.html>`_ for calendar level accuracy.\n\nTo parse a duration formatted as an ISO 8601 string::\n\n >>> import aniso8601\n >>> from relativetimebuilder import RelativeTimeBuilder\n >>> aniso8601.parse_duration('P1Y2M3DT4H54M6S', builder=RelativeTimeBuilder)\n relativedelta(years=+1, months=+2, days=+3, hours=+4, minutes=+54, seconds=+6)\n\nReduced accuracy is supported::\n\n >>> aniso8601.parse_duration('P1Y', builder=RelativeTimeBuilder)\n relativedelta(years=+1)\n\nA decimal fraction is allowed on the lowest order element::\n\n >>> aniso8601.parse_duration('P1YT3.5M', builder=RelativeTimeBuilder)\n relativedelta(years=+1, minutes=+3.5)\n\nThe decimal fraction can be specified with a comma instead of a full-stop::\n\n >>> aniso8601.parse_duration('P1YT3,5M', builder=RelativeTimeBuilder)\n relativedelta(years=+1, minutes=+3.5)\n\nDecimal fractions are not supported for years or months as calendar level accuracy would not be guaranteed::\n\n >>> aniso8601.parse_duration('P1Y2.5M', builder=RelativeTimeBuilder)\n Traceback (most recent call last):\n File \"<stdin>\", line 1, in <module>\n File \"/home/nielsenb/Jetfuse/aniso8601/aniso8601/aniso8601/duration.py\", line 30, in parse_duration\n return _parse_duration_prescribed(isodurationstr, builder)\n File \"/home/nielsenb/Jetfuse/aniso8601/aniso8601/aniso8601/duration.py\", line 75, in _parse_duration_prescribed\n return _parse_duration_prescribed_notime(durationstr, builder)\n File \"/home/nielsenb/Jetfuse/aniso8601/aniso8601/aniso8601/duration.py\", line 119, in _parse_duration_prescribed_notime\n PnW=weekstr, PnD=daystr)\n File \"relativetimebuilder/__init__.py\", line 24, in build_duration\n raise RelativeValueError('Fractional months and years are not '\n relativetimebuilder.RelativeValueError: Fractional months and years are not defined for relative durations.\n >>> aniso8601.parse_duration('P1.5Y', builder=RelativeTimeBuilder)\n Traceback (most recent call last):\n File \"<stdin>\", line 1, in <module>\n File \"/home/nielsenb/Jetfuse/aniso8601/aniso8601/aniso8601/duration.py\", line 30, in parse_duration\n return _parse_duration_prescribed(isodurationstr, builder)\n File \"/home/nielsenb/Jetfuse/aniso8601/aniso8601/aniso8601/duration.py\", line 75, in _parse_duration_prescribed\n return _parse_duration_prescribed_notime(durationstr, builder)\n File \"/home/nielsenb/Jetfuse/aniso8601/aniso8601/aniso8601/duration.py\", line 119, in _parse_duration_prescribed_notime\n PnW=weekstr, PnD=daystr)\n File \"relativetimebuilder/__init__.py\", line 24, in build_duration\n raise RelativeValueError('Fractional months and years are not '\n relativetimebuilder.RelativeValueError: Fractional months and years are not defined for relative durations.\n\nParsing a duration from a combined date and time is supported as well::\n\n >>> aniso8601.parse_duration('P0001-01-02T01:30:5', builder=RelativeTimeBuilder)\n relativedelta(years=+1, months=+1, days=+2, hours=+1, minutes=+30, seconds=+5)\n\nParsing intervals\n-----------------\n\nIntervals are built using :code:`relativedelta` objects from `dateutil <https://dateutil.readthedocs.io/en/stable/relativedelta.html>`_ for calendar level accuracy.\n\nTo parse an interval specified by a start and end::\n\n >>> import aniso8601\n >>> from relativetimebuilder import RelativeTimeBuilder\n >>> aniso8601.parse_interval('2007-03-01T13:00:00/2008-05-11T15:30:00', builder=RelativeTimeBuilder)\n (datetime.datetime(2007, 3, 1, 13, 0), datetime.datetime(2008, 5, 11, 15, 30))\n\nIntervals specified by a start time and a duration are supported::\n\n >>> aniso8601.parse_interval('2007-03-01T13:00:00/P1Y2M10DT2H30M', builder=RelativeTimeBuilder)\n (datetime.datetime(2007, 3, 1, 13, 0), datetime.datetime(2008, 5, 11, 15, 30))\n\nA duration can also be specified by a duration and end time::\n\n >>> aniso8601.parse_interval('P1M/1981-04-05', builder=RelativeTimeBuilder)\n (datetime.date(1981, 4, 5), datetime.date(1981, 3, 5))\n\nNotice that the result of the above parse is not in order from earliest to latest. If sorted intervals are required, simply use the :code:`sorted` keyword as shown below::\n\n >>> sorted(aniso8601.parse_interval('P1M/1981-04-05', builder=RelativeTimeBuilder))\n [datetime.date(1981, 3, 5), datetime.date(1981, 4, 5)]\n\nThe end of an interval is returned as a :code:`datetime` when required to maintain the resolution specified by a duration, even if the duration start is given as a date::\n\n >>> aniso8601.parse_interval('2014-11-12/PT4H54M6.5S', builder=RelativeTimeBuilder)\n (datetime.date(2014, 11, 12), datetime.datetime(2014, 11, 12, 4, 54, 6, 500000))\n >>> aniso8601.parse_interval('2007-03-01/P1.5D', builder=RelativeTimeBuilder)\n (datetime.date(2007, 3, 1), datetime.datetime(2007, 3, 2, 12, 0))\n\nRepeating intervals are supported as well, and return a generator::\n\n >>> aniso8601.parse_repeating_interval('R3/1981-04-05/P1D', builder=RelativeTimeBuilder)\n <generator object _date_generator at 0x7f0862919fa0>\n >>> list(aniso8601.parse_repeating_interval('R3/1981-04-05/P1D', builder=RelativeTimeBuilder))\n [datetime.date(1981, 4, 5), datetime.date(1981, 4, 6), datetime.date(1981, 4, 7)]\n\nRepeating intervals are allowed to go in the reverse direction::\n\n >>> list(aniso8601.parse_repeating_interval('R2/PT1H2M/1980-03-05T01:01:00', builder=RelativeTimeBuilder))\n [datetime.datetime(1980, 3, 5, 1, 1), datetime.datetime(1980, 3, 4, 23, 59)]\n\nUnbounded intervals are also allowed (Python 2)::\n\n >>> result = aniso8601.parse_repeating_interval('R/PT1H2M/1980-03-05T01:01:00', builder=RelativeTimeBuilder)\n >>> result.next()\n datetime.datetime(1980, 3, 5, 1, 1)\n >>> result.next()\n datetime.datetime(1980, 3, 4, 23, 59)\n\nor for Python 3::\n\n >>> result = aniso8601.parse_repeating_interval('R/PT1H2M/1980-03-05T01:01:00', builder=RelativeTimeBuilder)\n >>> next(result)\n datetime.datetime(1980, 3, 5, 1, 1)\n >>> next(result)\n datetime.datetime(1980, 3, 4, 23, 59)\n\nIntervals are calculated with calendar level accuracy::\n\n >>> aniso8601.parse_interval('2003-01-27/P1M', builder=RelativeTimeBuilder)\n (datetime.date(2003, 1, 27), datetime.date(2003, 2, 27))\n >>> aniso8601.parse_interval('2003-01-31/P1M', builder=RelativeTimeBuilder)\n (datetime.date(2003, 1, 31), datetime.date(2003, 2, 28))\n >>> aniso8601.parse_interval('P1Y/2001-02-28', builder=RelativeTimeBuilder)\n (datetime.date(2001, 2, 28), datetime.date(2000, 2, 28))\n\nFractional years and months do not make sense for relative intervals::\n\n >>> aniso8601.parse_interval('P1.1Y/2001-02-28', builder=RelativeTimeBuilder)\n Traceback (most recent call last):\n File \"<stdin>\", line 1, in <module>\n File \"/home/nielsenb/Jetfuse/aniso8601/aniso8601/aniso8601/interval.py\", line 40, in parse_interval\n intervaldelimiter, datetimedelimiter)\n File \"/home/nielsenb/Jetfuse/aniso8601/aniso8601/aniso8601/interval.py\", line 98, in _parse_interval\n return builder.build_interval(end=enddate, duration=duration)\n File \"/home/nielsenb/Jetfuse/aniso8601/aniso8601/aniso8601/builders/python.py\", line 311, in build_interval\n durationobject = cls._build_object(duration)\n File \"/home/nielsenb/Jetfuse/aniso8601/aniso8601/aniso8601/builders/__init__.py\", line 71, in _build_object\n TnS=parsetuple[6])\n File \"relativetimebuilder/__init__.py\", line 24, in build_duration\n raise RelativeValueError('Fractional months and years are not '\n relativetimebuilder.RelativeValueError: Fractional months and years are not defined for relative durations.\n\nDevelopment\n===========\n\nSetup\n-----\n\nIt is recommended to develop using a `virtualenv <https://virtualenv.pypa.io/en/stable/>`_.\n\nInside a virtualenv, development dependencies can be installed automatically::\n\n $ pip install -e .[dev]\n\n`pre-commit <https://pre-commit.com/>`_ is used for managing pre-commit hooks::\n\n $ pre-commit install\n\nTo run the pre-commit hooks manually::\n\n $ pre-commit run --all-files\n\nTests\n-----\n\nTests can be run using the `unittest testing framework <https://docs.python.org/3/library/unittest.html>`_::\n\n $ python -m unittest discover relativetimebuilder\n\nContributing\n============\n\nRelativeTimeBuilder is an open source project hosted on `Bitbucket <https://bitbucket.org/nielsenb/relativetimebuilder>`_.\n\nAny and all bugs are welcome on our `issue tracker <https://bitbucket.org/nielsenb/relativetimebuilder/issues>`_.\n",
"bugtrack_url": null,
"license": null,
"summary": "A library for using the dateutil relativedeltas for calendar precision with aniso8601",
"version": "3.0.1",
"project_urls": {
"Documentation": "https://relativetimebuilder.readthedocs.io/",
"Homepage": "https://bitbucket.org/nielsenb/relativetimebuilder",
"Source": "https://bitbucket.org/nielsenb/relativetimebuilder",
"Tracker": "https://bitbucket.org/nielsenb/relativetimebuilder/issues"
},
"split_keywords": [
"iso8601",
"dateutil",
"aniso8601",
"datetime"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "251369a44f85a69083fa3c0d92c449a898564a3a6a1ea18b72d551bf05b3f308",
"md5": "221d627b5c154b35d6a720bc49c25aa7",
"sha256": "cb89b531329b3d0c8dcf58b21c23e2c2e7d5fb13f7dd96927310c0acc23f0b3d"
},
"downloads": -1,
"filename": "relativetimebuilder-3.0.1-py2.py3-none-any.whl",
"has_sig": false,
"md5_digest": "221d627b5c154b35d6a720bc49c25aa7",
"packagetype": "bdist_wheel",
"python_version": "py2.py3",
"requires_python": null,
"size": 11264,
"upload_time": "2025-01-10T01:48:45",
"upload_time_iso_8601": "2025-01-10T01:48:45.945936Z",
"url": "https://files.pythonhosted.org/packages/25/13/69a44f85a69083fa3c0d92c449a898564a3a6a1ea18b72d551bf05b3f308/relativetimebuilder-3.0.1-py2.py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "f0295b29c98a56cf264eee16e52ba86a2e8b7439ec1843449a53997d4479edeb",
"md5": "d8007accb25488ff3f6c1e24ac499f9e",
"sha256": "f573f6535c1aa3b6e3271c4e2e0807ddc06e19c9da938e68ad197da9f8df03f5"
},
"downloads": -1,
"filename": "relativetimebuilder-3.0.1.tar.gz",
"has_sig": false,
"md5_digest": "d8007accb25488ff3f6c1e24ac499f9e",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 13665,
"upload_time": "2025-01-10T01:48:48",
"upload_time_iso_8601": "2025-01-10T01:48:48.136420Z",
"url": "https://files.pythonhosted.org/packages/f0/29/5b29c98a56cf264eee16e52ba86a2e8b7439ec1843449a53997d4479edeb/relativetimebuilder-3.0.1.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2025-01-10 01:48:48",
"github": false,
"gitlab": false,
"bitbucket": true,
"codeberg": false,
"bitbucket_user": "nielsenb",
"bitbucket_project": "relativetimebuilder",
"lcname": "relativetimebuilder"
}