← cast operator page · general/cast/string_to_duration/one_letter_codes

One letter codes 🟢 all ok

pandas ✅ · DuckDB ✅

Tests:

cast(Me_1, duration) on a String measure, without a mask: the one-letter codes.

Manual:

Type conversion: "To duration: If the input string starts with P, the entire string is consumed and parsed, according to the ISO-8601 standard for durations [...]. Otherwise, one of A, S, Q, M, W or D is consumed, and a duration value is returned representing the duration respectively of a year, a half of a year, a quarter of a year, a month, a week and a day."

Expected:

A year, a quarter and a day, written with the same codes: A, Q and D. The inputs have no blanks for the conversion to remove.

script.vtl ⇩

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

input/DS_1.csv ⇩

Id_1Me_1
1A
2Q
3D

input/DS_1.json ⇩

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

expected/DS_r.csv ⇩

Id_1Me_1Me_2
1AA
2QQ
3DD

expected/DS_r.json ⇩

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