add explicit type for string-based datetimes, replacing third-party datetime type with internal DateTime type

This commit is contained in:
MaysWind
2025-08-25 00:31:30 +08:00
parent f196ce969b
commit 25681f622d
35 changed files with 423 additions and 404 deletions
+22
View File
@@ -1,5 +1,27 @@
import type { TypeAndName, TypeAndDisplayName } from '@/core/base.ts';
export interface DateTime {
getUnixTime(): number;
getLocalizedCalendarYear(): number;
getGregorianCalendarYear(): number;
getGregorianCalendarQuarter(): number;
getLocalizedCalendarQuarter(): number;
getGregorianCalendarMonth(): number;
getGregorianCalendarMonthName(): string;
getLocalizedCalendarMonth(): number;
getGregorianCalendarDay(): number;
getLocalizedCalendarDay(): number;
getGregorianCalendarYearDashMonthDashDay(): TextualYearMonthDay;
getGregorianCalendarYearDashMonth(): TextualYearMonth;
getWeekDay(): WeekDay;
toGregorianCalendarYearMonthDay(): YearMonthDay;
toGregorianCalendarYear0BasedMonth(): Year0BasedMonth;
format(format: string): string;
}
export type TextualYearMonth = `${number}-${number}`;
export type TextualYearMonthDay = `${number}-${number}-${number}`;
export interface YearQuarter {
readonly year: number;
readonly quarter: number;
+3 -3
View File
@@ -1,4 +1,4 @@
import type { UnixTimeRange } from './datetime.ts';
import type { TextualYearMonth, UnixTimeRange } from './datetime.ts';
export class FiscalYearStart {
public static readonly JanuaryFirstDay = new FiscalYearStart(1, 1);
@@ -75,8 +75,8 @@ export class FiscalYearStart {
return FiscalYearStart.of(month, day);
}
public toMonthDashDayString(): string {
return `${this.month.toString().padStart(2, '0')}-${this.day.toString().padStart(2, '0')}`;
public toMonthDashDayString(): TextualYearMonth {
return `${this.month.toString().padStart(2, '0')}-${this.day.toString().padStart(2, '0')}` as TextualYearMonth;
}
private static isValidFiscalYearMonthDay(month: number, day: number): boolean {