File tree Expand file tree Collapse file tree 2 files changed +16
-3
lines changed
Expand file tree Collapse file tree 2 files changed +16
-3
lines changed Original file line number Diff line number Diff line change 11import { locale } from '$lib/stores/preferences.store';
22import { parseUtcDate } from '$lib/utils/date-time';
3- import { formatGroupTitle } from '$lib/utils/timeline-util';
3+ import { formatGroupTitle, toISOYearMonthUTC } from '$lib/utils/timeline-util';
44import { DateTime } from 'luxon';
55
66describe('formatGroupTitle', () => {
@@ -77,3 +77,13 @@ describe('formatGroupTitle', () => {
7777 expect(formatGroupTitle(date)).toBe('Invalid DateTime');
7878 });
7979});
80+
81+ describe('toISOYearMonthUTC', () => {
82+ it('should prefix year with 0s', () => {
83+ expect(toISOYearMonthUTC({ year: 28, month: 1 })).toBe('0028-01-01T00:00:00.000Z');
84+ });
85+
86+ it('should prefix month with 0s', () => {
87+ expect(toISOYearMonthUTC({ year: 2025, month: 1 })).toBe('2025-01-01T00:00:00.000Z');
88+ });
89+ });
Original file line number Diff line number Diff line change @@ -94,8 +94,11 @@ export const fromTimelinePlainYearMonth = (timelineYearMonth: TimelineYearMonth)
9494 { zone: 'local', locale: get(locale) },
9595 ) as DateTime<true>;
9696
97- export const toISOYearMonthUTC = ({ year, month }: TimelineYearMonth): string =>
98- `${year}-${month.toString().padStart(2, '0')}-01T00:00:00.000Z`;
97+ export const toISOYearMonthUTC = ({ year, month }: TimelineYearMonth): string => {
98+ const yearFull = `${year}`.padStart(4, '0');
99+ const monthFull = `${month}`.padStart(2, '0');
100+ return `${yearFull}-${monthFull}-01T00:00:00.000Z`;
101+ };
99102
100103export function formatMonthGroupTitle(_date: DateTime): string {
101104 if (!_date.isValid) {
You can’t perform that action at this time.
0 commit comments