← cast operator page · general/cast/duration_to_string/iso_8601_durations

Iso 8601 durations 🟢 all ok

pandas ✅ · DuckDB ✅

Tests:

cast(Me_1, string) on a Duration measure, without a mask: the default format.

Manual:

Type conversion: "From duration: the duration value is printed using the ISO-8601 representation for durations."

Expected:

The inputs are the one-letter codes that vtlengine reads ("A Year", "M Month", "D Day" in the mask section), and one year, month and day are P1Y, P1M and P1D in ISO-8601.

script.vtl ⇩

DS_r := DS_1[calc Me_2 := cast(Me_1, string)];

input/DS_1.csv ⇩

Id_1Me_1
1A
2M
3D

input/DS_1.json ⇩

{
  "datasets": [
    {
      "name": "DS_1",
      "DataStructure": [
        {"name": "Id_1", "type": "Integer", "role": "Identifier", "nullable": false},
        {"name": "Me_1", "type": "Duration", "role": "Measure", "nullable": true}
      ]
    }
  ]
}

expected/DS_r.csv ⇩

Id_1Me_1Me_2
1AP1Y
2MP1M
3DP1D

expected/DS_r.json ⇩

{
  "datasets": [
    {
      "name": "DS_r",
      "DataStructure": [
        {"name": "Id_1", "type": "Integer", "role": "Identifier"},
        {"name": "Me_1", "type": "Duration", "role": "Measure"},
        {"name": "Me_2", "type": "String", "role": "Measure"}
      ]
    }
  ]
}