/** * Peak/off-peak pricing periods. * * DeepSeek bills off-peak minutes at {@link ScheduleConfig.offPeakFactor} times the * peak rate ("空闲时段价格为高峰时段价格的一半"), so the pricing period is a scalar * multiplier over an otherwise time-independent rate. The period is decided from * the **Beijing** wall clock: Monday-Friday 09:00-12:00 and 14:00-18:00 are peak, * everything else — explicitly including weekends and statutory holidays — is * off-peak. The machine's own time zone never participates. * * Per the published wording the peak predicate keys on "周一至周五", while a * make-up workday (调休补班日) is by construction a Saturday or Sunday, so the * default treats it as off-peak. `treatMakeupWorkdaysAsPeak` exists because that * reading is an interpretation of prose rather than a measured fact; the estimator * probes it against observed balance drops instead of trusting either guess. * * @module dsh-balance/schedule */ /** One daily peak window in wall-clock `HH:mm`, `to` exclusive. */ export interface PeakWindow { readonly from: string; readonly to: string; } /** The holiday/off-peak calendar for one year, as `YYYY-MM-DD` sets. */ export interface CalendarYear { /** Statutory holidays: these dates are off-peak even when they are weekdays. */ readonly offDays: readonly string[]; /** Make-up workdays: weekend dates the State Council turns into working days. */ readonly makeupWorkdays: readonly string[]; } /** Everything the schedule needs to classify an instant. */ export interface ScheduleConfig { /** IANA zone the peak hours are expressed in. */ readonly timeZone: string; /** ISO weekdays (1 = Monday .. 7 = Sunday) that carry peak windows. */ readonly peakDays: readonly number[]; /** Daily peak windows in wall-clock time. */ readonly peakWindows: readonly PeakWindow[]; /** Multiplier applied outside peak windows (official value: 0.5). */ readonly offPeakFactor: number; /** Whether a make-up workday is priced as a peak day. */ readonly treatMakeupWorkdaysAsPeak: boolean; } /** Which kind of day an instant falls on. */ export type CalendarClass = 'weekday' | 'weekend' | 'holiday' | 'makeup'; /** Wall-clock decomposition of one instant in the configured zone. */ export interface WallClock { /** `YYYY-MM-DD` in the configured zone. */ readonly date: string; /** Minutes since local midnight. */ readonly minutes: number; /** ISO weekday, 1 = Monday .. 7 = Sunday. */ readonly isoDay: number; } /** * Decompose an instant into the configured zone's wall clock. * @param timeZone - IANA zone name. * @param epochMs - the instant. * @returns date, minutes since midnight, and ISO weekday. * @throws when the zone is unknown to `Intl` or the parts carry no weekday. */ export declare function wallClock(timeZone: string, epochMs: number): WallClock; /** * Convert a wall-clock date plus minutes-since-midnight in `timeZone` to an instant. * * The offset is measured on both sides of the naive guess and reused only when it * is stable, so a zone without daylight saving (China has none) converges on the * first correction while a DST zone still lands on a valid instant. * * @param timeZone - IANA zone name. * @param date - `YYYY-MM-DD`. * @param minutes - minutes since local midnight. * @returns the epoch milliseconds. */ export declare function zonedEpoch(timeZone: string, date: string, minutes: number): number; /** Shift a `YYYY-MM-DD` date by whole days using calendar arithmetic. */ export declare function shiftDate(date: string, days: number): string; /** Parse `HH:mm` into minutes since midnight. */ export declare function parseHhMm(value: string): number | null; /** Resolved, validated schedule windows in minutes since midnight. */ export interface ResolvedWindow { readonly start: number; readonly end: number; } /** * Validate configured windows once at plugin activation. * @param windows - the configured `HH:mm` pairs. * @returns the windows in minutes since midnight, in configured order. * @throws when a value is not `HH:mm` or a window does not end after it starts. */ export declare function resolveWindows(windows: readonly PeakWindow[]): readonly ResolvedWindow[]; /** Immutable lookup over the merged holiday calendar. */ export interface CalendarLookup { /** Whether a year's holidays are known at all (absent years are NOT "no holidays"). */ knows(year: number): boolean; /** Statutory holidays for one date, if known. */ isOffDay(date: string): boolean; /** Make-up workday for one date, if known. */ isMakeup(date: string): boolean; /** Years with usable data, ascending. */ readonly years: readonly number[]; } /** Build a calendar lookup from per-year sets. */ export declare function createCalendarLookup(years: Readonly>): CalendarLookup; /** A schedule bound to one configuration and calendar. */ export interface Schedule { /** Classify the day one instant falls on. */ calendarClass(at: number): CalendarClass; /** Whether the instant is priced at peak rates. */ isPeak(at: number): boolean; /** Price multiplier in force at the instant. */ factor(at: number): number; /** The next instant at which {@link factor} changes. */ nextBoundary(at: number): number; } /** * Bind a schedule to its configuration and calendar. * @param config - validated schedule configuration. * @param calendar - the merged holiday lookup. * @param resolveWindowsFn - window parser, injectable for testing. * @returns the schedule. */ export declare function createSchedule(config: ScheduleConfig, calendar: CalendarLookup, resolveWindowsFn?: (windows: readonly PeakWindow[]) => readonly ResolvedWindow[]): Schedule;