mirror of
https://github.com/mayswind/ezbookkeeping.git
synced 2026-05-15 15:37:33 +08:00
support date display type (Gregorian and Buddhist)
This commit is contained in:
@@ -0,0 +1,88 @@
|
||||
import type { TypeAndName } from '@/core/base.ts';
|
||||
|
||||
export enum CalendarType {
|
||||
Gregorian = 0,
|
||||
Buddhist = 1,
|
||||
Chinese = 2
|
||||
}
|
||||
|
||||
export class CalendarDisplayType implements TypeAndName {
|
||||
private static readonly allInstances: CalendarDisplayType[] = [];
|
||||
private static readonly allInstancesByType: Record<number, CalendarDisplayType> = {};
|
||||
private static readonly allInstancesByTypeName: Record<string, CalendarDisplayType> = {};
|
||||
|
||||
public static readonly LanguageDefaultType: number = 0;
|
||||
public static readonly Gregorian = new CalendarDisplayType(1, 'Gregorian', 'Gregorian', CalendarType.Gregorian);
|
||||
|
||||
public static readonly Default = CalendarDisplayType.Gregorian;
|
||||
|
||||
public readonly type: number;
|
||||
public readonly typeName: string;
|
||||
public readonly name: string;
|
||||
public readonly primaryCalendarType: CalendarType;
|
||||
public readonly secondaryCalendarType?: CalendarType;
|
||||
|
||||
private constructor(type: number, typeName: string, name: string, primaryCalendarType: CalendarType, secondaryCalendarType?: CalendarType) {
|
||||
this.type = type;
|
||||
this.typeName = typeName;
|
||||
this.name = name;
|
||||
this.primaryCalendarType = primaryCalendarType;
|
||||
this.secondaryCalendarType = secondaryCalendarType;
|
||||
|
||||
CalendarDisplayType.allInstances.push(this);
|
||||
CalendarDisplayType.allInstancesByType[type] = this;
|
||||
CalendarDisplayType.allInstancesByTypeName[typeName] = this;
|
||||
}
|
||||
|
||||
public static values(): CalendarDisplayType[] {
|
||||
return CalendarDisplayType.allInstances;
|
||||
}
|
||||
|
||||
public static valueOf(type: number): CalendarDisplayType | undefined {
|
||||
return CalendarDisplayType.allInstancesByType[type];
|
||||
}
|
||||
|
||||
public static parse(typeName: string): CalendarDisplayType | undefined {
|
||||
return CalendarDisplayType.allInstancesByTypeName[typeName];
|
||||
}
|
||||
}
|
||||
|
||||
export class DateDisplayType implements TypeAndName {
|
||||
private static readonly allInstances: DateDisplayType[] = [];
|
||||
private static readonly allInstancesByType: Record<number, DateDisplayType> = {};
|
||||
private static readonly allInstancesByTypeName: Record<string, DateDisplayType> = {};
|
||||
|
||||
public static readonly LanguageDefaultType: number = 0;
|
||||
public static readonly Gregorian = new DateDisplayType(1, 'Gregorian', 'Gregorian', CalendarType.Gregorian);
|
||||
public static readonly Chinese = new DateDisplayType(2, 'Buddhist', 'Buddhist', CalendarType.Buddhist);
|
||||
|
||||
public static readonly Default = DateDisplayType.Gregorian;
|
||||
|
||||
public readonly type: number;
|
||||
public readonly typeName: string;
|
||||
public readonly name: string;
|
||||
public readonly calendarType: CalendarType;
|
||||
|
||||
private constructor(type: number, typeName: string, name: string, calendarType: CalendarType) {
|
||||
this.type = type;
|
||||
this.typeName = typeName;
|
||||
this.name = name;
|
||||
this.calendarType = calendarType;
|
||||
|
||||
DateDisplayType.allInstances.push(this);
|
||||
DateDisplayType.allInstancesByType[type] = this;
|
||||
DateDisplayType.allInstancesByTypeName[typeName] = this;
|
||||
}
|
||||
|
||||
public static values(): DateDisplayType[] {
|
||||
return DateDisplayType.allInstances;
|
||||
}
|
||||
|
||||
public static valueOf(type: number): DateDisplayType | undefined {
|
||||
return DateDisplayType.allInstancesByType[type];
|
||||
}
|
||||
|
||||
public static parse(typeName: string): DateDisplayType | undefined {
|
||||
return DateDisplayType.allInstancesByTypeName[typeName];
|
||||
}
|
||||
}
|
||||
+30
-13
@@ -1,33 +1,50 @@
|
||||
import type { TypeAndName, TypeAndDisplayName } from '@/core/base.ts';
|
||||
import type { CalendarType } from '@/core/calendar.ts';
|
||||
import type { NumeralSystem } from '@/core/numeral.ts';
|
||||
|
||||
export interface DateTime {
|
||||
getUnixTime(): number;
|
||||
getLocalizedCalendarYear(): number;
|
||||
getLocalizedCalendarYear(options: DateTimeFormatOptions): number;
|
||||
getGregorianCalendarYear(): number;
|
||||
getGregorianCalendarQuarter(): number;
|
||||
getLocalizedCalendarQuarter(): number;
|
||||
getLocalizedCalendarQuarter(options: DateTimeFormatOptions): number;
|
||||
getGregorianCalendarMonth(): number;
|
||||
getGregorianCalendarMonthDisplayName(): string;
|
||||
getGregorianCalendarMonthDisplayShortName(): string;
|
||||
getLocalizedCalendarMonth(): number;
|
||||
getLocalizedCalendarMonthDisplayName(): string;
|
||||
getLocalizedCalendarMonthDisplayShortName(): string;
|
||||
getGregorianCalendarMonthDisplayName(options: DateTimeFormatOptions): string;
|
||||
getGregorianCalendarMonthDisplayShortName(options: DateTimeFormatOptions): string;
|
||||
getLocalizedCalendarMonth(options: DateTimeFormatOptions): number;
|
||||
getLocalizedCalendarMonthDisplayName(options: DateTimeFormatOptions): string;
|
||||
getLocalizedCalendarMonthDisplayShortName(options: DateTimeFormatOptions): string;
|
||||
getGregorianCalendarDay(): number;
|
||||
getLocalizedCalendarDay(): number;
|
||||
getLocalizedCalendarDay(options: DateTimeFormatOptions): number;
|
||||
getGregorianCalendarYearDashMonthDashDay(): TextualYearMonthDay;
|
||||
getGregorianCalendarYearDashMonth(): TextualYearMonth;
|
||||
getWeekDay(): WeekDay;
|
||||
getWeekDayDisplayName(): string
|
||||
getWeekDayDisplayShortName(): string;
|
||||
getWeekDayDisplayMinName(): string;
|
||||
getWeekDayDisplayName(options: DateTimeFormatOptions): string
|
||||
getWeekDayDisplayShortName(options: DateTimeFormatOptions): string;
|
||||
getWeekDayDisplayMinName(options: DateTimeFormatOptions): string;
|
||||
getHour(): number;
|
||||
getMinute(): number;
|
||||
getSecond(): number;
|
||||
getDisplayAMPM(): string;
|
||||
getDisplayAMPM(options: DateTimeFormatOptions): string;
|
||||
getTimezoneUtcOffsetMinutes(): number;
|
||||
toGregorianCalendarYearMonthDay(): YearMonthDay;
|
||||
toGregorianCalendarYear0BasedMonth(): Year0BasedMonth;
|
||||
format(format: string): string;
|
||||
format(format: string, options: DateTimeFormatOptions): string;
|
||||
}
|
||||
|
||||
export interface DateTimeFormatOptions {
|
||||
calendarType: CalendarType;
|
||||
numeralSystem: NumeralSystem;
|
||||
localeData: DateTimeLocaleData;
|
||||
}
|
||||
|
||||
export interface DateTimeLocaleData {
|
||||
months: () => string[];
|
||||
monthsShort: () => string[];
|
||||
weekdays: () => string[];
|
||||
weekdaysShort: () => string[];
|
||||
weekdaysMin: () => string[];
|
||||
meridiem: (hour: number, minute: number, isLower: boolean) => string;
|
||||
}
|
||||
|
||||
export type TextualYearMonth = `${number}-${number}`;
|
||||
|
||||
Reference in New Issue
Block a user