Commentspganssle changed the title datetime: parse "Z" timezone suffix in fromisoformat() datetime: Expand scope of fromisoformat to include all of ISO 8601. May 3, 2022pganssle added a commit that referenced this issue May 6, 2022
This expands `fromisoformat` to cover most of the common uses of ISO 8601. We may expand the scope more in the future. felixxm added a commit to felixxm/django that referenced this issue May 9, 2022
date/datetime/time.fromisoformat() support any valid ISO 8601 format in Python 3.11+, see python/cpython#80010. felixxm added a commit to felixxm/django that referenced this issue May 9, 2022
date/datetime/time.fromisoformat() support any valid ISO 8601 format in Python 3.11+, see python/cpython#80010. felixxm added a commit to django/django that referenced this issue May 9, 2022
date/datetime/time.fromisoformat() support any valid ISO 8601 format in Python 3.11+, see python/cpython#80010.
Python ISO8601 (2004) full-specification parser and data model/manipulation utilities. Intended to be used in a similar way to Python's datetime module. InstallationInstall from PyPI: $ pip install metomi-isodatetime Or build yourself: $ git clone https://github.com/metomi/isodatetime.git isodatetime $ cd isodatetime $ python setup.py install UsagePython API: >>> import metomi.isodatetime.parsers as parse >>> import metomi.isodatetime.dumpers as dump # Dates and times >>> date_time = parse.TimePointParser().parse('2000-01-01T00:00Z') >>> date_time.month_of_year 1 # Durations >>> duration = parse.DurationParser().parse('P1YT3H') >>> duration.get_days_and_seconds() (365.0, 10800.0) >>> date_time + duration <metomi.isodatetime.data.TimePoint: 2001-01-01T03:00:00Z> # Recurrences >>> recurrence = parse.TimeRecurrenceParser().parse('R/1999/P1Y') >>> recurrence.get_next(date_time) <metomi.isodatetime.data.TimePoint: 2001-01-01T00:00:00Z> # Output >>> dump.TimePointDumper().strftime(date_time, '%d/%M/%Y %H:%M:%S') '01/00/2000 00:00:00' CLI: $ isodatetime 2000-01-01T00:00:00Z $ isodatetime 1066 1066 $ isodatetime 1066 --offset P1Y 1067 $ isodatetime R/2000/P1Y --max 3 2000-01-01T00:00:00Z 2001-01-01T00:00:00Z 2002-01-01T00:00:00Z Copyright and Terms of UseCopyright (C) 2013-2022 British Crown (Met Office) & Contributors. This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this program. If not, see GNU licenses. ISO 8601ISO 8601 (2004) is an international standard for writing down date/time information. It is the correct, internationally-friendly, computer-sortable way to numerically represent date/time information. Good reading material:
Reference material:
Dates and timesHow do I write the year, month-of-year, and day-of-month down?
How about writing down the year, week-of-year, and day-of-week?
How about writing down the year and day-of-year?
How do I write just the year?Either:
For example, you can write the year 1995 AD as: Note: writing just the year where you mean a proper date implies Day 1 of Month 1 in that year - How do I write just the year and month-of-year?Either: (not
allowed: How do I write dates past the year 9999 and before 0000?
How do I write down time information by itself?
How do I write down time information at a date in ISO 8601?Write the time after the date, separated with a
What about just the hour and minute at a date?
What about just the hour at a date?
What about decimal parts of the hour or minute or second?Use a comma or period to delimit the decimal part, and don't include any smaller units:
How do I specify a time zone?If the time zone is UTC, use "Z" - otherwise, use a numeric representation of the hours and minutes difference from UTC. Note that this difference is (TIMEZONE - UTC) - so longitudes east of 0 tend to have positive differences, and west of 0 usually have negative differences.
DurationsHow do I write down a certain period of time in X units?A "P" followed by the number of units (optionally including a decimal part) followed by a designator to mark the units:
If the unit is one of hours, minutes, or seconds, you need a leading "T" to delimit time from date:
Combining any other unit with weeks is not allowed. Decimals may only be used for hours, minutes and seconds. Note that years and months are "nominal" durations, whose exact length of time depends on their position in the calendar. E.g., a duration of 1 calendar year starts on a particular day of a particular month and ends on the same day of the same month in the following calendar year, and may be different to 365 days in the Gregorian calendar due to leap years. Conversely, weeks, days, hours, minutes and seconds are exact units, so A supplementary format (which has to be agreed in advance) is to specify a date-time-like duration ( Recurring date-time series1. Recur with a duration given by the difference between a start date and a subsequent date
*See the previous section as to why only an approximate equivalent number of years are given. 2. Recur with a specified duration, starting at a context date-time(You have to supply the context somewhere else)
3. Recur with a specified duration starting at a particular date-time
4. Recur with a specified duration ending at a particular date-timeThe starting date-time of the recurrence is calculated from the specified duration.
|