code refactor
This commit is contained in:
@@ -34,7 +34,7 @@ var MONTH_MAX_DAYS = []uint8{
|
||||
|
||||
// NewFiscalYearStart creates a new FiscalYearStart from month and day values
|
||||
func NewFiscalYearStart(month uint8, day uint8) (FiscalYearStart, error) {
|
||||
if !isValidMonthDay(month, day) {
|
||||
if !isValidFiscalYearMonthDay(month, day) {
|
||||
return 0, errs.ErrFormatInvalid
|
||||
}
|
||||
|
||||
@@ -51,7 +51,7 @@ func (f FiscalYearStart) GetMonthDay() (uint8, uint8, error) {
|
||||
month := uint8(f >> 8)
|
||||
day := uint8(f & 0xFF)
|
||||
|
||||
if !isValidMonthDay(month, day) {
|
||||
if !isValidFiscalYearMonthDay(month, day) {
|
||||
return 0, 0, errs.ErrFormatInvalid
|
||||
}
|
||||
|
||||
@@ -69,8 +69,8 @@ func (f FiscalYearStart) String() string {
|
||||
return fmt.Sprintf("%02d-%02d", month, day)
|
||||
}
|
||||
|
||||
// isValidMonthDay returns whether the specified month and day is valid
|
||||
func isValidMonthDay(month uint8, day uint8) bool {
|
||||
// isValidFiscalYearMonthDay returns whether the specified month and day is valid
|
||||
func isValidFiscalYearMonthDay(month uint8, day uint8) bool {
|
||||
return uint8(1) <= month && month <= uint8(12) && uint8(1) <= day && day <= MONTH_MAX_DAYS[int(month)-1]
|
||||
}
|
||||
|
||||
|
||||
@@ -30,7 +30,7 @@ export class FiscalYearStart {
|
||||
}
|
||||
|
||||
public static of(month: number, day: number): FiscalYearStart | undefined {
|
||||
if (!FiscalYearStart.isValidMonthDay(month, day)) {
|
||||
if (!FiscalYearStart.isValidFiscalYearMonthDay(month, day)) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
@@ -79,7 +79,7 @@ export class FiscalYearStart {
|
||||
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];
|
||||
}
|
||||
}
|
||||
|
||||
+10
-15
@@ -641,10 +641,6 @@ export function useI18n() {
|
||||
return t('default.firstDayOfWeek');
|
||||
}
|
||||
|
||||
function getDefaultFiscalYearFormat(): string {
|
||||
return t('default.fiscalYearFormat');
|
||||
}
|
||||
|
||||
function getAllLanguageOptions(includeSystemDefault: boolean): LanguageOption[] {
|
||||
const ret: LanguageOption[] = [];
|
||||
|
||||
@@ -944,27 +940,27 @@ export function useI18n() {
|
||||
}
|
||||
|
||||
const currentFiscalYearRange = getFiscalYearTimeRangeFromUnixTime(now, fiscalYearStart);
|
||||
const ret: TypeAndDisplayName[] = [];
|
||||
let defaultFiscalYearFormat = FiscalYearFormat.parse(t('default.fiscalYearFormat'));
|
||||
|
||||
let fiscalYearFormat = FiscalYearFormat.parse(getDefaultFiscalYearFormat());
|
||||
|
||||
if (!fiscalYearFormat) {
|
||||
fiscalYearFormat = FiscalYearFormat.Default;
|
||||
if (!defaultFiscalYearFormat) {
|
||||
defaultFiscalYearFormat = FiscalYearFormat.Default;
|
||||
}
|
||||
|
||||
const ret: TypeAndDisplayName[] = [];
|
||||
|
||||
ret.push({
|
||||
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();
|
||||
|
||||
for (let i = 0; i < allFiscalYearFormats.length; i++) {
|
||||
const format = allFiscalYearFormats[i];
|
||||
const fiscalYearFormat = allFiscalYearFormats[i];
|
||||
|
||||
ret.push({
|
||||
type: format.type,
|
||||
displayName: formatTimeRangeToFiscalYearFormat(format, currentFiscalYearRange),
|
||||
type: fiscalYearFormat.type,
|
||||
displayName: formatTimeRangeToFiscalYearFormat(fiscalYearFormat, currentFiscalYearRange),
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1371,7 +1367,7 @@ export function useI18n() {
|
||||
let fiscalYearFormat = FiscalYearFormat.valueOf(userStore.currentUserFiscalYearFormat);
|
||||
|
||||
if (!fiscalYearFormat) {
|
||||
const defaultFiscalYearFormatTypeName = getDefaultFiscalYearFormat();
|
||||
const defaultFiscalYearFormatTypeName = t('default.fiscalYearFormat');
|
||||
fiscalYearFormat = FiscalYearFormat.parse(defaultFiscalYearFormatTypeName);
|
||||
|
||||
if (!fiscalYearFormat) {
|
||||
@@ -1815,7 +1811,6 @@ export function useI18n() {
|
||||
// get localization default type
|
||||
getDefaultCurrency,
|
||||
getDefaultFirstDayOfWeek,
|
||||
getDefaultFiscalYearFormat,
|
||||
// get all localized info of specified type
|
||||
getAllLanguageOptions,
|
||||
getAllEnableDisableOptions,
|
||||
|
||||
Reference in New Issue
Block a user