code refactor

This commit is contained in:
MaysWind
2025-06-08 21:04:55 +08:00
parent f905dcb3fd
commit 51eb8fa377
3 changed files with 16 additions and 21 deletions
+4 -4
View File
@@ -34,7 +34,7 @@ var MONTH_MAX_DAYS = []uint8{
// NewFiscalYearStart creates a new FiscalYearStart from month and day values // NewFiscalYearStart creates a new FiscalYearStart from month and day values
func NewFiscalYearStart(month uint8, day uint8) (FiscalYearStart, error) { func NewFiscalYearStart(month uint8, day uint8) (FiscalYearStart, error) {
if !isValidMonthDay(month, day) { if !isValidFiscalYearMonthDay(month, day) {
return 0, errs.ErrFormatInvalid return 0, errs.ErrFormatInvalid
} }
@@ -51,7 +51,7 @@ func (f FiscalYearStart) GetMonthDay() (uint8, uint8, error) {
month := uint8(f >> 8) month := uint8(f >> 8)
day := uint8(f & 0xFF) day := uint8(f & 0xFF)
if !isValidMonthDay(month, day) { if !isValidFiscalYearMonthDay(month, day) {
return 0, 0, errs.ErrFormatInvalid return 0, 0, errs.ErrFormatInvalid
} }
@@ -69,8 +69,8 @@ func (f FiscalYearStart) String() string {
return fmt.Sprintf("%02d-%02d", month, day) return fmt.Sprintf("%02d-%02d", month, day)
} }
// isValidMonthDay returns whether the specified month and day is valid // isValidFiscalYearMonthDay returns whether the specified month and day is valid
func isValidMonthDay(month uint8, day uint8) bool { func isValidFiscalYearMonthDay(month uint8, day uint8) bool {
return uint8(1) <= month && month <= uint8(12) && uint8(1) <= day && day <= MONTH_MAX_DAYS[int(month)-1] return uint8(1) <= month && month <= uint8(12) && uint8(1) <= day && day <= MONTH_MAX_DAYS[int(month)-1]
} }
+2 -2
View File
@@ -30,7 +30,7 @@ export class FiscalYearStart {
} }
public static of(month: number, day: number): FiscalYearStart | undefined { public static of(month: number, day: number): FiscalYearStart | undefined {
if (!FiscalYearStart.isValidMonthDay(month, day)) { if (!FiscalYearStart.isValidFiscalYearMonthDay(month, day)) {
return undefined; return undefined;
} }
@@ -79,7 +79,7 @@ export class FiscalYearStart {
return `${this.month.toString().padStart(2, '0')}-${this.day.toString().padStart(2, '0')}`; return `${this.month.toString().padStart(2, '0')}-${this.day.toString().padStart(2, '0')}`;
} }
private static isValidMonthDay(month: number, day: number): boolean { private static isValidFiscalYearMonthDay(month: number, day: number): boolean {
return 1 <= month && month <= 12 && 1 <= day && day <= FiscalYearStart.MONTH_MAX_DAYS[month - 1]; return 1 <= month && month <= 12 && 1 <= day && day <= FiscalYearStart.MONTH_MAX_DAYS[month - 1];
} }
} }
+10 -15
View File
@@ -641,10 +641,6 @@ export function useI18n() {
return t('default.firstDayOfWeek'); return t('default.firstDayOfWeek');
} }
function getDefaultFiscalYearFormat(): string {
return t('default.fiscalYearFormat');
}
function getAllLanguageOptions(includeSystemDefault: boolean): LanguageOption[] { function getAllLanguageOptions(includeSystemDefault: boolean): LanguageOption[] {
const ret: LanguageOption[] = []; const ret: LanguageOption[] = [];
@@ -944,27 +940,27 @@ export function useI18n() {
} }
const currentFiscalYearRange = getFiscalYearTimeRangeFromUnixTime(now, fiscalYearStart); const currentFiscalYearRange = getFiscalYearTimeRangeFromUnixTime(now, fiscalYearStart);
const ret: TypeAndDisplayName[] = []; let defaultFiscalYearFormat = FiscalYearFormat.parse(t('default.fiscalYearFormat'));
let fiscalYearFormat = FiscalYearFormat.parse(getDefaultFiscalYearFormat()); if (!defaultFiscalYearFormat) {
defaultFiscalYearFormat = FiscalYearFormat.Default;
if (!fiscalYearFormat) {
fiscalYearFormat = FiscalYearFormat.Default;
} }
const ret: TypeAndDisplayName[] = [];
ret.push({ ret.push({
type: LANGUAGE_DEFAULT_FISCAL_YEAR_FORMAT_VALUE, type: LANGUAGE_DEFAULT_FISCAL_YEAR_FORMAT_VALUE,
displayName: `${t('Language Default')} (${formatTimeRangeToFiscalYearFormat(fiscalYearFormat, currentFiscalYearRange)})` displayName: `${t('Language Default')} (${formatTimeRangeToFiscalYearFormat(defaultFiscalYearFormat, currentFiscalYearRange)})`
}); });
const allFiscalYearFormats = FiscalYearFormat.values(); const allFiscalYearFormats = FiscalYearFormat.values();
for (let i = 0; i < allFiscalYearFormats.length; i++) { for (let i = 0; i < allFiscalYearFormats.length; i++) {
const format = allFiscalYearFormats[i]; const fiscalYearFormat = allFiscalYearFormats[i];
ret.push({ ret.push({
type: format.type, type: fiscalYearFormat.type,
displayName: formatTimeRangeToFiscalYearFormat(format, currentFiscalYearRange), displayName: formatTimeRangeToFiscalYearFormat(fiscalYearFormat, currentFiscalYearRange),
}); });
} }
@@ -1371,7 +1367,7 @@ export function useI18n() {
let fiscalYearFormat = FiscalYearFormat.valueOf(userStore.currentUserFiscalYearFormat); let fiscalYearFormat = FiscalYearFormat.valueOf(userStore.currentUserFiscalYearFormat);
if (!fiscalYearFormat) { if (!fiscalYearFormat) {
const defaultFiscalYearFormatTypeName = getDefaultFiscalYearFormat(); const defaultFiscalYearFormatTypeName = t('default.fiscalYearFormat');
fiscalYearFormat = FiscalYearFormat.parse(defaultFiscalYearFormatTypeName); fiscalYearFormat = FiscalYearFormat.parse(defaultFiscalYearFormatTypeName);
if (!fiscalYearFormat) { if (!fiscalYearFormat) {
@@ -1815,7 +1811,6 @@ export function useI18n() {
// get localization default type // get localization default type
getDefaultCurrency, getDefaultCurrency,
getDefaultFirstDayOfWeek, getDefaultFirstDayOfWeek,
getDefaultFiscalYearFormat,
// get all localized info of specified type // get all localized info of specified type
getAllLanguageOptions, getAllLanguageOptions,
getAllEnableDisableOptions, getAllEnableDisableOptions,