Extract the day of the year · dayofyear

🟢 2 of 2 forms all ok · VTL 2.2 Reference Manual ↗ · vtlengine 1.10.0rc2 (90ee9376) · pandas 2.3.3 · DuckDB 1.5.5
🟢 all ok🟡 partially implemented🛡️ refused with an error🔴 not implemented or crash🔵 engines differ ✅ match · ❌ wrong result · 🛡 guarded error (code) · 💥 crash · 📌 team decision
Dataset formsComponent formsScalar forms
        ---
config:
  flowchart:
    useMaxWidth: false

---
flowchart TB
    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["Extract the day of the year · dayofyear<br/>🟢2"]:::ok
    subgraph G_comp["Component"]
        direction LR
        v_comp["calc dayofyear(comp)"]:::ok
    end
    subgraph G_sc["Scalar"]
        direction LR
        v_sc["dayofyear(sc)"]:::ok
    end
    O --- G_comp
    O --- G_sc
    style G_comp fill:#f8f9fa,stroke:#495057,stroke-width:2px,stroke-dasharray: 8 5
    style G_sc fill:#f8f9fa,stroke:#495057,stroke-width:2px,stroke-dasharray: 2 3
    click v_comp href "#form-comp"
    click v_sc href "#form-sc"
    

Types

Takes date, time_period · Gives integer

Goes to · integer — 44 operators in 8 blocks 🟢44
General purpose operators (1) 🟢1
String operators (2) 🟢2
Numeric operators (18) 🟢18
Time operators (6) 🟢6
Hierarchical aggregation (1) 🟢1
Aggregate and Analytic operators (10) 🟢10
Data validation operators (2) 🟢2
Definitions (VTL-DL) (4) 🟢4
Goes to · operators that take any scalar — 46 operators in 8 blocks 🟢46
General purpose operators (6) 🟢6
Join operators (4) 🟢4
Comparison operators (11) 🟢11
Set operators (4) 🟢4
Aggregate and Analytic operators (8) 🟢8
Data validation operators (1) 🟢1
Conditional operators (3) 🟢3
Clause operators (9) 🟢9

Forms

calc dayofyear(comp) 🟢 · date, time_period → integer

Leap and common years 🟢 pandas ✅ · DuckDB ✅
Tests:

dayofyear(Me_1) inside calc, on March 1st of a common and of a leap year, and on the last day of a leap year.

Manual:

Extract time period: “The operator dayofyear returns the ordinal day within the year (between 1 and 366).”

Expected:

Me_2 is 60 (31 + 28 + 1, in 2019), 61 (31 + 29 + 1, in 2020) and 366, Integers.

script.vtl
DS_r := DS_1[calc Me_2 := dayofyear(Me_1)];
Input DS_1
Id_1Me_1
G2019-03-01
H2020-03-01
T2020-12-31
Expected DS_r
Id_1Me_1Me_2
G2019-03-0160
H2020-03-0161
T2020-12-31366

Files: script.vtl · input/DS_1.csv · input/DS_1.json · expected/DS_r.csv · expected/DS_r.json · example page ↗

dayofyear(sc) 🟢 · date, time_period → integer

April in a leap year 🟢 pandas ✅ · DuckDB ✅
Tests:

dayofyear(SC_1) on a scalar date, SC_1 = 2020-04-07, from the example that the manual misplaced on the Days between two dates page, its Example 2.

Manual:

Extract time period: “The operator dayofyear returns the ordinal day within the year (between 1 and 366)”; and dayofyear (2020-04-07); “returns 98”.

Expected:

DS_r = 98, an Integer: 31 + 29 (2020 is a leap year) + 31 + 7.

script.vtl
DS_r := dayofyear(SC_1);
Input scalars
SC_1
2020-04-07
Expected scalars

Name

Type

Value

DS_r

Integer

98

Files: script.vtl · input/scalars.csv · input/scalars.json · expected/scalars.json · example page ↗