MeridianMERIDIAN

ISO 8601 Duration

Duration in ISO 8601 format (PnYnMnDTnHnMnS or PnW for weeks). Used in iCalendar, XML Schema, YouTube API, Google Calendar, and many APIs. Covers both compact (PT30M) and verbose (P1Y2M3DT4H5M6S) forms.

ISO 8601 Duration

datetime.duration.iso_8601

Duration in ISO 8601 format (PnYnMnDTnHnMnS or PnW for weeks). Used in iCalendar, XML Schema, YouTube API, Google Calendar, and many APIs. Covers both compact (PT30M) and verbose (P1Y2M3DT4H5M6S) forms.

Domain
datetime
Category
duration
Casts to
INTERVAL
Scope
Universal

Try it

CLI
$ finetype infer -i "PT30M" --mode column
→ datetime.duration.iso_8601

DuckDB

Detect
SELECT ft_infer('PT30M');
-- → 'datetime.duration.iso_8601'
Cast expression
CAST(
  COALESCE(NULLIF(REGEXP_EXTRACT({col}, '(\d+)Y', 1), '') || ' years ', '') ||
  COALESCE(NULLIF(REGEXP_EXTRACT({col}, 'P[^T]*?(\d+)M', 1), '') || ' months ', '') ||
  COALESCE(NULLIF(REGEXP_EXTRACT({col}, '(\d+)W', 1), '') || ' weeks ', '') ||
  COALESCE(NULLIF(REGEXP_EXTRACT({col}, '(\d+)D', 1), '') || ' days ', '') ||
  COALESCE(NULLIF(REGEXP_EXTRACT({col}, '(\d+)H', 1), '') || ' hours ', '') ||
  COALESCE(NULLIF(REGEXP_EXTRACT({col}, 'T.*?(\d+)M', 1), '') || ' minutes ', '') ||
  COALESCE(NULLIF(REGEXP_EXTRACT({col}, '(\d+(?:\.\d+)?)S', 1), '') || ' seconds', '0 seconds')
AS INTERVAL)
Safe cast pipeline
-- Normalise and cast in one step
SELECT TRY_CAST(ft_cast(my_column) AS INTERVAL) AS clean_value
FROM my_table
WHERE ft_infer(my_column) = 'datetime.duration.iso_8601';

JSON Schema

finetype taxonomy datetime.duration.iso_8601 -o json-schema
{
  "$id": "https://meridian.online/schemas/datetime.duration.iso_8601",
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "description": "Duration in ISO 8601 format (PnYnMnDTnHnMnS or PnW for weeks). Used in iCalendar, XML Schema, YouTube API, Google Calendar, and many APIs. Covers both compact (PT30M) and verbose (P1Y2M3DT4H5M6S) forms.",
  "examples": [
    "PT30M",
    "PT1H30M",
    "P1DT12H",
    "P1Y6M",
    "P2W",
    "P1Y2M3DT4H5M6S"
  ],
  "pattern": "^-?P(?=\\d|T\\d)(?:(\\d+)Y)?(?:(\\d+)M)?(?:(\\d+)[DW])?(?:T(?:(\\d+)H)?(?:(\\d+)M)?(?:(\\d+(?:\\.\\d+)?)S)?)?$",
  "title": "ISO 8601 Duration",
  "type": "string",
  "x-finetype-label": "datetime.duration.iso_8601",
  "x-finetype-pii": false
}

Examples

PT30MPT1H30MP1DT12HP1Y6MP2WP1Y2M3DT4H5M6S

Aliases

durationiso_8601_verbose

Type Registry