Time shift: timeshift
Syntax
timeshift ( op , shiftNumber )
Input parameters
op |
the operand |
shiftNumber |
the number of periods to be shifted |
Examples of valid syntaxes
timeshift ( DS_1, 2 )
Semantics for scalar operations
This operator does not perform scalar operations.
Input parameters type
op
dataset { identifier < time > _ , identifier _* }
shiftNumber
integer
Result type
result
dataset { identifier < time > _ , identifier _* }
Additional Constraints
The operand dataset has an Identifier of type time, date or time_period and may have other Identifiers.
Behavior
This operator takes in input a Data Set of time series and, for each time series of the Data Set, 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. For example, if the period of the time series is month and shiftNumber is -1 the reference time Identifier is shifted of two months in the past.
The operator can be applied only on Data Sets of time series and returns a Data Set of time series.
The result Data Set has the same Identifier, Measure and Attribute Components as the operand Data Set and contains the same time series as the operand, because the time series Identifiers (all the Identifiers except the reference time Identifier) are not changed.
The Attribute propagation rule is not applied.
As mentioned in the section “Behaviour of the Time Operators”, the operator is assumed to know which is the time Identifier as well as the period of each data point.
Examples
As described in the User Manual, the time data type is the intervening time between two time points and using the ISO 8601 standard it can be expressed through a start date and an end date separated by a slash at any precision. In the examples relevant to the time data type the precision is set at the level of month and the time format YYYY-MM/YYYY-MM is used.
Given:
the operand dataset DS_1, which contains annual time series, where Id_2 is the reference time Identifier of time type;
the operand dataset DS_2, which contains annual time series, where Id_2 is the reference time Identifier of date type (conventionally each period is identified by its last day);
the operand dataset DS_3, which contains annual time series, where Id_2 is the reference time Identifier of time_period type;
and the operand dataset DS_4, which contains both quarterly and annual time series relevant to the same phenomenon “A”, where Id_2 is the reference time Identifier of time_period type:
Input DS_1 (see structure)
Id_1 |
Id_2 |
Me_1 |
---|---|---|
A |
2010M1/2010M12 |
hello world |
A |
2011M1/2011M12 |
|
A |
2012M1/2012M12 |
say hello |
A |
2013M1/2013M12 |
he |
B |
2010M1/2010M12 |
hi, hello! |
B |
2011M1/2011M12 |
hi |
B |
2012M1/2012M12 |
|
B |
2013M1/2013M12 |
hello! |
Input DS_2 (see structure)
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! |
Input DS_3 (see structure)
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! |
Input DS_4 (see structure)
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! |
Example 1
DS_r := timeshift ( DS_1 , -1 );
results in (see structure):
Id_1 |
Id_2 |
Me_1 |
---|---|---|
A |
2009M1/2009M12 |
hello world |
A |
2010M1/2010M12 |
|
A |
2011M1/2011M12 |
say hello |
A |
2012M1/2012M12 |
he |
B |
2009M1/2009M12 |
hi, hello! |
B |
2010M1/2010M12 |
hi |
B |
2011M1/2011M12 |
|
B |
2012M1/2012M12 |
hello! |
Example 2
DS_r := timeshift ( DS_2 , 2 );
results in (see structure):
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! |
Example 3
DS_r := timeshift ( DS_3 , 1 );
results in (see structure):
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! |
Example 4
DS_r := timeshift( DS_4 , -1 );
results in (see structure):
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! |