Skip to content

Commit 5cbfd3a

Browse files
authored
fix(charts): properly format week of year (#726)
1 parent 7440a9b commit 5cbfd3a

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

app/services/forest_liana/line_stat_getter.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ def get_format
1414
when 'day'
1515
'%d/%m/%Y'
1616
when 'week'
17-
'W%V-%Y'
17+
'W%V-%G'
1818
when 'month'
1919
'%b %Y'
2020
when 'year'

spec/services/forest_liana/line_stat_getter_spec.rb

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,25 @@ module ForestLiana
6868
expect(stat.value.find { |item| item[:label] == "W18-2021" }[:values][:value]).to eq(2)
6969
expect(stat.value.find { |item| item[:label] == "W19-2021" }[:values][:value]).to eq(2)
7070
end
71+
72+
it 'should return consistent data for a leap year with week transition' do
73+
Owner.delete_all
74+
Owner.create(name: 'Michel', hired_at: Date.parse('23-12-2024'));
75+
Owner.create(name: 'Robert', hired_at: Date.parse('23-12-2024'));
76+
Owner.create(name: 'José', hired_at: Date.parse('30-12-2024'));
77+
Owner.create(name: 'Yves', hired_at: Date.parse('06-01-2025'));
78+
79+
stat = LineStatGetter.new(Owner, {
80+
timezone: "Europe/Paris",
81+
aggregator: "Count",
82+
timeRange: "Week",
83+
groupByFieldName: "hired_at",
84+
}, user).perform
85+
86+
expect(stat.value.find { |item| item[:label] == "W52-2024" }[:values][:value]).to eq(2)
87+
expect(stat.value.find { |item| item[:label] == "W01-2025" }[:values][:value]).to eq(1)
88+
expect(stat.value.find { |item| item[:label] == "W02-2025" }[:values][:value]).to eq(1)
89+
end
7190
end
7291
end
7392
end

0 commit comments

Comments
 (0)