mirror of
https://github.com/solidtime-io/solidtime.git
synced 2026-08-21 06:32:14 +01:00
add formatting support for months grouping
This commit is contained in:
@@ -1,5 +1,10 @@
|
||||
import { describe, expect, test } from 'vitest';
|
||||
import { formatHumanReadableDuration, formatReportingDuration, formatWeekRange } from './time';
|
||||
import {
|
||||
formatHumanReadableDuration,
|
||||
formatMonth,
|
||||
formatReportingDuration,
|
||||
formatWeekRange,
|
||||
} from './time';
|
||||
|
||||
const seconds = 14 * 3600 + 45 * 60 + 6; // 14h 45m 06s
|
||||
|
||||
@@ -60,3 +65,9 @@ describe('formatWeekRange', () => {
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe('formatMonth', () => {
|
||||
test('renders the name of the month that the key covers', () => {
|
||||
expect(formatMonth('2001-02')).toBe('February 2001');
|
||||
});
|
||||
});
|
||||
|
||||
@@ -245,6 +245,15 @@ export function formatWeekRange(date: string, format?: DateFormat): string {
|
||||
return `${formatDate(date, format)} - ${formatDate(end, format)}`;
|
||||
}
|
||||
|
||||
/*
|
||||
* Returns the month that the given key falls in. There is no `DateFormat` variant for a
|
||||
* month, so this is not affected by the organization date format.
|
||||
* @param date - a month, in the format of 'YYYY-MM'
|
||||
*/
|
||||
export function formatMonth(date: string): string {
|
||||
return getDayJsInstance()(date).format('MMMM YYYY');
|
||||
}
|
||||
|
||||
/*
|
||||
* Returns a human readable date format.
|
||||
* @param date - date in the format of 'YYYY-MM-DD'
|
||||
|
||||
@@ -15,7 +15,12 @@ import {
|
||||
} from '@heroicons/vue/16/solid';
|
||||
import { Coffee } from '@lucide/vue';
|
||||
import BillableIcon from '@/packages/ui/src/Icons/BillableIcon.vue';
|
||||
import { type DateFormat, formatDate, formatWeekRange } from '@/packages/ui/src/utils/time';
|
||||
import {
|
||||
type DateFormat,
|
||||
formatDate,
|
||||
formatMonth,
|
||||
formatWeekRange,
|
||||
} from '@/packages/ui/src/utils/time';
|
||||
|
||||
export type GroupingOption =
|
||||
| 'project'
|
||||
@@ -27,7 +32,9 @@ export type GroupingOption =
|
||||
| 'tag'
|
||||
| 'type'
|
||||
| 'day'
|
||||
| 'week';
|
||||
| 'week'
|
||||
| 'month'
|
||||
| 'year';
|
||||
|
||||
export const useReportingStore = defineStore('reporting', () => {
|
||||
// Cache query composables to avoid creating new subscriptions on every call
|
||||
@@ -94,6 +101,10 @@ export const useReportingStore = defineStore('reporting', () => {
|
||||
if (type === 'week') {
|
||||
return formatWeekRange(key, dateFormat);
|
||||
}
|
||||
if (type === 'month') {
|
||||
return formatMonth(key);
|
||||
}
|
||||
// A `year` key is already a bare year, so it falls through unchanged.
|
||||
return key;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user