← cast operator page · general/cast/date_to_time_period/daily_periods

Daily periods 🟢 all ok

pandas ✅ · DuckDB ✅

Tests:

cast(Me_1, time_period) on a Date measure, an explicit cast without mask.

Manual:

Type conversion: "From date to time_period: A time_period value with a daily duration is returned, starting and ending at the specified date value."

Expected:

Daily periods, written YYYYD and the day of the year: 2020D15, 2020D61 for March 1st, after the 31 days of January and the 29 of February, and 2021D365, 2021 not being a leap year.

script.vtl ⇩

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

input/DS_1.csv ⇩

Id_1Me_1
12020-01-15
22020-03-01
32021-12-31

input/DS_1.json ⇩

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

expected/DS_r.csv ⇩

Id_1Me_1Me_2
12020-01-152020D15
22020-03-012020D61
32021-12-312021D365

expected/DS_r.json ⇩

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