feat: implement fiscal period date fields component and validation logic (#301)

* feat: implement fiscal period date fields component and validation logic

* feat: update fiscal period validation and naming logic
This commit is contained in:
Mattsson
2026-04-21 17:08:38 +02:00
committed by GitHub
parent 08991218ee
commit 885dd8a2e4
8 changed files with 504 additions and 257 deletions
@@ -64,12 +64,12 @@ describe('validatePeriodDuration', () => {
expect(validatePeriodDuration('2025-03-25', '2025-12-31', { isFirstPeriod: true })).toBeNull()
})
it('allows mid-month start for first period (October)', () => {
expect(validatePeriodDuration('2025-10-15', '2025-12-31', { isFirstPeriod: true })).toBeNull()
it('allows mid-month start for first period (July)', () => {
expect(validatePeriodDuration('2025-07-15', '2025-12-31', { isFirstPeriod: true })).toBeNull()
})
it('still allows day-1 start for first period', () => {
expect(validatePeriodDuration('2025-10-01', '2025-12-31', { isFirstPeriod: true })).toBeNull()
it('still allows day-1 start for first period (6 months)', () => {
expect(validatePeriodDuration('2025-07-01', '2025-12-31', { isFirstPeriod: true })).toBeNull()
})
it('enforces end-of-month even for first period', () => {
@@ -84,6 +84,26 @@ describe('validatePeriodDuration', () => {
expect(result).toContain('18 months')
})
it('enforces 6-month minimum for first period (2 months)', () => {
expect(validatePeriodDuration('2026-03-25', '2026-05-31', { isFirstPeriod: true })).toBe(
'First fiscal period must be at least 6 months (BFL 3 kap.)'
)
})
it('enforces 6-month minimum for first period (5 months)', () => {
expect(validatePeriodDuration('2026-08-01', '2026-12-31', { isFirstPeriod: true })).toBe(
'First fiscal period must be at least 6 months (BFL 3 kap.)'
)
})
it('allows exactly 6 months for first period', () => {
expect(validatePeriodDuration('2026-07-01', '2026-12-31', { isFirstPeriod: true })).toBeNull()
})
it('realistic customer case: 2026-03-25 to 2027-02-28', () => {
expect(validatePeriodDuration('2026-03-25', '2027-02-28', { isFirstPeriod: true })).toBeNull()
})
it('returns error when end is not last day of month', () => {
expect(validatePeriodDuration('2025-01-01', '2025-12-15')).toBe(
'Period end must be the last day of a month'
@@ -62,5 +62,10 @@ export function validatePeriodDuration(start: string, end: string, options?: Val
return `Period duration ${months} months exceeds maximum 18 months (BFL 3 kap.)`
}
// First fiscal period must be at least 6 months per BFL 3 kap.
if (options?.isFirstPeriod && months < 6) {
return `First fiscal period must be at least 6 months (BFL 3 kap.)`
}
return null
}