Package: isodatetime
isodatetimePython ISO 8601 full-specification parser and data model/manipulation utilities.
Intended to be used in a similar way to Python's datetime module.InstallationInstall from PyPI:$pipinstallisodatetimeOr build yourself:$gitclonehttps://github.com/metomi/isodatetime.gitisodatetime$cdisodatetime$pythonsetup.pyinstallUsagePython API:>>>importisodatetime.parsersasparse>>>importisodatetime.dumpersasdump# Dates and times>>>date_time=parse.TimePointParser().parse('2000-01-01T00:00Z')>>>date_time.month_of_year1# Durations>>>duration=parse.DurationParser().parse('P1YT3H')>>>duration.get_days_and_seconds()(365.0,10800.0)>>>date_time+duration2001-01-01T03:00:00Z# Recurrences>>>recurrence=parse.TimeRecurrenceParser().parse('R/1999/P1Y')>>>recurrence.get_next(date_time)2001-01-01T00:00:00Z# Output>>>dump.TimePointDumper().strftime(date_time,'%d/%M/%Y %H:%M:%S')'01/00/2000 00:00:00'CLI:$isodatetime2000-01-01T00:00:00Z$isodatetime10661066$isodatetime1066--offsetP1Y1067$isodatetimeR/2000/P1Y--max32000-01-01T00:00:00Z2001-01-01T00:00:00Z2002-01-01T00:00:00ZISO8601ISO8601 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:http://www.cl.cam.ac.uk/~mgk25/iso-time.htmlhttp://www.tondering.dk/claus/calendar.htmlReference material:http://www.iso.org/iso/home/standards/iso8601.htmhttp://en.wikipedia.org/wiki/ISO_8601Dates and timesHow do I write the year, month-of-year, and day-of-month down?SyntaxExampleCCYYMMDD20151231CCYY-MM-DD2015-12-31How about writing down the year, week-of-year, and day-of-week?SyntaxExampleCCYYWwwD2015W534CCYY-Www-D2015-W53-4How about writing down the year and day-of-year?SyntaxExampleCCYYDDD2015365CCYY-DDD2015-365How do I write just the year?Either:CCYYor+XCCYY+Xstands for a plus or minus sign (+or-), followed by a fixed,
agreed number of expanded year digits (X). For example, if we agree to have
2 expanded year digits, we can represent years from -999999 to +999999
(1000000 BC to 999999 AD). Note that 1 BC is the year 0 in the proleptic
Gregorian calendar used by ISO 8601.For example, you can write the year 1995 AD as:1995or+001995(using 2 expanded year digits).Note: writing just the year where you mean a proper date implies Day 1 of
Month 1 in that year -1995implies1995-01=>1995-01-01=>1995-01-01T00=>1995-01-01T00:00=>1995-01-01T00:00:00.How do I write just the year and month-of-year?Either:CCYY-MMor+XCCYY-MM(+ standing in here for a+or-sign)(not allowed:CCYYMMor+XCCYYMM).How do I write dates past the year 9999 and before 0000?SyntaxExample (2 expanded year digits)+XCCYYMMDD+0020151231+XCCYY-MM-DD+002015-12-31+XCCYYWwwD+002015W534+XCCYY-Www-D+002015-W53-4+XCCYYDDD+002015365+XCCYY-DDD+002015-365How do I write down time information by itself?SyntaxExamplehhmmss083000hhmm0830hh:mm:ss17:45:01hh:mm17:45hh08How do I write down time information at a date in ISO 8601?Write the time after the date, separated with aT:SyntaxExampleCCYYMMDDThhmmss20151231T063101CCYY-MM-DDThh:mm:ss2015-12-31T06:31:01CCYYWwwDThhmmss2015W534T063101CCYY-Www-DThh:mm:ss2015-W53-4T06:31:01CCYYDDDThhmmss2015365T063101CCYY-DDDThh:mm:ss2015-365T06:31:01What about just the hour and minute at a date?SyntaxExampleCCYYWwwDThhmm2015W534T0631CCYY-Www-DThh:mm2015-W53-4T06:31What about just the hour at a date?SyntaxExampleCCYYMMDDThh20151231T06CCYY-MM-DDThh2015-12-31T06What 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:SyntaxExampleCCYYMMDDThh,ii20151231T06,5CCYYMMDDThh.ii20151231T06.5CCYYMMDDThhmm,nn20151231T0631,3333CCYYMMDDThhmm.nn20151231T0631.3333CCYYMMDDThhmmss,tt20151231T063101,25671CCYYMMDDThhmmss.tt20151231T063101.25671How 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.SyntaxExampleCCYYMMDDThhmmssZ20151231T063101ZCCYY-MM-DDThh:mm:ssZ2015-12-31T06:31:01ZCCYYMMDDThhmmss-hh20151231T013101-05CCYY-MM-DDThh:mm:ss-hh2015-12-31T01:31:01-05CCYYMMDDThhmmss+hh20151231T083101+02CCYY-MM-DDThh:mm:ss+hh2015-12-31T08:31:01+02CCYYMMDDThhmmss-hhmm20151230T203101-1000CCYY-MM-DDThh:mm:ss-hh:mm2015-12-30T20:31:01-10:00CCYYMMDDThhmmss+hhmm20151231T193101+1300CCYY-MM-DDThh:mm:ss+hh:mm2015-12-31T19:31:01+13:00DurationsHow 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:Unit typeUnit designatoryearsYmonthsMweeksWdaysDhoursHminutesMsecondsSIf the unit is one of hours, minutes, or seconds, you need a leading "T"
to delimit time from date:SyntaxExampleMeaningPnYP2Y2 yearsPn,oYP5,5Y5 and a half yearsPn.oYP5.5Y5 and a half yearsPTnMPT7M7 minutes (note the 'T')PnMP10M10 monthsPnDTnHP5DT6H5 days and 6 hoursPnWP2W2 weeksCombining any other unit with weeks is not allowed.A supplementary format (which has to be agreed in advance) is to specify a
date-time-like duration (PCCYY-MM-DDThh:mm:ss) where the numbers given for
years, months, days, hours, minutes, and seconds are used literally
(P1995-00-00T00:10:00=P1995YT10M).Recurring date-time series1 - Recur with a duration given by the difference between a start dateand a subsequent date, starting at the start dateExample SyntaxExampleMeaningR/CCYY/CCYYR/2010/2014Repeat every 4 years, starting at 2010-01-01.R/CCYY-MM/CCYY-DDDR/2010-01/2012-045Repeat every 2 years and 44 days, starting at 2010-01-01R5/CCYY-Www-D/CCYY-Www-DR/2015-W05-2/2015-W07-3Repeat every 2 weeks and 1 day, five times, starting at 2015-W05-22 - Recur with a given duration, starting at a context date-time(You have to supply the context somewhere else)Example SyntaxExampleMeaningR/PnMnDTnMR/P10M3DT45MRepeat every 10 months, 3 days, and 45 minutes from a context start date-time.Rn/PnYR2/P4YRepeat every 4 years, for a total of 2 times, from a context start date-time.3 - Recur with a given duration starting at a particular date-timeExample SyntaxExampleMeaningR/CCYYMMDDThhZ/PTnHR/20201231T00Z/PT12HRepeat every 12 hours starting at 2020-12-31T00ZR/CCYY-Www-D/PnWR/2012-W02-1/P1WRepeat weekly starting at Monday in the second ISO week of 2012R/CCYYDDDThhmm/PnDR/1996291T0630+0100/P2DRepeat every 2 days starting on the 291st day of 1996 at 06:30, UTC + 1Rn/CCYY-MM-DDThh:mm/PTnHR2/19900201T06Z/PT12HRepeat every 12 hours, for a total of 2 repetitions, starting at 1990-02-01T06ZRn/CCYY-Www-D/PnWR5/2012-W02-1/P1WRepeat weekly, for a total of 5 repetitions, starting at Monday in the second ISO week of 2012Rn/CCYYDDDThhmm/PnDR1/1996291T0630+0100/P2DRepeat once at the 291st day of 1996 at 06:30, UTC + 14 - Recur with a given duration counting back from a particular date-timeExample SyntaxExampleMeaningR/PTnH/CCYY-MM-DDThhZR/PT1H/2012-01-02T00ZRepeat hourly counting back from 2012-01-02T00ZR/PnY/CCYYR/P3Y/2000Repeat every 3 years counting back from 2000-01-01.R/PTnS/+XCCYYDDDThhmmR/PT5s/-002500012T1800Repeat every 5 seconds counting back from the 12th day in 2501 BC at 18:00 (using 2 expanded year digits).Rn/PnYTnM/CCYY-MM-DDThhZR5/P1YT5M/2012-01-02T00ZRepeat every year and 5 minutes counting back from 2012-01-02T00ZRn/PnM/CCYY-MMR4/P1M/2000-05Repeat monthly, four times, counting back from 2000-05-01.