From 12c426159c456b785d7d3cdf7c7dc65a08692a96 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?John=20Molakvo=C3=A6?= <14975046+skjnldsv@users.noreply.github.com> Date: Thu, 26 Nov 2026 21:45:38 +0100 Subject: [PATCH] feat(profile): show what one's vacation days are made of MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The vacation card on one's own profile showed the days available in a ring and left the rest of the card empty. The ring now splits the used days in taken and planned, shows the days waiting for approval, and counts the days left in its centre. Next to it: what the days are made of (the year's days, carried over, HR's adjustment), a legend with the figures, the next leave, and a warning when carried-over days are about to expire. Planned days are the approved leave starting after today, counted in the year the leave starts, as the server does for the balance. Assisted-by: ClaudeCode:claude-opus-5-5 Signed-off-by: John Molakvoæ <14975046+skjnldsv@users.noreply.github.com> --- src/components/VacationOverview.vue | 308 ++++++++++++++++++++++++++++ src/utils/dates.spec.ts | 13 ++ src/utils/dates.ts | 16 ++ src/utils/vacation.spec.ts | 41 ++++ src/utils/vacation.ts | 55 +++++ src/views/ProfileView.vue | 37 ++-- 6 files changed, 453 insertions(+), 17 deletions(-) create mode 100644 src/components/VacationOverview.vue create mode 100644 src/utils/vacation.spec.ts create mode 100644 src/utils/vacation.ts diff --git a/src/components/VacationOverview.vue b/src/components/VacationOverview.vue new file mode 100644 index 00000000..25837e81 --- /dev/null +++ b/src/components/VacationOverview.vue @@ -0,0 +1,308 @@ + + + + + + diff --git a/src/utils/dates.spec.ts b/src/utils/dates.spec.ts index 5a3a1dbf..ea794f78 100644 --- a/src/utils/dates.spec.ts +++ b/src/utils/dates.spec.ts @@ -8,6 +8,7 @@ import { countWorkingDays, formatCountdown, formatRange, + formatShortRange, parseWeekdays, seasonOf, toIso, @@ -83,6 +84,18 @@ describe('formatRange', () => { }) }) +describe('formatShortRange', () => { + it('leaves the current year out', () => { + expect(formatShortRange('2026-11-30', '2026-12-04', 2026)).not.toContain('2026') + expect(formatShortRange('2026-11-30', '2026-11-30', 2026)).not.toContain('2026') + }) + + it('shows the year of a range that leaves the current year', () => { + expect(formatShortRange('2026-12-22', '2027-01-05', 2026)).toContain('2027') + expect(formatShortRange('2027-03-01', '2027-03-05', 2026)).toContain('2027') + }) +}) + describe('formatCountdown', () => { it('pads minutes and seconds but not hours', () => { expect(formatCountdown(((7 * 60) + 5) * 60000 + 3000)).toBe('7:05:03') diff --git a/src/utils/dates.ts b/src/utils/dates.ts index 468b0730..3d2e5755 100644 --- a/src/utils/dates.ts +++ b/src/utils/dates.ts @@ -86,6 +86,22 @@ export function formatRange(startIso: string | null | undefined, endIso: string return `${formatDate(startIso)} – ${formatDate(endIso)}` } +/** + * A short range like "Nov 30 – Dec 4", with the year only when it is not the + * current one: "Dec 22, 2026 – Jan 5, 2027". + * + * @param startIso 'YYYY-MM-DD' + * @param endIso 'YYYY-MM-DD' + * @param currentYear the year that goes without saying + */ +export function formatShortRange(startIso: string, endIso: string, currentYear: number): string { + const start = new Date(startIso + 'T00:00:00') + const end = new Date(endIso + 'T00:00:00') + const withYear = start.getFullYear() !== currentYear || end.getFullYear() !== currentYear + const format = new Intl.DateTimeFormat(locale(), withYear ? { year: 'numeric', month: 'short', day: 'numeric' } : { month: 'short', day: 'numeric' }) + return startIso === endIso ? format.format(start) : format.formatRange(start, end) +} + /** * A duration as `H:MM:SS`, for the final stretch before a break starts. Hours are * not padded (and run past 24) because "47:59:12" reads as a countdown while diff --git a/src/utils/vacation.spec.ts b/src/utils/vacation.spec.ts new file mode 100644 index 00000000..44719208 --- /dev/null +++ b/src/utils/vacation.spec.ts @@ -0,0 +1,41 @@ +/** + * SPDX-FileCopyrightText: 2026 Nextcloud GmbH and Nextcloud contributors + * SPDX-License-Identifier: AGPL-3.0-or-later + */ +import type { RequestStatus } from '../types/index.ts' + +import { describe, expect, it } from 'vitest' +import { vacationSplit } from './vacation.ts' + +const row = { typeId: 1, year: 2026, used: 24, pending: 2 } +const leave = (startDate: string, endDate: string, workingDays: number, status: RequestStatus = 'APPROVED', typeId = 1) => ({ typeId, status, startDate, endDate, workingDays }) + +describe('vacationSplit', () => { + it('counts the leave starting after today as planned, the rest of the used days as taken', () => { + const split = vacationSplit(row, [leave('2026-03-02', '2026-03-06', 5), leave('2026-12-22', '2026-12-31', 4)], '2026-11-26') + expect(split.taken).toBe(20) + expect(split.planned).toBe(4) + expect(split.pending).toBe(2) + }) + + it('counts leave that started already as taken, and leave starting next year in that year', () => { + const split = vacationSplit(row, [leave('2026-11-25', '2026-11-27', 3), leave('2027-01-04', '2027-01-08', 5)], '2026-11-26') + expect(split.planned).toBe(0) + expect(split.taken).toBe(24) + }) + + it('leaves out other types, cancelled leave and requests still waiting from the planned days', () => { + const split = vacationSplit(row, [leave('2026-12-01', '2026-12-01', 1, 'APPROVED', 2), leave('2026-12-02', '2026-12-02', 1, 'CANCELLED'), leave('2026-12-03', '2026-12-03', 1, 'PENDING')], '2026-11-26') + expect(split.planned).toBe(0) + }) + + it('never plans more than is used', () => { + expect(vacationSplit({ ...row, used: 2 }, [leave('2026-12-22', '2026-12-31', 4)], '2026-11-26')).toMatchObject({ taken: 0, planned: 2 }) + }) + + it('names the next leave, booked or waiting for approval', () => { + const requests = [leave('2027-01-04', '2027-01-08', 5), leave('2026-12-14', '2026-12-15', 2, 'PENDING'), leave('2026-11-02', '2026-11-03', 2)] + expect(vacationSplit(row, requests, '2026-11-26').next).toEqual({ startDate: '2026-12-14', endDate: '2026-12-15', workingDays: 2, pending: true }) + expect(vacationSplit(row, [], '2026-11-26').next).toBeNull() + }) +}) diff --git a/src/utils/vacation.ts b/src/utils/vacation.ts new file mode 100644 index 00000000..282978bf --- /dev/null +++ b/src/utils/vacation.ts @@ -0,0 +1,55 @@ +/** + * SPDX-FileCopyrightText: 2026 Nextcloud GmbH and Nextcloud contributors + * SPDX-License-Identifier: AGPL-3.0-or-later + */ +import type { BalanceRow, LeaveRequest, RequestStatus } from '../types/index.ts' + +/** Statuses whose days count as used, as on the server (§4.2) */ +const USED: RequestStatus[] = ['APPROVED', 'WITHDRAWAL_PENDING'] +/** Statuses still waiting for a decision */ +const PENDING: RequestStatus[] = ['PENDING', 'ESCALATED'] + +/** The next leave of a type, booked or waiting for approval */ +export interface NextLeave { + startDate: string + endDate: string + workingDays: number + pending: boolean +} + +/** How the vacation days of a year split up */ +export interface VacationSplit { + /** Used days whose leave started today or before */ + taken: number + /** Used days whose leave starts after today */ + planned: number + pending: number + next: NextLeave | null +} + +/** + * Splits the used days of a balance row into taken and planned, the way the + * server counts them: each request's days in the year its leave starts. + * + * @param row the balance of the type and year + * @param requests the person's requests + * @param today 'YYYY-MM-DD' + */ +export function vacationSplit(row: Pick, requests: Pick[], today: string): VacationSplit { + const ofType = requests.filter((request) => request.typeId === row.typeId) + const planned = ofType + .filter((request) => USED.includes(request.status) && request.startDate > today && request.startDate.startsWith(`${row.year}-`)) + .reduce((sum, request) => sum + request.workingDays, 0) + const upcoming = ofType + .filter((request) => (USED.includes(request.status) || PENDING.includes(request.status)) && request.startDate > today) + .sort((a, b) => a.startDate.localeCompare(b.startDate))[0] + const clamped = Math.min(planned, row.used) + return { + taken: row.used - clamped, + planned: clamped, + pending: row.pending, + next: upcoming + ? { startDate: upcoming.startDate, endDate: upcoming.endDate, workingDays: upcoming.workingDays, pending: PENDING.includes(upcoming.status) } + : null, + } +} diff --git a/src/views/ProfileView.vue b/src/views/ProfileView.vue index 2ed9f6f7..ef06d0a5 100644 --- a/src/views/ProfileView.vue +++ b/src/views/ProfileView.vue @@ -68,12 +68,17 @@

{{ t('absence', 'Vacation {year}', { year: profile.holidays.year }) }}

-
- - - {{ t('absence', 'Details in My leave') }} - -
+ @@ -91,7 +96,7 @@ {{ t('absence', 'Somebody else from HR changes your own days.') }}

-

+

{{ n('absence', 'Next leave: {range}, {count} working day', 'Next leave: {range}, {count} working days', profile.nextLeave.workingDays, { range: formatRange(profile.nextLeave.startDate, profile.nextLeave.endDate), count: profile.nextLeave.workingDays }) }}

@@ -172,7 +177,7 @@