feat : helpers isMonthInRange/isYearInRange (#date-year-picker)
Recommit : Task 2 avait orphelin le commit d'origine (reset HEAD). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
import {describe, expect, it} from 'vitest'
|
import {describe, expect, it} from 'vitest'
|
||||||
import {formatIsoToDisplay, isDateInRange, isValidIso, parseDisplayToIso} from './dateFormat'
|
import {formatIsoToDisplay, isDateInRange, isMonthInRange, isValidIso, isYearInRange, parseDisplayToIso} from './dateFormat'
|
||||||
|
|
||||||
describe('dateFormat', () => {
|
describe('dateFormat', () => {
|
||||||
describe('isValidIso', () => {
|
describe('isValidIso', () => {
|
||||||
@@ -59,4 +59,36 @@ describe('dateFormat', () => {
|
|||||||
expect(isDateInRange('2026-05-25', '2026-05-10', '2026-05-20')).toBe(false)
|
expect(isDateInRange('2026-05-25', '2026-05-10', '2026-05-20')).toBe(false)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
describe('isMonthInRange', () => {
|
||||||
|
it('returns true when no bounds are given', () => {
|
||||||
|
expect(isMonthInRange(2026, 4)).toBe(true)
|
||||||
|
})
|
||||||
|
it('respects the min bound by month (inclusive)', () => {
|
||||||
|
expect(isMonthInRange(2026, 4, '2026-05-10')).toBe(true) // mai chevauche
|
||||||
|
expect(isMonthInRange(2026, 3, '2026-05-10')).toBe(false) // avril < mai
|
||||||
|
})
|
||||||
|
it('respects the max bound by month (inclusive)', () => {
|
||||||
|
expect(isMonthInRange(2026, 4, undefined, '2026-05-31')).toBe(true)
|
||||||
|
expect(isMonthInRange(2026, 5, undefined, '2026-05-31')).toBe(false) // juin > mai
|
||||||
|
})
|
||||||
|
it('disables months in years outside the range', () => {
|
||||||
|
expect(isMonthInRange(2025, 11, '2026-05-10')).toBe(false)
|
||||||
|
expect(isMonthInRange(2027, 0, undefined, '2026-05-31')).toBe(false)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
describe('isYearInRange', () => {
|
||||||
|
it('returns true when no bounds are given', () => {
|
||||||
|
expect(isYearInRange(2026)).toBe(true)
|
||||||
|
})
|
||||||
|
it('respects the min bound by year (inclusive)', () => {
|
||||||
|
expect(isYearInRange(2026, '2026-05-10')).toBe(true)
|
||||||
|
expect(isYearInRange(2025, '2026-05-10')).toBe(false)
|
||||||
|
})
|
||||||
|
it('respects the max bound by year (inclusive)', () => {
|
||||||
|
expect(isYearInRange(2026, undefined, '2026-05-31')).toBe(true)
|
||||||
|
expect(isYearInRange(2027, undefined, '2026-05-31')).toBe(false)
|
||||||
|
})
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -24,3 +24,16 @@ export function isDateInRange(iso: string, min?: string, max?: string): boolean
|
|||||||
if (max && iso > max) return false
|
if (max && iso > max) return false
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function isMonthInRange(year: number, month: number, min?: string, max?: string): boolean {
|
||||||
|
const ym = `${year}-${String(month + 1).padStart(2, '0')}`
|
||||||
|
if (min && ym < min.slice(0, 7)) return false
|
||||||
|
if (max && ym > max.slice(0, 7)) return false
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
export function isYearInRange(year: number, min?: string, max?: string): boolean {
|
||||||
|
if (min && year < Number(min.slice(0, 4))) return false
|
||||||
|
if (max && year > Number(max.slice(0, 4))) return false
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user