Time shift · timeshift
---
config:
flowchart:
useMaxWidth: false
---
flowchart LR
classDef ok fill:#d4edda,stroke:#28a745,color:#000
classDef partial fill:#fff3cd,stroke:#ffc107,color:#000
classDef refused fill:#d4edda,stroke:#28a745,stroke-width:3px,stroke-dasharray: 2 2,color:#000
classDef missing fill:#f8d7da,stroke:#dc3545,color:#000
classDef diverge fill:#cce5ff,stroke:#007bff,color:#000
classDef block fill:#2b3a4a,stroke:#2b3a4a,color:#fff,font-weight:bold
classDef ext fill:#fff,stroke:#666,color:#000,stroke-dasharray: 5 5
O["Time shift · timeshift<br/>🟢3"]:::ok
v_time_period["timeshift(DS, n) on time_period"]:::ok
v_date["timeshift(DS, n) on date"]:::ok
v_time["timeshift(DS, n) on time"]:::ok
v_time_period --- O
v_date --- O
O --- v_time
click v_time_period href "#form-time-period"
click v_date href "#form-date"
click v_time href "#form-time"
Types
Takes integer, time, date, time_period · Gives time, date, time_period, any type
Comes from · integer, time, date, time_period — 26 operators in 6 blocks 🟢26
General purpose operators (2) 🟢2
String operators (2) 🟢2
Numeric operators (4) 🟢4
Time operators (13) 🟢13
fill_time_seriesFlow to stock flow_to_stockStock to flow stock_to_flowTime aggregation time_aggActual time current_dateDays between two dates datediffAdd time unit to date dateaddExtract the year getyearExtract the month getmonthExtract the day of the month dayofmonthExtract the day of the year dayofyearYears and days to number of days yeartodayMonths and days to number of days monthtodayAggregate and Analytic operators (2) 🟢2
Data validation operators (3) 🟢3
Comes from · operators that return any type (their input's) — 34 operators in 7 blocks 🟢34
General purpose operators (5) 🟢5
Join operators (4) 🟢4
Set operators (4) 🟢4
Hierarchical aggregation (1) 🟢1
Aggregate and Analytic operators (8) 🟢8
Conditional operators (3) 🟢3
Goes to: whatever takes its input's type
Goes to · time, date, time_period — 13 operators in 3 blocks 🟢13
General purpose operators (1) 🟢1
Time operators (11) 🟢11
period_indicatorFill time series fill_time_seriesFlow to stock flow_to_stockStock to flow stock_to_flowTime aggregation time_aggDays between two dates datediffAdd time unit to date dateaddExtract the year getyearExtract the month getmonthExtract the day of the month dayofmonthExtract the day of the year dayofyearDefinitions (VTL-DL) (1) 🟢1
Goes to · operators that take any scalar — 49 operators in 9 blocks 🟢49
General purpose operators (6) 🟢6
Join operators (4) 🟢4
Comparison operators (11) 🟢11
Set operators (4) 🟢4
Aggregate and Analytic operators (10) 🟢10
Data validation operators (1) 🟢1
Conditional operators (3) 🟢3
Clause operators (9) 🟢9
Definitions (VTL-DL) (1) 🟢1
Forms
timeshift(DS, n) on time_period 🟢 · time_period, integer → time_period, any type
Manual example 3 🟢 pandas ✅ · DuckDB ✅
- Tests:
timeshift(DS_3, 1)on annual time_period series: one period into the future.- Manual:
Time shift, Example 3, output verbatim: the operator “shifts the reference time Identifier of a number of periods (of the time series) equal to the shiftNumber parameter. If shiftNumber is negative, the shift is in the past, otherwise it is in the future.”
- Expected:
Each year moves one year on, 2010 to 2013 becoming 2011 to 2014, with the measures as they were.
DS_r := timeshift ( DS_3 , 1 );
| Id_1 | Id_2 | Me_1 |
|---|---|---|
| A | 2010 | hello world |
| A | 2011 | |
| A | 2012 | say hello |
| A | 2013 | he |
| B | 2010 | hi,hello! |
| B | 2011 | hi |
| B | 2012 | |
| B | 2013 | hello! |
| Id_1 | Id_2 | Me_1 |
|---|---|---|
| A | 2011 | hello world |
| A | 2012 | |
| A | 2013 | say hello |
| A | 2014 | he |
| B | 2011 | hi,hello! |
| B | 2012 | hi |
| B | 2013 | |
| B | 2014 | hello! |
Files: script.vtl · input/DS_3.csv · input/DS_3.json · expected/DS_r.csv · expected/DS_r.json · example page ↗
Manual example 4 🟢 pandas ✅ · DuckDB ✅
- Tests:
timeshift(DS_4, -1)on an annual and a quarterly series of the same phenomenonA: one period of each series into the past.- Manual:
Time shift, Example 4, output verbatim: the operator “shifts the reference time Identifier of a number of periods (of the time series) equal to the shiftNumber parameter. If shiftNumber is negative, the shift is in the past”.
- Expected:
The years move back one year, 2010 to 2013 becoming 2009 to 2012, and the quarters one quarter, 2010Q1 to 2010Q4 becoming 2009Q4 to 2010Q3.
DS_r := timeshift( DS_4 , -1 );
| Id_1 | Id_2 | Me_1 |
|---|---|---|
| A | 2010 | hello world |
| A | 2011 | |
| A | 2012 | say hello |
| A | 2013 | he |
| A | 2010Q1 | hi, hello! |
| A | 2010Q2 | hi |
| A | 2010Q3 | |
| A | 2010Q4 | hello! |
| Id_1 | Id_2 | Me_1 |
|---|---|---|
| A | 2009 | hello world |
| A | 2010 | |
| A | 2011 | say hello |
| A | 2012 | he |
| A | 2009Q4 | hi, hello! |
| A | 2010Q1 | hi |
| A | 2010Q2 | |
| A | 2010Q3 | hello! |
Files: script.vtl · input/DS_4.csv · input/DS_4.json · expected/DS_r.csv · expected/DS_r.json · example page ↗
timeshift(DS, n) on date 🟢 · date, integer → date, any type
Manual example 2 🟢 pandas ✅ · DuckDB ✅
- Tests:
timeshift(DS_2, 2)on annual date series, where “conventionally each period is identified by its last day”.- Manual:
Time shift, Example 2, output verbatim: the operator “shifts the reference time Identifier of a number of periods (of the time series) equal to the shiftNumber parameter”.
- Expected:
Each date moves two years on, 2010-12-31 to 2013-12-31 becoming 2012-12-31 to 2015-12-31, with the measures as they were.
DS_r := timeshift ( DS_2 , 2 );
| Id_1 | Id_2 | Me_1 |
|---|---|---|
| A | 2010-12-31 | hello world |
| A | 2011-12-31 | |
| A | 2012-12-31 | say hello |
| A | 2013-12-31 | he |
| B | 2010-12-31 | hi, hello! |
| B | 2011-12-31 | hi |
| B | 2012-12-31 | |
| B | 2013-12-31 | hello! |
| Id_1 | Id_2 | Me_1 |
|---|---|---|
| A | 2012-12-31 | hello world |
| A | 2013-12-31 | |
| A | 2014-12-31 | say hello |
| A | 2015-12-31 | he |
| B | 2012-12-31 | hi, hello! |
| B | 2013-12-31 | hi |
| B | 2014-12-31 | |
| B | 2015-12-31 | hello! |
Files: script.vtl · input/DS_2.csv · input/DS_2.json · expected/DS_r.csv · expected/DS_r.json · example page ↗
timeshift(DS, n) on time 🟢 · time, integer → time, any type
Manual example 1 🟢 pandas ✅ · DuckDB ✅
- Tests:
timeshift(DS_1, -1)on annual series whose reference time identifier is a time.- Manual:
Time shift, Example 1: “If shiftNumber is negative, the shift is in the past, otherwise it is in the future.”
- Expected:
The manual’s output with its time values rewritten: each year moves one year back, 2010 to 2013 becoming 2009 to 2012, each the whole year
YYYY-01-01/YYYY-12-31.- Adaptation:
The page writes its time values in “the time format YYYY-MM/YYYY-MM”, as
2010M1/2010M12, which vtlengine cannot load (DataLoadError0-3-1-6, “Use YYYY-MM-DD/YYYY-MM-DD or YYYY or YYYY-MM”, on both engines). EachYYYYM1/YYYYM12of the input and the output is writtenYYYY-01-01/YYYY-12-31, the same interval in theYYYY-MM-DD/YYYY-MM-DDform of the manual’s “Behaviour of Time operators” and ofdocs/data_types.rst; nothing else changes.
DS_r := timeshift ( DS_1 , -1 );
| Id_1 | Id_2 | Me_1 |
|---|---|---|
| A | 2010-01-01/2010-12-31 | hello world |
| A | 2011-01-01/2011-12-31 | |
| A | 2012-01-01/2012-12-31 | say hello |
| A | 2013-01-01/2013-12-31 | he |
| B | 2010-01-01/2010-12-31 | hi, hello! |
| B | 2011-01-01/2011-12-31 | hi |
| B | 2012-01-01/2012-12-31 | |
| B | 2013-01-01/2013-12-31 | hello! |
| Id_1 | Id_2 | Me_1 |
|---|---|---|
| A | 2009-01-01/2009-12-31 | hello world |
| A | 2010-01-01/2010-12-31 | |
| A | 2011-01-01/2011-12-31 | say hello |
| A | 2012-01-01/2012-12-31 | he |
| B | 2009-01-01/2009-12-31 | hi, hello! |
| B | 2010-01-01/2010-12-31 | hi |
| B | 2011-01-01/2011-12-31 | |
| B | 2012-01-01/2012-12-31 | hello! |
Files: script.vtl · input/DS_1.csv · input/DS_1.json · expected/DS_r.csv · expected/DS_r.json · example page ↗