mirror of
https://github.com/solidtime-io/solidtime.git
synced 2026-08-21 06:32:14 +01:00
Add "Week" grouping option to reporting
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import { describe, expect, test } from 'vitest';
|
||||
import { formatHumanReadableDuration, formatReportingDuration } from './time';
|
||||
import { formatHumanReadableDuration, formatReportingDuration, formatWeekRange } from './time';
|
||||
|
||||
const seconds = 14 * 3600 + 45 * 60 + 6; // 14h 45m 06s
|
||||
|
||||
@@ -42,3 +42,21 @@ describe('formatReportingDuration', () => {
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe('formatWeekRange', () => {
|
||||
test('renders the six days following the given first day of the week', () => {
|
||||
expect(formatWeekRange('2026-07-27', 'slash-separated-dd-mm-yyyy')).toBe(
|
||||
'27/07/2026 - 02/08/2026'
|
||||
);
|
||||
});
|
||||
|
||||
test('spans a month boundary', () => {
|
||||
expect(formatWeekRange('2026-07-27')).toBe('27.7.2026 - 2.8.2026');
|
||||
});
|
||||
|
||||
test('spans a year boundary', () => {
|
||||
expect(formatWeekRange('2025-12-29', 'slash-separated-dd-mm-yyyy')).toBe(
|
||||
'29/12/2025 - 04/01/2026'
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -236,6 +236,15 @@ export function formatWeek(date: string | null): string {
|
||||
return 'Week ' + getDayJsInstance()(date).week();
|
||||
}
|
||||
|
||||
/*
|
||||
* Returns the range covered by the week starting on the given day.
|
||||
* @param date - first day of a week, in the format of 'YYYY-MM-DD'
|
||||
*/
|
||||
export function formatWeekRange(date: string, format?: DateFormat): string {
|
||||
const end = getDayJsInstance()(date).add(6, 'day').format('YYYY-MM-DD');
|
||||
return `${formatDate(date, format)} - ${formatDate(end, format)}`;
|
||||
}
|
||||
|
||||
/*
|
||||
* Returns a human readable date format.
|
||||
* @param date - date in the format of 'YYYY-MM-DD'
|
||||
|
||||
Reference in New Issue
Block a user