You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
sims-hq/packages/domain/src/business-day.ts

33 lines
1009 B
TypeScript

/**
* The working-day concept carried over from the OG applications (Day Begin /
* Day End in the Manager Menu): every dated record stamps the store's opened
* business date, never the machine clock. The wall clock is display metadata.
*/
export type IsoDate = string // YYYY-MM-DD
export interface BusinessDay {
tenantId: string
storeId: string
date: IsoDate
openedAt: string
openedBy: string
closedAt?: string
closedBy?: string
}
export function isOpen(day: BusinessDay): boolean {
return day.closedAt === undefined
}
/** Indian financial year label: 2026-04-01 → "2026-27", 2026-03-31 → "2025-26". */
export function fyOf(date: IsoDate, fyStartMonth = 4): string {
const [y, m] = [Number(date.slice(0, 4)), Number(date.slice(5, 7))]
const start = m >= fyStartMonth ? y : y - 1
return `${start}-${String(start + 1).slice(2)}`
}
/** Short FY marker for document series prefixes: "2026-27" → "26". */
export function fyShort(fy: string): string {
return fy.slice(2, 4)
}