mirror of
https://github.com/solidtime-io/solidtime.git
synced 2026-08-20 22:22:16 +01:00
Add "Week" grouping option to reporting
This commit is contained in:
committed by
Gregor Vostrak
parent
97fd882878
commit
dfe3206614
@@ -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'
|
||||
|
||||
@@ -7,10 +7,15 @@ import { useTasksQuery } from '@/utils/useTasksQuery';
|
||||
import { useClientsQuery } from '@/utils/useClientsQuery';
|
||||
import { useTagsQuery } from '@/utils/useTagsQuery';
|
||||
import { CheckCircleIcon, UserCircleIcon, UserGroupIcon } from '@heroicons/vue/20/solid';
|
||||
import { CalendarIcon, DocumentTextIcon, FolderIcon } from '@heroicons/vue/16/solid';
|
||||
import {
|
||||
CalendarDaysIcon,
|
||||
CalendarIcon,
|
||||
DocumentTextIcon,
|
||||
FolderIcon,
|
||||
} from '@heroicons/vue/16/solid';
|
||||
import { Coffee } from '@lucide/vue';
|
||||
import BillableIcon from '@/packages/ui/src/Icons/BillableIcon.vue';
|
||||
import { type DateFormat, formatDate } from '@/packages/ui/src/utils/time';
|
||||
import { type DateFormat, formatDate, formatWeekRange } from '@/packages/ui/src/utils/time';
|
||||
|
||||
export type GroupingOption =
|
||||
| 'project'
|
||||
@@ -21,7 +26,8 @@ export type GroupingOption =
|
||||
| 'description'
|
||||
| 'tag'
|
||||
| 'type'
|
||||
| 'day';
|
||||
| 'day'
|
||||
| 'week';
|
||||
|
||||
export const useReportingStore = defineStore('reporting', () => {
|
||||
// Cache query composables to avoid creating new subscriptions on every call
|
||||
@@ -85,6 +91,9 @@ export const useReportingStore = defineStore('reporting', () => {
|
||||
if (type === 'day') {
|
||||
return formatDate(key, dateFormat);
|
||||
}
|
||||
if (type === 'week') {
|
||||
return formatWeekRange(key, dateFormat);
|
||||
}
|
||||
return key;
|
||||
}
|
||||
|
||||
@@ -138,6 +147,11 @@ export const useReportingStore = defineStore('reporting', () => {
|
||||
value: 'day',
|
||||
icon: CalendarIcon,
|
||||
},
|
||||
{
|
||||
label: 'Week',
|
||||
value: 'week',
|
||||
icon: CalendarDaysIcon,
|
||||
},
|
||||
];
|
||||
|
||||
return {
|
||||
|
||||
Reference in New Issue
Block a user