migrate consts/datetime.js to ts

This commit is contained in:
MaysWind
2025-01-02 00:31:28 +08:00
parent 5525635df1
commit ad9a390b58
22 changed files with 633 additions and 665 deletions
@@ -59,7 +59,7 @@ import { useTheme } from 'vuetify';
import { mapStores } from 'pinia';
import { useUserStore } from '@/stores/user.js';
import datetimeConstants from '@/consts/datetime.js';
import { DateRange } from '@/core/datetime.ts';
import { ThemeType } from '@/core/theme.ts';
import { arrangeArrayWithNewStartIndex } from '@/lib/common.ts';
import {
@@ -149,12 +149,12 @@ export default {
const presetRanges = [];
[
datetimeConstants.allDateRanges.Today,
datetimeConstants.allDateRanges.LastSevenDays,
datetimeConstants.allDateRanges.LastThirtyDays,
datetimeConstants.allDateRanges.ThisWeek,
datetimeConstants.allDateRanges.ThisMonth,
datetimeConstants.allDateRanges.ThisYear
DateRange.Today,
DateRange.LastSevenDays,
DateRange.LastThirtyDays,
DateRange.ThisWeek,
DateRange.ThisMonth,
DateRange.ThisYear
].forEach(dateRangeType => {
const dateRange = getDateRangeByDateType(dateRangeType.type, this.firstDayOfWeek);
+4 -4
View File
@@ -10,10 +10,10 @@ import { mapStores } from 'pinia';
import { useSettingsStore } from '@/stores/setting.js';
import { useUserStore } from '@/stores/user.js';
import { DEFAULT_ICON_COLOR, DEFAULT_CHART_COLORS } from '@/consts/color.ts';
import datetimeConstants from '@/consts/datetime.js';
import statisticsConstants from '@/consts/statistics.js';
import { DateRangeScene } from '@/core/datetime.ts';
import { ThemeType } from '@/core/theme.ts';
import { DEFAULT_ICON_COLOR, DEFAULT_CHART_COLORS } from '@/consts/color.ts';
import statisticsConstants from '@/consts/statistics.js';
import {
isArray,
isNumber
@@ -376,7 +376,7 @@ export default {
}
}
const dateRangeType = getDateTypeByDateRange(minUnixTime, maxUnixTime, this.userStore.currentUserFirstDayOfWeek, datetimeConstants.allDateRangeScenes.Normal);
const dateRangeType = getDateTypeByDateRange(minUnixTime, maxUnixTime, this.userStore.currentUserFirstDayOfWeek, DateRangeScene.Normal);
this.$emit('click', {
itemId: itemId,
@@ -56,7 +56,7 @@
import { mapStores } from 'pinia';
import { useUserStore } from '@/stores/user.js';
import datetimeConstants from '@/consts/datetime.js';
import { DateRange } from '@/core/datetime.ts';
import { arrangeArrayWithNewStartIndex } from '@/lib/common.ts';
import {
getCurrentUnixTime,
@@ -136,12 +136,12 @@ export default {
const presetRanges = [];
[
datetimeConstants.allDateRanges.Today,
datetimeConstants.allDateRanges.LastSevenDays,
datetimeConstants.allDateRanges.LastThirtyDays,
datetimeConstants.allDateRanges.ThisWeek,
datetimeConstants.allDateRanges.ThisMonth,
datetimeConstants.allDateRanges.ThisYear
DateRange.Today,
DateRange.LastSevenDays,
DateRange.LastThirtyDays,
DateRange.ThisWeek,
DateRange.ThisMonth,
DateRange.ThisYear
].forEach(dateRangeType => {
const dateRange = getDateRangeByDateType(dateRangeType.type, this.firstDayOfWeek);
@@ -52,7 +52,6 @@
import { mapStores } from 'pinia';
import { useUserStore } from '@/stores/user.js';
import datetimeConstants from '@/consts/datetime.js';
import { arrangeArrayWithNewStartIndex } from '@/lib/common.ts';
import {
getCurrentUnixTime,
@@ -202,19 +201,15 @@ export default {
return getTimeValues(datetime, this.is24Hour, this.isMeridiemIndicatorFirst);
},
getTimePickerColumns() {
const self = this;
const ret = [];
if (!self.is24Hour && this.isMeridiemIndicatorFirst) {
ret.push({
values: datetimeConstants.allMeridiemIndicatorsArray,
displayValues: self.$locale.getAllMeridiemIndicatorNames()
});
if (!this.is24Hour && this.isMeridiemIndicatorFirst) {
ret.push(this.$locale.getAllMeridiemIndicators());
}
// Hours
ret.push({
values: self.generateAllHours()
values: this.generateAllHours()
});
// Divider
ret.push({
@@ -223,7 +218,7 @@ export default {
});
// Minutes
ret.push({
values: self.generateAllMinutesOrSeconds()
values: this.generateAllMinutesOrSeconds()
});
// Divider
ret.push({
@@ -232,14 +227,11 @@ export default {
});
// Seconds
ret.push({
values: self.generateAllMinutesOrSeconds()
values: this.generateAllMinutesOrSeconds()
});
if (!self.is24Hour && !this.isMeridiemIndicatorFirst) {
ret.push({
values: datetimeConstants.allMeridiemIndicatorsArray,
displayValues: self.$locale.getAllMeridiemIndicatorNames()
});
if (!this.is24Hour && !this.isMeridiemIndicatorFirst) {
ret.push(this.$locale.getAllMeridiemIndicators());
}
return ret;
+2 -2
View File
@@ -93,8 +93,8 @@ import { mapStores } from 'pinia';
import { useSettingsStore } from '@/stores/setting.js';
import { useUserStore } from '@/stores/user.js';
import { DateRangeScene } from '@/core/datetime.ts';
import { DEFAULT_ICON_COLOR, DEFAULT_CHART_COLORS } from '@/consts/color.ts';
import datetimeConstants from '@/consts/datetime.js';
import statisticsConstants from '@/consts/statistics.js';
import { isNumber } from '@/lib/common.ts';
import {
@@ -303,7 +303,7 @@ export default {
}
}
const dateRangeType = getDateTypeByDateRange(minUnixTime, maxUnixTime, this.userStore.currentUserFirstDayOfWeek, datetimeConstants.allDateRangeScenes.Normal);
const dateRangeType = getDateTypeByDateRange(minUnixTime, maxUnixTime, this.userStore.currentUserFirstDayOfWeek, DateRangeScene.Normal);
this.$emit('click', {
itemId: itemId,
-381
View File
@@ -1,381 +0,0 @@
const allMeridiemIndicators = {
AM: 'AM',
PM: 'PM'
};
const allMeridiemIndicatorsArray = [
allMeridiemIndicators.AM,
allMeridiemIndicators.PM
];
const allMonthsArray = [
'January',
'February',
'March',
'April',
'May',
'June',
'July',
'August',
'September',
'October',
'November',
'December'
];
const allWeekDays = {
Sunday: {
type: 0,
name: 'Sunday'
},
Monday: {
type: 1,
name: 'Monday'
},
Tuesday: {
type: 2,
name: 'Tuesday'
},
Wednesday: {
type: 3,
name: 'Wednesday'
},
Thursday: {
type: 4,
name: 'Thursday'
},
Friday: {
type: 5,
name: 'Friday'
},
Saturday: {
type: 6,
name: 'Saturday'
}
};
const allWeekDaysArray = [
allWeekDays.Sunday,
allWeekDays.Monday,
allWeekDays.Tuesday,
allWeekDays.Wednesday,
allWeekDays.Thursday,
allWeekDays.Friday,
allWeekDays.Saturday
];
const allLongDateFormat = {
YYYYMMDD: {
type: 1,
key: 'yyyy_mm_dd',
isMonthAfterYear: true
},
MMDDYYYY: {
type: 2,
key: 'mm_dd_yyyy',
isMonthAfterYear: false
},
DDMMYYYY: {
type: 3,
key: 'dd_mm_yyyy',
isMonthAfterYear: false
}
};
const allLongDateFormatArray = [
allLongDateFormat.YYYYMMDD,
allLongDateFormat.MMDDYYYY,
allLongDateFormat.DDMMYYYY
];
const allShortDateFormat = {
YYYYMMDD: {
type: 1,
key: 'yyyy_mm_dd',
isMonthAfterYear: true
},
MMDDYYYY: {
type: 2,
key: 'mm_dd_yyyy',
isMonthAfterYear: false
},
DDMMYYYY: {
type: 3,
key: 'dd_mm_yyyy',
isMonthAfterYear: false
}
};
const allShortDateFormatArray = [
allShortDateFormat.YYYYMMDD,
allShortDateFormat.MMDDYYYY,
allShortDateFormat.DDMMYYYY
];
const allLongTimeFormat = {
HHMMSS: {
type: 1,
key: 'hh_mm_ss',
is24HourFormat: true,
isMeridiemIndicatorFirst: null
},
AHHMMSS: {
type: 2,
key: 'a_hh_mm_ss',
is24HourFormat: false,
isMeridiemIndicatorFirst: true
},
HHMMSSA: {
type: 3,
key: 'hh_mm_ss_a',
is24HourFormat: false,
isMeridiemIndicatorFirst: false
}
};
const allLongTimeFormatArray = [
allLongTimeFormat.HHMMSS,
allLongTimeFormat.AHHMMSS,
allLongTimeFormat.HHMMSSA
];
const allShortTimeFormat = {
HHMM: {
type: 1,
key: 'hh_mm',
is24HourFormat: true,
isMeridiemIndicatorFirst: null
},
AHHMM: {
type: 2,
key: 'a_hh_mm',
is24HourFormat: false,
isMeridiemIndicatorFirst: true
},
HHMMA: {
type: 3,
key: 'hh_mm_a',
is24HourFormat: false,
isMeridiemIndicatorFirst: false
}
};
const allShortTimeFormatArray = [
allShortTimeFormat.HHMM,
allShortTimeFormat.AHHMM,
allShortTimeFormat.HHMMA
];
const allDateRangeScenes = {
Normal: 0,
TrendAnalysis: 1
};
const allDateRanges = {
All: {
type: 0,
name: 'All',
availableScenes: {
[allDateRangeScenes.Normal]: true,
[allDateRangeScenes.TrendAnalysis]: true
}
},
Today: {
type: 1,
name: 'Today',
availableScenes: {
[allDateRangeScenes.Normal]: true
}
},
Yesterday: {
type: 2,
name: 'Yesterday',
availableScenes: {
[allDateRangeScenes.Normal]: true
}
},
LastSevenDays: {
type: 3,
name: 'Recent 7 days',
availableScenes: {
[allDateRangeScenes.Normal]: true
}
},
LastThirtyDays: {
type: 4,
name: 'Recent 30 days',
availableScenes: {
[allDateRangeScenes.Normal]: true
}
},
ThisWeek: {
type: 5,
name: 'This week',
availableScenes: {
[allDateRangeScenes.Normal]: true
}
},
LastWeek: {
type: 6,
name: 'Last week',
availableScenes: {
[allDateRangeScenes.Normal]: true
}
},
ThisMonth: {
type: 7,
name: 'This month',
availableScenes: {
[allDateRangeScenes.Normal]: true
}
},
LastMonth: {
type: 8,
name: 'Last month',
availableScenes: {
[allDateRangeScenes.Normal]: true
}
},
ThisYear: {
type: 9,
name: 'This year',
availableScenes: {
[allDateRangeScenes.Normal]: true,
[allDateRangeScenes.TrendAnalysis]: true
}
},
LastYear: {
type: 10,
name: 'Last year',
availableScenes: {
[allDateRangeScenes.Normal]: true,
[allDateRangeScenes.TrendAnalysis]: true
}
},
PreviousBillingCycle: {
type: 51,
name: 'Previous Billing Cycle',
isBillingCycle: true,
availableScenes: {
[allDateRangeScenes.Normal]: true
}
},
CurrentBillingCycle: {
type: 52,
name: 'Current Billing Cycle',
isBillingCycle: true,
availableScenes: {
[allDateRangeScenes.Normal]: true
}
},
RecentTwelveMonths: {
type: 101,
name: 'Recent 12 months',
availableScenes: {
[allDateRangeScenes.TrendAnalysis]: true
}
},
RecentTwentyFourMonths: {
type: 102,
name: 'Recent 24 months',
availableScenes: {
[allDateRangeScenes.TrendAnalysis]: true
}
},
RecentThirtySixMonths: {
type: 103,
name: 'Recent 36 months',
availableScenes: {
[allDateRangeScenes.TrendAnalysis]: true
}
},
RecentTwoYears: {
type: 104,
name: 'Recent 2 years',
availableScenes: {
[allDateRangeScenes.TrendAnalysis]: true
}
},
RecentThreeYears: {
type: 105,
name: 'Recent 3 years',
availableScenes: {
[allDateRangeScenes.TrendAnalysis]: true
}
},
RecentFiveYears: {
type: 106,
name: 'Recent 5 years',
availableScenes: {
[allDateRangeScenes.TrendAnalysis]: true
}
},
Custom: {
type: 255,
name: 'Custom Date',
availableScenes: {
[allDateRangeScenes.Normal]: true,
[allDateRangeScenes.TrendAnalysis]: true
}
}
};
const allDateRangesMap = {
[allDateRanges.All.type]: allDateRanges.All,
[allDateRanges.Today.type]: allDateRanges.Today,
[allDateRanges.Yesterday.type]: allDateRanges.Yesterday,
[allDateRanges.LastSevenDays.type]: allDateRanges.LastSevenDays,
[allDateRanges.LastThirtyDays.type]: allDateRanges.LastThirtyDays,
[allDateRanges.ThisWeek.type]: allDateRanges.ThisWeek,
[allDateRanges.LastWeek.type]: allDateRanges.LastWeek,
[allDateRanges.ThisMonth.type]: allDateRanges.ThisMonth,
[allDateRanges.LastMonth.type]: allDateRanges.LastMonth,
[allDateRanges.ThisYear.type]: allDateRanges.ThisYear,
[allDateRanges.LastYear.type]: allDateRanges.LastYear,
[allDateRanges.PreviousBillingCycle.type]: allDateRanges.PreviousBillingCycle,
[allDateRanges.CurrentBillingCycle.type]: allDateRanges.CurrentBillingCycle,
[allDateRanges.RecentTwentyFourMonths.type]: allDateRanges.RecentTwentyFourMonths,
[allDateRanges.RecentThirtySixMonths.type]: allDateRanges.RecentThirtySixMonths,
[allDateRanges.RecentTwoYears.type]: allDateRanges.RecentTwoYears,
[allDateRanges.RecentThreeYears.type]: allDateRanges.RecentThreeYears,
[allDateRanges.RecentFiveYears.type]: allDateRanges.RecentFiveYears,
[allDateRanges.Custom.type]: allDateRanges.Custom
};
const allBillingCycleDateRangesMap = {
[allDateRanges.PreviousBillingCycle.type]: allDateRanges.PreviousBillingCycle,
[allDateRanges.CurrentBillingCycle.type]: allDateRanges.CurrentBillingCycle
};
const defaultFirstDayOfWeek = allWeekDays.Sunday.type;
const defaultLongDateFormat = allLongDateFormat.YYYYMMDD;
const defaultShortDateFormat = allShortDateFormat.YYYYMMDD;
const defaultLongTimeFormat = allLongTimeFormat.HHMMSS;
const defaultShortTimeFormat = allShortTimeFormat.HHMM;
const defaultDateTimeFormatValue = 0;
export default {
allMeridiemIndicators: allMeridiemIndicators,
allMeridiemIndicatorsArray: allMeridiemIndicatorsArray,
allWeekDays: allWeekDays,
allWeekDaysArray: allWeekDaysArray,
allMonthsArray: allMonthsArray,
allLongDateFormat: allLongDateFormat,
allLongDateFormatArray: allLongDateFormatArray,
allShortDateFormat: allShortDateFormat,
allShortDateFormatArray: allShortDateFormatArray,
allLongTimeFormat: allLongTimeFormat,
allLongTimeFormatArray: allLongTimeFormatArray,
allShortTimeFormat: allShortTimeFormat,
allShortTimeFormatArray: allShortTimeFormatArray,
allDateRangeScenes: allDateRangeScenes,
allDateRanges: allDateRanges,
allDateRangesMap: allDateRangesMap,
allBillingCycleDateRangesMap: allBillingCycleDateRangesMap,
defaultFirstDayOfWeek: defaultFirstDayOfWeek,
defaultLongDateFormat: defaultLongDateFormat,
defaultShortDateFormat: defaultShortDateFormat,
defaultLongTimeFormat: defaultLongTimeFormat,
defaultShortTimeFormat: defaultShortTimeFormat,
defaultDateTimeFormatValue: defaultDateTimeFormatValue,
};
+3 -3
View File
@@ -1,4 +1,4 @@
import datetime from './datetime.js';
import { DateRange } from '@/core/datetime.ts';
const allAnalysisTypes = {
CategoricalAnalysis: 0,
@@ -203,8 +203,8 @@ export default {
allChartDataTypes: allChartDataTypes,
allChartDataTypesMap: allChartDataTypesMap,
defaultChartDataType: defaultChartDataType,
defaultCategoricalChartDataRangeType: datetime.allDateRanges.ThisMonth.type,
defaultTrendChartDataRangeType: datetime.allDateRanges.ThisYear.type,
defaultCategoricalChartDataRangeType: DateRange.ThisMonth.type,
defaultTrendChartDataRangeType: DateRange.ThisYear.type,
allSortingTypes: allSortingTypes,
allSortingTypesArray: allSortingTypesArray,
defaultSortingType: defaultSortingType,
+365 -3
View File
@@ -1,3 +1,78 @@
import type { TypeAndName } from '@/core/base.ts';
export class Month {
private static readonly allInstances: Month[] = [];
public static readonly January = new Month(1, 'January');
public static readonly February = new Month(2, 'February');
public static readonly March = new Month(3, 'March');
public static readonly April = new Month(4, 'April');
public static readonly May = new Month(5, 'May');
public static readonly June = new Month(6, 'June');
public static readonly July = new Month(7, 'July');
public static readonly August = new Month(8, 'August');
public static readonly September = new Month(9, 'September');
public static readonly October = new Month(10, 'October');
public static readonly November = new Month(11, 'November');
public static readonly December = new Month(12, 'December');
public readonly month: number;
public readonly name: string;
private constructor(month: number, name: string) {
this.month = month;
this.name = name;
Month.allInstances.push(this);
}
public static values(): Month[] {
return Month.allInstances;
}
public static valueOf(month: number): Month {
return Month.allInstances[month - 1];
}
}
export class WeekDay implements TypeAndName {
private static readonly allInstances: WeekDay[] = [];
private static readonly allInstancesByName: Record<string, WeekDay> = {};
public static readonly Sunday = new WeekDay(0, 'Sunday');
public static readonly Monday = new WeekDay(1, 'Monday');
public static readonly Tuesday = new WeekDay(2, 'Tuesday');
public static readonly Wednesday = new WeekDay(3, 'Wednesday');
public static readonly Thursday = new WeekDay(4, 'Thursday');
public static readonly Friday = new WeekDay(5, 'Friday');
public static readonly Saturday = new WeekDay(6, 'Saturday');
public static readonly DefaultFirstDay = WeekDay.Sunday;
public readonly type: number;
public readonly name: string;
private constructor(type: number, name: string) {
this.type = type;
this.name = name;
WeekDay.allInstances.push(this);
WeekDay.allInstancesByName[name] = this;
}
public static values(): WeekDay[] {
return WeekDay.allInstances;
}
public static valueOf(dayOfWeek: number): WeekDay {
return WeekDay.allInstances[dayOfWeek];
}
public static parse(typeName: string): WeekDay {
return WeekDay.allInstancesByName[typeName];
}
}
export class MeridiemIndicator {
private static readonly allInstances: MeridiemIndicator[] = [];
@@ -5,11 +80,11 @@ export class MeridiemIndicator {
public static readonly PM = new MeridiemIndicator(1, 'PM');
public readonly type: number;
public readonly value: string;
public readonly name: string;
private constructor(type: number, value: string) {
private constructor(type: number, name: string) {
this.type = type;
this.value = value;
this.name = name;
MeridiemIndicator.allInstances.push(this);
}
@@ -18,3 +93,290 @@ export class MeridiemIndicator {
return MeridiemIndicator.allInstances;
}
}
export const LANGUAGE_DEFAULT_DATE_TIME_FORMAT_VALUE: number = 0;
export interface DateFormat {
readonly type: number;
readonly key: string;
readonly isMonthAfterYear: boolean;
}
type DateFormatTypeName = 'YYYYMMDD' | 'MMDDYYYY' | 'DDMMYYYY';
export class LongDateFormat implements DateFormat {
private static readonly allInstances: LongDateFormat[] = [];
private static readonly allInstancesByType: Record<number, LongDateFormat> = {};
private static readonly allInstancesByTypeName: Record<string, LongDateFormat> = {};
public static readonly YYYYMMDD = new LongDateFormat(1, 'YYYYMMDD', 'yyyy_mm_dd', true);
public static readonly MMDDYYYY = new LongDateFormat(2, 'MMDDYYYY', 'mm_dd_yyyy', false);
public static readonly DDMMYYYY = new LongDateFormat(3, 'DDMMYYYY', 'dd_mm_yyyy', false);
public static readonly Default = LongDateFormat.YYYYMMDD;
public readonly type: number;
public readonly typeName: string;
public readonly key: string;
public readonly isMonthAfterYear: boolean;
private constructor(type: number, typeName: DateFormatTypeName, key: string, isMonthAfterYear: boolean) {
this.type = type;
this.typeName = typeName;
this.key = key;
this.isMonthAfterYear = isMonthAfterYear;
LongDateFormat.allInstances.push(this);
LongDateFormat.allInstancesByType[type] = this;
LongDateFormat.allInstancesByTypeName[typeName] = this;
}
public static values(): LongDateFormat[] {
return LongDateFormat.allInstances;
}
public static all(): Record<DateFormatTypeName, LongDateFormat> {
return LongDateFormat.allInstancesByTypeName;
}
public static valueOf(type: number): LongDateFormat {
return LongDateFormat.allInstancesByType[type];
}
}
export class ShortDateFormat implements DateFormat {
private static readonly allInstances: ShortDateFormat[] = [];
private static readonly allInstancesByType: Record<number, ShortDateFormat> = {};
private static readonly allInstancesByTypeName: Record<string, ShortDateFormat> = {};
public static readonly YYYYMMDD = new ShortDateFormat(1, 'YYYYMMDD', 'yyyy_mm_dd', true);
public static readonly MMDDYYYY = new ShortDateFormat(2, 'MMDDYYYY', 'mm_dd_yyyy', false);
public static readonly DDMMYYYY = new ShortDateFormat(3, 'DDMMYYYY', 'dd_mm_yyyy', false);
public static readonly Default = ShortDateFormat.YYYYMMDD;
public readonly type: number;
public readonly typeName: string;
public readonly key: string;
public readonly isMonthAfterYear: boolean;
private constructor(type: number, typeName: DateFormatTypeName, key: string, isMonthAfterYear: boolean) {
this.type = type;
this.typeName = typeName;
this.key = key;
this.isMonthAfterYear = isMonthAfterYear;
ShortDateFormat.allInstances.push(this);
ShortDateFormat.allInstancesByType[type] = this;
ShortDateFormat.allInstancesByTypeName[typeName] = this;
}
public static values(): ShortDateFormat[] {
return ShortDateFormat.allInstances;
}
public static all(): Record<DateFormatTypeName, ShortDateFormat> {
return ShortDateFormat.allInstancesByTypeName;
}
public static valueOf(type: number): ShortDateFormat {
return ShortDateFormat.allInstancesByType[type];
}
}
export interface TimeFormat {
readonly type: number;
readonly key: string;
readonly is24HourFormat: boolean;
readonly isMeridiemIndicatorFirst: boolean | null;
}
export type LongTimeFormatTypeName = 'HHMMSS' | 'AHHMMSS' | 'HHMMSSA';
export class LongTimeFormat implements TimeFormat {
private static readonly allInstances: LongTimeFormat[] = [];
private static readonly allInstancesByType: Record<number, LongTimeFormat> = {};
private static readonly allInstancesByTypeName: Record<string, LongTimeFormat> = {};
public static readonly HHMMSS = new LongTimeFormat(1, 'HHMMSS', 'hh_mm_ss', true, null);
public static readonly AHHMMSS = new LongTimeFormat(2, 'AHHMMSS', 'a_hh_mm_ss', false, true);
public static readonly HHMMSSA = new LongTimeFormat(3, 'HHMMSSA', 'hh_mm_ss_a', false, false);
public static readonly Default = LongTimeFormat.HHMMSS;
public readonly type: number;
public readonly typeName: string;
public readonly key: string;
public readonly is24HourFormat: boolean;
public readonly isMeridiemIndicatorFirst: boolean | null;
private constructor(type: number, typeName: LongTimeFormatTypeName, key: string, is24HourFormat: boolean, isMeridiemIndicatorFirst: boolean | null) {
this.type = type;
this.typeName = typeName;
this.key = key;
this.is24HourFormat = is24HourFormat;
this.isMeridiemIndicatorFirst = isMeridiemIndicatorFirst;
LongTimeFormat.allInstances.push(this);
LongTimeFormat.allInstancesByType[type] = this;
LongTimeFormat.allInstancesByTypeName[typeName] = this;
}
public static values(): LongTimeFormat[] {
return LongTimeFormat.allInstances;
}
public static all(): Record<LongTimeFormatTypeName, LongTimeFormat> {
return LongTimeFormat.allInstancesByTypeName;
}
public static valueOf(type: number): LongTimeFormat {
return LongTimeFormat.allInstancesByType[type];
}
}
export type ShortTimeFormatTypeName = 'HHMM' | 'AHHMM' | 'HHMMA';
export class ShortTimeFormat implements TimeFormat {
private static readonly allInstances: ShortTimeFormat[] = [];
private static readonly allInstancesByType: Record<number, ShortTimeFormat> = {};
private static readonly allInstancesByTypeName: Record<string, ShortTimeFormat> = {};
public static readonly HHMM = new ShortTimeFormat(1, 'HHMM', 'hh_mm', true, null);
public static readonly AHHMM = new ShortTimeFormat(2, 'AHHMM', 'a_hh_mm', false, true);
public static readonly HHMMA = new ShortTimeFormat(3, 'HHMMA', 'hh_mm_a', false, false);
public static readonly Default = ShortTimeFormat.HHMM;
public readonly type: number;
public readonly typeName: string;
public readonly key: string;
public readonly is24HourFormat: boolean;
public readonly isMeridiemIndicatorFirst: boolean | null;
private constructor(type: number, typeName: ShortTimeFormatTypeName, key: string, is24HourFormat: boolean, isMeridiemIndicatorFirst: boolean | null) {
this.type = type;
this.typeName = typeName;
this.key = key;
this.is24HourFormat = is24HourFormat;
this.isMeridiemIndicatorFirst = isMeridiemIndicatorFirst;
ShortTimeFormat.allInstances.push(this);
ShortTimeFormat.allInstancesByType[type] = this;
ShortTimeFormat.allInstancesByTypeName[typeName] = this;
}
public static values(): ShortTimeFormat[] {
return ShortTimeFormat.allInstances;
}
public static all(): Record<ShortTimeFormatTypeName, ShortTimeFormat> {
return ShortTimeFormat.allInstancesByTypeName;
}
public static valueOf(type: number): ShortTimeFormat {
return ShortTimeFormat.allInstancesByType[type];
}
}
export enum DateRangeScene {
Normal = 0,
TrendAnalysis = 1
}
export type DateRangeTypeName = 'All' |
'Today' | 'Yesterday' |
'LastSevenDays' | 'LastThirtyDays' |
'ThisWeek' | 'LastWeek' |
'ThisMonth' | 'LastMonth' |
'ThisYear' | 'LastYear' |
'PreviousBillingCycle' | 'CurrentBillingCycle' |
'RecentTwelveMonths' | 'RecentTwentyFourMonths' | 'RecentThirtySixMonths' |
'RecentTwoYears' | 'RecentThreeYears' | 'RecentFiveYears' |
'Custom';
export class DateRange implements TypeAndName {
private static readonly allInstances: DateRange[] = [];
private static readonly allInstancesByType: Record<number, DateRange> = {};
private static readonly allInstancesByTypeName: Record<string, DateRange> = {};
// All date range
public static readonly All = new DateRange(0, 'All', 'All', false, DateRangeScene.Normal, DateRangeScene.TrendAnalysis);
// Date ranges for normal scene only
public static readonly Today = new DateRange(1, 'Today', 'Today', false, DateRangeScene.Normal);
public static readonly Yesterday = new DateRange(2, 'Yesterday', 'Yesterday', false, DateRangeScene.Normal);
public static readonly LastSevenDays = new DateRange(3, 'LastSevenDays', 'Recent 7 days', false, DateRangeScene.Normal);
public static readonly LastThirtyDays = new DateRange(4, 'LastThirtyDays', 'Recent 30 days', false, DateRangeScene.Normal);
public static readonly ThisWeek = new DateRange(5, 'ThisWeek', 'This week', false, DateRangeScene.Normal);
public static readonly LastWeek = new DateRange(6, 'LastWeek', 'Last week', false, DateRangeScene.Normal);
public static readonly ThisMonth = new DateRange(7, 'ThisMonth', 'This month', false, DateRangeScene.Normal);
public static readonly LastMonth = new DateRange(8, 'LastMonth', 'Last month', false, DateRangeScene.Normal);
// Date ranges for normal and trend analysis scene
public static readonly ThisYear = new DateRange(9, 'ThisYear', 'This year', false, DateRangeScene.Normal, DateRangeScene.TrendAnalysis);
public static readonly LastYear = new DateRange(10, 'LastYear', 'Last year', false, DateRangeScene.Normal, DateRangeScene.TrendAnalysis);
// Billing cycle date ranges for normal scene only
public static readonly PreviousBillingCycle = new DateRange(51, 'PreviousBillingCycle', 'Previous Billing Cycle', true, DateRangeScene.Normal);
public static readonly CurrentBillingCycle = new DateRange(52, 'CurrentBillingCycle', 'Current Billing Cycle', true, DateRangeScene.Normal);
// Date ranges for trend analysis scene only
public static readonly RecentTwelveMonths = new DateRange(101, 'RecentTwelveMonths', 'Recent 12 months', false, DateRangeScene.TrendAnalysis);
public static readonly RecentTwentyFourMonths = new DateRange(102, 'RecentTwentyFourMonths', 'Recent 24 months', false, DateRangeScene.TrendAnalysis);
public static readonly RecentThirtySixMonths = new DateRange(103, 'RecentThirtySixMonths', 'Recent 36 months', false, DateRangeScene.TrendAnalysis);
public static readonly RecentTwoYears = new DateRange(104, 'RecentTwoYears', 'Recent 2 years', false, DateRangeScene.TrendAnalysis);
public static readonly RecentThreeYears = new DateRange(105, 'RecentThreeYears', 'Recent 3 years', false, DateRangeScene.TrendAnalysis);
public static readonly RecentFiveYears = new DateRange(106, 'RecentFiveYears', 'Recent 5 years', false, DateRangeScene.TrendAnalysis);
// Custom date range
public static readonly Custom = new DateRange(255, 'Custom', 'Custom Date', false, DateRangeScene.Normal, DateRangeScene.TrendAnalysis);
public readonly type: number;
public readonly name: string;
public readonly isBillingCycle: boolean;
private readonly availableScenes: Record<number, boolean>;
private constructor(type: number, typeName: DateRangeTypeName, name: string, isBillingCycle: boolean, ...availableScenes: DateRangeScene[]) {
this.type = type;
this.name = name;
this.isBillingCycle = isBillingCycle;
this.availableScenes = {};
if (availableScenes) {
for (const scene of availableScenes) {
this.availableScenes[scene] = true;
}
}
DateRange.allInstances.push(this);
DateRange.allInstancesByType[type] = this;
DateRange.allInstancesByTypeName[typeName] = this;
}
public isAvailableForScene(scene: DateRangeScene): boolean {
return this.availableScenes[scene] || false;
}
public static values(): DateRange[] {
return DateRange.allInstances;
}
public static all(): Record<DateRangeTypeName, DateRange> {
return DateRange.allInstancesByTypeName;
}
public static valueOf(type: number): DateRange {
return DateRange.allInstancesByType[type];
}
public static isAvailableForScene(type: number, scene: DateRangeScene): boolean {
const dateRange = DateRange.allInstancesByType[type];
return dateRange?.isAvailableForScene(scene) || false;
}
public static isBillingCycle(type: number): boolean {
const dateRange = DateRange.allInstancesByType[type];
return dateRange?.isBillingCycle || false;
}
}
+54 -57
View File
@@ -1,6 +1,6 @@
import moment from 'moment';
import dateTimeConstants from '@/consts/datetime.js';
import { Month, WeekDay, MeridiemIndicator, DateRangeScene, DateRange, LANGUAGE_DEFAULT_DATE_TIME_FORMAT_VALUE } from '@/core/datetime.ts';
import { isObject, isString, isNumber } from './common.ts';
export function isYearMonthValid(year, month) {
@@ -198,16 +198,16 @@ export function getDay(date) {
export function getDayOfWeekName(date) {
const dayOfWeek = moment(date).days();
return dateTimeConstants.allWeekDaysArray[dayOfWeek].name;
return WeekDay.valueOf(dayOfWeek).name;
}
export function getMonthName(date) {
const dayOfWeek = moment(date).month();
return dateTimeConstants.allMonthsArray[dayOfWeek];
const month = moment(date).month();
return Month.valueOf(month + 1).name;
}
export function getAMOrPM(hour) {
return isPM(hour) ? dateTimeConstants.allMeridiemIndicators.PM : dateTimeConstants.allMeridiemIndicators.AM;
return isPM(hour) ? MeridiemIndicator.PM.name : MeridiemIndicator.AM.name;
}
export function getUnixTimeBeforeUnixTime(unixTime, amount, unit) {
@@ -429,9 +429,9 @@ export function getAllMonthsStartAndEndUnixTimes(startYearMonth, endYearMonth) {
}
export function getDateTimeFormatType(allFormatMap, allFormatArray, localeDefaultFormatTypeName, systemDefaultFormatType, formatTypeValue) {
if (formatTypeValue > dateTimeConstants.defaultDateTimeFormatValue && allFormatArray[formatTypeValue - 1] && allFormatArray[formatTypeValue - 1].key) {
if (formatTypeValue > LANGUAGE_DEFAULT_DATE_TIME_FORMAT_VALUE && allFormatArray[formatTypeValue - 1] && allFormatArray[formatTypeValue - 1].key) {
return allFormatArray[formatTypeValue - 1];
} else if (formatTypeValue === dateTimeConstants.defaultDateTimeFormatValue && allFormatMap[localeDefaultFormatTypeName] && allFormatMap[localeDefaultFormatTypeName].key) {
} else if (formatTypeValue === LANGUAGE_DEFAULT_DATE_TIME_FORMAT_VALUE && allFormatMap[localeDefaultFormatTypeName] && allFormatMap[localeDefaultFormatTypeName].key) {
return allFormatMap[localeDefaultFormatTypeName];
} else {
return systemDefaultFormatType;
@@ -489,12 +489,12 @@ export function getShiftedDateRangeAndDateType(minTime, maxTime, scale, firstDay
}
export function getShiftedDateRangeAndDateTypeForBillingCycle(minTime, maxTime, scale, firstDayOfWeek, scene, statementDate) {
if (!statementDate || !dateTimeConstants.allDateRanges.PreviousBillingCycle.availableScenes[scene] || !dateTimeConstants.allDateRanges.CurrentBillingCycle.availableScenes[scene]) {
if (!statementDate || !DateRange.PreviousBillingCycle.isAvailableForScene(scene) || !DateRange.CurrentBillingCycle.isAvailableForScene(scene)) {
return null;
}
const previousBillingCycleRange = getDateRangeByBillingCycleDateType(dateTimeConstants.allDateRanges.PreviousBillingCycle.type, firstDayOfWeek, statementDate);
const currentBillingCycleRange = getDateRangeByBillingCycleDateType(dateTimeConstants.allDateRanges.CurrentBillingCycle.type, firstDayOfWeek, statementDate);
const previousBillingCycleRange = getDateRangeByBillingCycleDateType(DateRange.PreviousBillingCycle.type, firstDayOfWeek, statementDate);
const currentBillingCycleRange = getDateRangeByBillingCycleDateType(DateRange.CurrentBillingCycle.type, firstDayOfWeek, statementDate);
if (previousBillingCycleRange && getUnixTimeBeforeUnixTime(previousBillingCycleRange.maxTime, 1, 'months') === maxTime && getUnixTimeBeforeUnixTime(previousBillingCycleRange.minTime, 1, 'months') === minTime && scale === 1) {
return previousBillingCycleRange;
@@ -510,23 +510,20 @@ export function getShiftedDateRangeAndDateTypeForBillingCycle(minTime, maxTime,
}
export function getDateTypeByDateRange(minTime, maxTime, firstDayOfWeek, scene) {
let newDateType = dateTimeConstants.allDateRanges.Custom.type;
const allDateRanges = DateRange.values();
let newDateType = DateRange.Custom.type;
for (let dateRangeField in dateTimeConstants.allDateRanges) {
if (!Object.prototype.hasOwnProperty.call(dateTimeConstants.allDateRanges, dateRangeField)) {
for (let i = 0; i < allDateRanges.length; i++) {
const dateRange = allDateRanges[i];
if (!dateRange.isAvailableForScene(scene)) {
continue;
}
const dateRangeType = dateTimeConstants.allDateRanges[dateRangeField];
const range = getDateRangeByDateType(dateRange.type, firstDayOfWeek);
if (!dateRangeType.availableScenes[scene]) {
continue;
}
const dateRange = getDateRangeByDateType(dateRangeType.type, firstDayOfWeek);
if (dateRange && dateRange.minTime === minTime && dateRange.maxTime === maxTime) {
newDateType = dateRangeType.type;
if (range && range.minTime === minTime && range.maxTime === maxTime) {
newDateType = dateRange.type;
break;
}
}
@@ -535,12 +532,12 @@ export function getDateTypeByDateRange(minTime, maxTime, firstDayOfWeek, scene)
}
export function getDateTypeByBillingCycleDateRange(minTime, maxTime, firstDayOfWeek, scene, statementDate) {
if (!statementDate || !dateTimeConstants.allDateRanges.PreviousBillingCycle.availableScenes[scene] || !dateTimeConstants.allDateRanges.CurrentBillingCycle.availableScenes[scene]) {
if (!statementDate || !DateRange.PreviousBillingCycle.isAvailableForScene(scene) || !DateRange.CurrentBillingCycle.isAvailableForScene(scene)) {
return null;
}
const previousBillingCycleRange = getDateRangeByBillingCycleDateType(dateTimeConstants.allDateRanges.PreviousBillingCycle.type, firstDayOfWeek, statementDate);
const currentBillingCycleRange = getDateRangeByBillingCycleDateType(dateTimeConstants.allDateRanges.CurrentBillingCycle.type, firstDayOfWeek, statementDate);
const previousBillingCycleRange = getDateRangeByBillingCycleDateType(DateRange.PreviousBillingCycle.type, firstDayOfWeek, statementDate);
const currentBillingCycleRange = getDateRangeByBillingCycleDateType(DateRange.CurrentBillingCycle.type, firstDayOfWeek, statementDate);
if (previousBillingCycleRange && previousBillingCycleRange.maxTime === maxTime && previousBillingCycleRange.minTime === minTime) {
return previousBillingCycleRange.dateType;
@@ -555,55 +552,55 @@ export function getDateRangeByDateType(dateType, firstDayOfWeek) {
let maxTime = 0;
let minTime = 0;
if (dateType === dateTimeConstants.allDateRanges.All.type) { // All
if (dateType === DateRange.All.type) { // All
maxTime = 0;
minTime = 0;
} else if (dateType === dateTimeConstants.allDateRanges.Today.type) { // Today
} else if (dateType === DateRange.Today.type) { // Today
maxTime = getTodayLastUnixTime();
minTime = getTodayFirstUnixTime();
} else if (dateType === dateTimeConstants.allDateRanges.Yesterday.type) { // Yesterday
} else if (dateType === DateRange.Yesterday.type) { // Yesterday
maxTime = getUnixTimeBeforeUnixTime(getTodayLastUnixTime(), 1, 'days');
minTime = getUnixTimeBeforeUnixTime(getTodayFirstUnixTime(), 1, 'days');
} else if (dateType === dateTimeConstants.allDateRanges.LastSevenDays.type) { // Last 7 days
} else if (dateType === DateRange.LastSevenDays.type) { // Last 7 days
maxTime = getTodayLastUnixTime();
minTime = getUnixTimeBeforeUnixTime(getTodayFirstUnixTime(), 6, 'days');
} else if (dateType === dateTimeConstants.allDateRanges.LastThirtyDays.type) { // Last 30 days
} else if (dateType === DateRange.LastThirtyDays.type) { // Last 30 days
maxTime = getTodayLastUnixTime();
minTime = getUnixTimeBeforeUnixTime(getTodayFirstUnixTime(), 29, 'days');
} else if (dateType === dateTimeConstants.allDateRanges.ThisWeek.type) { // This week
} else if (dateType === DateRange.ThisWeek.type) { // This week
maxTime = getThisWeekLastUnixTime(firstDayOfWeek);
minTime = getThisWeekFirstUnixTime(firstDayOfWeek);
} else if (dateType === dateTimeConstants.allDateRanges.LastWeek.type) { // Last week
} else if (dateType === DateRange.LastWeek.type) { // Last week
maxTime = getUnixTimeBeforeUnixTime(getThisWeekLastUnixTime(firstDayOfWeek), 7, 'days');
minTime = getUnixTimeBeforeUnixTime(getThisWeekFirstUnixTime(firstDayOfWeek), 7, 'days');
} else if (dateType === dateTimeConstants.allDateRanges.ThisMonth.type) { // This month
} else if (dateType === DateRange.ThisMonth.type) { // This month
maxTime = getThisMonthLastUnixTime();
minTime = getThisMonthFirstUnixTime();
} else if (dateType === dateTimeConstants.allDateRanges.LastMonth.type) { // Last month
} else if (dateType === DateRange.LastMonth.type) { // Last month
maxTime = getUnixTimeBeforeUnixTime(getThisMonthFirstUnixTime(), 1, 'seconds');
minTime = getUnixTimeBeforeUnixTime(getThisMonthFirstUnixTime(), 1, 'months');
} else if (dateType === dateTimeConstants.allDateRanges.ThisYear.type) { // This year
} else if (dateType === DateRange.ThisYear.type) { // This year
maxTime = getThisYearLastUnixTime();
minTime = getThisYearFirstUnixTime();
} else if (dateType === dateTimeConstants.allDateRanges.LastYear.type) { // Last year
} else if (dateType === DateRange.LastYear.type) { // Last year
maxTime = getUnixTimeBeforeUnixTime(getThisYearLastUnixTime(), 1, 'years');
minTime = getUnixTimeBeforeUnixTime(getThisYearFirstUnixTime(), 1, 'years');
} else if (dateType === dateTimeConstants.allDateRanges.RecentTwelveMonths.type) { // Recent 12 months
} else if (dateType === DateRange.RecentTwelveMonths.type) { // Recent 12 months
maxTime = getThisMonthLastUnixTime();
minTime = getUnixTimeBeforeUnixTime(getThisMonthFirstUnixTime(), 11, 'months');
} else if (dateType === dateTimeConstants.allDateRanges.RecentTwentyFourMonths.type) { // Recent 24 months
} else if (dateType === DateRange.RecentTwentyFourMonths.type) { // Recent 24 months
maxTime = getThisMonthLastUnixTime();
minTime = getUnixTimeBeforeUnixTime(getThisMonthFirstUnixTime(), 23, 'months');
} else if (dateType === dateTimeConstants.allDateRanges.RecentThirtySixMonths.type) { // Recent 36 months
} else if (dateType === DateRange.RecentThirtySixMonths.type) { // Recent 36 months
maxTime = getThisMonthLastUnixTime();
minTime = getUnixTimeBeforeUnixTime(getThisMonthFirstUnixTime(), 35, 'months');
} else if (dateType === dateTimeConstants.allDateRanges.RecentTwoYears.type) { // Recent 2 years
} else if (dateType === DateRange.RecentTwoYears.type) { // Recent 2 years
maxTime = getThisYearLastUnixTime();
minTime = getUnixTimeBeforeUnixTime(getThisYearFirstUnixTime(), 1, 'years');
} else if (dateType === dateTimeConstants.allDateRanges.RecentThreeYears.type) { // Recent 3 years
} else if (dateType === DateRange.RecentThreeYears.type) { // Recent 3 years
maxTime = getThisYearLastUnixTime();
minTime = getUnixTimeBeforeUnixTime(getThisYearFirstUnixTime(), 2, 'years');
} else if (dateType === dateTimeConstants.allDateRanges.RecentFiveYears.type) { // Recent 5 years
} else if (dateType === DateRange.RecentFiveYears.type) { // Recent 5 years
maxTime = getThisYearLastUnixTime();
minTime = getUnixTimeBeforeUnixTime(getThisYearFirstUnixTime(), 4, 'years');
} else {
@@ -621,7 +618,7 @@ export function getDateRangeByBillingCycleDateType(dateType, firstDayOfWeek, sta
let maxTime = 0;
let minTime = 0;
if (dateType === dateTimeConstants.allDateRanges.PreviousBillingCycle.type || dateType === dateTimeConstants.allDateRanges.CurrentBillingCycle.type) { // Previous Billing Cycle | Current Billing Cycle
if (dateType === DateRange.PreviousBillingCycle.type || dateType === DateRange.CurrentBillingCycle.type) { // Previous Billing Cycle | Current Billing Cycle
if (statementDate) {
if (getCurrentDay() <= statementDate) {
maxTime = getThisMonthSpecifiedDayLastUnixTime(statementDate);
@@ -631,17 +628,17 @@ export function getDateRangeByBillingCycleDateType(dateType, firstDayOfWeek, sta
minTime = getUnixTimeAfterUnixTime(getThisMonthSpecifiedDayFirstUnixTime(statementDate), 1, 'days');
}
if (dateType === dateTimeConstants.allDateRanges.PreviousBillingCycle.type) {
if (dateType === DateRange.PreviousBillingCycle.type) {
maxTime = getUnixTimeBeforeUnixTime(maxTime, 1, 'months');
minTime = getUnixTimeBeforeUnixTime(minTime, 1, 'months');
}
} else {
let fallbackDateRange = null;
if (dateType === dateTimeConstants.allDateRanges.CurrentBillingCycle.type) { // same as This Month
fallbackDateRange = getDateRangeByDateType(dateTimeConstants.allDateRanges.ThisMonth.type, firstDayOfWeek);
} else if (dateType === dateTimeConstants.allDateRanges.PreviousBillingCycle.type) { // same as Last Month
fallbackDateRange = getDateRangeByDateType(dateTimeConstants.allDateRanges.LastMonth.type, firstDayOfWeek);
if (dateType === DateRange.CurrentBillingCycle.type) { // same as This Month
fallbackDateRange = getDateRangeByDateType(DateRange.ThisMonth.type, firstDayOfWeek);
} else if (dateType === DateRange.PreviousBillingCycle.type) { // same as Last Month
fallbackDateRange = getDateRangeByDateType(DateRange.LastMonth.type, firstDayOfWeek);
}
if (fallbackDateRange) {
@@ -672,14 +669,14 @@ export function getRecentMonthDateRanges(monthCount) {
}
let maxTime = getUnixTimeBeforeUnixTime(getUnixTimeAfterUnixTime(minTime, 1, 'months'), 1, 'seconds');
let dateType = dateTimeConstants.allDateRanges.Custom.type;
let dateType = DateRange.Custom.type;
let year = getYear(parseDateFromUnixTime(minTime));
let month = getMonth(parseDateFromUnixTime(minTime));
if (i === 0) {
dateType = dateTimeConstants.allDateRanges.ThisMonth.type;
dateType = DateRange.ThisMonth.type;
} else if (i === 1) {
dateType = dateTimeConstants.allDateRanges.LastMonth.type;
dateType = DateRange.LastMonth.type;
}
recentDateRanges.push({
@@ -707,17 +704,17 @@ export function getRecentDateRangeTypeByDateType(allRecentMonthDateRanges, dateT
export function getRecentDateRangeType(allRecentMonthDateRanges, dateType, minTime, maxTime, firstDayOfWeek) {
let dateRange = getDateRangeByDateType(dateType, firstDayOfWeek);
if (dateRange && dateRange.dateType === dateTimeConstants.allDateRanges.All.type) {
return getRecentDateRangeTypeByDateType(allRecentMonthDateRanges, dateTimeConstants.allDateRanges.All.type);
if (dateRange && dateRange.dateType === DateRange.All.type) {
return getRecentDateRangeTypeByDateType(allRecentMonthDateRanges, DateRange.All.type);
}
if (!dateRange && (!maxTime || !minTime)) {
return getRecentDateRangeTypeByDateType(allRecentMonthDateRanges, dateTimeConstants.allDateRanges.Custom.type);
return getRecentDateRangeTypeByDateType(allRecentMonthDateRanges, DateRange.Custom.type);
}
if (!dateRange) {
dateRange = {
dateType: dateTimeConstants.allDateRanges.Custom.type,
dateType: DateRange.Custom.type,
maxTime: maxTime,
minTime: minTime
};
@@ -731,7 +728,7 @@ export function getRecentDateRangeType(allRecentMonthDateRanges, dateType, minTi
}
}
return getRecentDateRangeTypeByDateType(allRecentMonthDateRanges, dateTimeConstants.allDateRanges.Custom.type);
return getRecentDateRangeTypeByDateType(allRecentMonthDateRanges, DateRange.Custom.type);
}
export function getTimeValues(date, is24Hour, isMeridiemIndicatorFirst) {
@@ -779,7 +776,7 @@ export function getCombinedDateAndTimeValues(date, timeValues, is24Hour, isMerid
hours = 0;
}
if (meridiemIndicator === dateTimeConstants.allMeridiemIndicators.PM) {
if (meridiemIndicator === MeridiemIndicator.PM.name) {
hours += 12;
}
}
+113 -113
View File
@@ -2,6 +2,7 @@ import moment from 'moment-timezone';
import { defaultLanguage, allLanguages } from '@/locales/index.ts';
import { Month, WeekDay, MeridiemIndicator, LongDateFormat, ShortDateFormat, LongTimeFormat, ShortTimeFormat, DateRangeScene, DateRange, LANGUAGE_DEFAULT_DATE_TIME_FORMAT_VALUE } from '@/core/datetime.ts';
import { TimezoneTypeForStatistics } from '@/core/timezone.ts';
import { CurrencyDisplayType, CurrencySortingType } from '@/core/currency.ts';
import { PresetAmountColor } from '@/core/color.ts';
@@ -11,7 +12,6 @@ import { TransactionEditScopeType, TransactionTagFilterType } from '@/core/trans
import { ScheduledTemplateFrequencyType } from '@/core/template.ts';
import numeralConstants from '@/consts/numeral.js';
import datetimeConstants from '@/consts/datetime.js';
import { UTC_TIMEZONE, ALL_TIMEZONES } from '@/consts/timezone.ts';
import { ALL_CURRENCIES } from '@/consts/currency.ts';
import { SUPPORTED_IMPORT_FILE_TYPES } from '@/consts/file.ts';
@@ -24,7 +24,6 @@ import {
isString,
isNumber,
isBoolean,
getNameByKeyValue,
copyObjectTo,
copyArrayTo
} from './common.ts';
@@ -247,90 +246,102 @@ function getCurrencyUnitName(currencyCode, isPlural, translateFn) {
return '';
}
function getAllMeridiemIndicatorNames(translateFn) {
const allMeridiemIndicatorNames = [];
function getAllMeridiemIndicators(translateFn) {
const allMeridiemIndicators = MeridiemIndicator.values();
const meridiemIndicatorNames = [];
const localizedMeridiemIndicatorNames = [];
for (let i = 0; i < datetimeConstants.allMeridiemIndicatorsArray.length; i++) {
const indicatorName = datetimeConstants.allMeridiemIndicatorsArray[i];
allMeridiemIndicatorNames.push(translateFn(`datetime.${indicatorName}.content`));
for (let i = 0; i < allMeridiemIndicators.length; i++) {
const indicator = allMeridiemIndicators[i];
meridiemIndicatorNames.push(indicator.name);
localizedMeridiemIndicatorNames.push(translateFn(`datetime.${indicator.name}.content`));
}
return allMeridiemIndicatorNames;
return {
values: meridiemIndicatorNames,
displayValues: localizedMeridiemIndicatorNames
};
}
function getAllLongMonthNames(translateFn) {
const allMonthNames = [];
const ret = [];
const allMonths = Month.values();
for (let i = 0; i < datetimeConstants.allMonthsArray.length; i++) {
const monthName = datetimeConstants.allMonthsArray[i];
allMonthNames.push(translateFn(`datetime.${monthName}.long`));
for (let i = 0; i < allMonths.length; i++) {
const month = allMonths[i];
ret.push(translateFn(`datetime.${month.name}.long`));
}
return allMonthNames;
return ret;
}
function getAllShortMonthNames(translateFn) {
const allMonthNames = [];
const ret = [];
const allMonths = Month.values();
for (let i = 0; i < datetimeConstants.allMonthsArray.length; i++) {
const monthName = datetimeConstants.allMonthsArray[i];
allMonthNames.push(translateFn(`datetime.${monthName}.short`));
for (let i = 0; i < allMonths.length; i++) {
const month = allMonths[i];
ret.push(translateFn(`datetime.${month.name}.short`));
}
return allMonthNames;
return ret;
}
function getAllLongWeekdayNames(translateFn) {
const allWeekNames = [];
const ret = [];
const allWeekDays = WeekDay.values();
for (let i = 0; i < datetimeConstants.allWeekDaysArray.length; i++) {
const weekDay = datetimeConstants.allWeekDaysArray[i];
allWeekNames.push(translateFn(`datetime.${weekDay.name}.long`));
for (let i = 0; i < allWeekDays.length; i++) {
const weekDay = allWeekDays[i];
ret.push(translateFn(`datetime.${weekDay.name}.long`));
}
return allWeekNames;
return ret;
}
function getAllShortWeekdayNames(translateFn) {
const allWeekNames = [];
const ret = [];
const allWeekDays = WeekDay.values();
for (let i = 0; i < datetimeConstants.allWeekDaysArray.length; i++) {
const weekDay = datetimeConstants.allWeekDaysArray[i];
allWeekNames.push(translateFn(`datetime.${weekDay.name}.short`));
for (let i = 0; i < allWeekDays.length; i++) {
const weekDay = allWeekDays[i];
ret.push(translateFn(`datetime.${weekDay.name}.short`));
}
return allWeekNames;
return ret;
}
function getAllMinWeekdayNames(translateFn) {
const allWeekNames = [];
const ret = [];
const allWeekDays = WeekDay.values();
for (let i = 0; i < datetimeConstants.allWeekDaysArray.length; i++) {
const weekDay = datetimeConstants.allWeekDaysArray[i];
allWeekNames.push(translateFn(`datetime.${weekDay.name}.min`));
for (let i = 0; i < allWeekDays.length; i++) {
const weekDay = allWeekDays[i];
ret.push(translateFn(`datetime.${weekDay.name}.min`));
}
return allWeekNames;
return ret;
}
function getAllLongDateFormats(translateFn) {
const defaultLongDateFormatTypeName = translateFn('default.longDateFormat');
return getDateTimeFormats(translateFn, datetimeConstants.allLongDateFormat, datetimeConstants.allLongDateFormatArray, 'format.longDate', defaultLongDateFormatTypeName, datetimeConstants.defaultLongDateFormat);
return getDateTimeFormats(translateFn, LongDateFormat.all(), LongDateFormat.values(), 'format.longDate', defaultLongDateFormatTypeName, LongDateFormat.Default);
}
function getAllShortDateFormats(translateFn) {
const defaultShortDateFormatTypeName = translateFn('default.shortDateFormat');
return getDateTimeFormats(translateFn, datetimeConstants.allShortDateFormat, datetimeConstants.allShortDateFormatArray, 'format.shortDate', defaultShortDateFormatTypeName, datetimeConstants.defaultShortDateFormat);
return getDateTimeFormats(translateFn, ShortDateFormat.all(), ShortDateFormat.values(), 'format.shortDate', defaultShortDateFormatTypeName, ShortDateFormat.Default);
}
function getAllLongTimeFormats(translateFn) {
const defaultLongTimeFormatTypeName = translateFn('default.longTimeFormat');
return getDateTimeFormats(translateFn, datetimeConstants.allLongTimeFormat, datetimeConstants.allLongTimeFormatArray, 'format.longTime', defaultLongTimeFormatTypeName, datetimeConstants.defaultLongTimeFormat);
return getDateTimeFormats(translateFn, LongTimeFormat.values(), LongTimeFormat.values(), 'format.longTime', defaultLongTimeFormatTypeName, LongTimeFormat.Default);
}
function getAllShortTimeFormats(translateFn) {
const defaultShortTimeFormatTypeName = translateFn('default.shortTimeFormat');
return getDateTimeFormats(translateFn, datetimeConstants.allShortTimeFormat, datetimeConstants.allShortTimeFormatArray, 'format.shortTime', defaultShortTimeFormatTypeName, datetimeConstants.defaultShortTimeFormat);
return getDateTimeFormats(translateFn, ShortTimeFormat.values(), ShortTimeFormat.values(), 'format.shortTime', defaultShortTimeFormatTypeName, ShortTimeFormat.Default);
}
function getMonthShortName(monthName, translateFn) {
@@ -380,96 +391,89 @@ function getMultiMonthdayShortNames(monthDays, translateFn) {
function getMultiWeekdayLongNames(weekdayTypes, firstDayOfWeek, translateFn) {
const weekdayTypesMap = {};
const finalWeekdayTypes = [];
if (!isNumber(firstDayOfWeek)) {
firstDayOfWeek = datetimeConstants.allWeekDays.Sunday.type;
firstDayOfWeek = WeekDay.DefaultFirstDay.type;
}
for (let i = 0; i < weekdayTypes.length; i++) {
weekdayTypesMap[weekdayTypes[i]] = true;
}
for (let i = firstDayOfWeek; i < datetimeConstants.allWeekDaysArray.length; i++) {
const weekDay = datetimeConstants.allWeekDaysArray[i];
const allWeekDays = getAllWeekDays(firstDayOfWeek, translateFn);
const finalWeekdayNames = [];
for (let i = 0; i < allWeekDays.length; i++) {
const weekDay = allWeekDays[i];
if (weekdayTypesMap[weekDay.type]) {
finalWeekdayTypes.push(weekDay.type);
finalWeekdayNames.push(weekDay.displayName);
}
}
for (let i = 0; i < firstDayOfWeek; i++) {
const weekDay = datetimeConstants.allWeekDaysArray[i];
if (weekdayTypesMap[weekDay.type]) {
finalWeekdayTypes.push(weekDay.type);
}
}
const allWeekDays = getAllWeekDays(null, translateFn)
return joinMultiText(finalWeekdayTypes.map(type => getNameByKeyValue(allWeekDays, type, 'type', 'displayName')), translateFn);
return joinMultiText(finalWeekdayNames, translateFn);
}
function getI18nLongDateFormat(translateFn, formatTypeValue) {
const defaultLongDateFormatTypeName = translateFn('default.longDateFormat');
return getDateTimeFormat(translateFn, datetimeConstants.allLongDateFormat, datetimeConstants.allLongDateFormatArray, 'format.longDate', defaultLongDateFormatTypeName, datetimeConstants.defaultLongDateFormat, formatTypeValue);
return getDateTimeFormat(translateFn, LongDateFormat.all(), LongDateFormat.values(), 'format.longDate', defaultLongDateFormatTypeName, LongDateFormat.Default, formatTypeValue);
}
function getI18nShortDateFormat(translateFn, formatTypeValue) {
const defaultShortDateFormatTypeName = translateFn('default.shortDateFormat');
return getDateTimeFormat(translateFn, datetimeConstants.allShortDateFormat, datetimeConstants.allShortDateFormatArray, 'format.shortDate', defaultShortDateFormatTypeName, datetimeConstants.defaultShortDateFormat, formatTypeValue);
return getDateTimeFormat(translateFn, ShortDateFormat.all(), ShortDateFormat.values(), 'format.shortDate', defaultShortDateFormatTypeName, ShortDateFormat.Default, formatTypeValue);
}
function getI18nLongYearFormat(translateFn, formatTypeValue) {
const defaultLongDateFormatTypeName = translateFn('default.longDateFormat');
return getDateTimeFormat(translateFn, datetimeConstants.allLongDateFormat, datetimeConstants.allLongDateFormatArray, 'format.longYear', defaultLongDateFormatTypeName, datetimeConstants.defaultLongDateFormat, formatTypeValue);
return getDateTimeFormat(translateFn, LongDateFormat.all(), LongDateFormat.values(), 'format.longYear', defaultLongDateFormatTypeName, LongDateFormat.Default, formatTypeValue);
}
function getI18nShortYearFormat(translateFn, formatTypeValue) {
const defaultShortDateFormatTypeName = translateFn('default.shortDateFormat');
return getDateTimeFormat(translateFn, datetimeConstants.allShortDateFormat, datetimeConstants.allShortDateFormatArray, 'format.shortYear', defaultShortDateFormatTypeName, datetimeConstants.defaultShortDateFormat, formatTypeValue);
return getDateTimeFormat(translateFn, ShortDateFormat.all(), ShortDateFormat.values(), 'format.shortYear', defaultShortDateFormatTypeName, ShortDateFormat.Default, formatTypeValue);
}
function getI18nLongYearMonthFormat(translateFn, formatTypeValue) {
const defaultLongDateFormatTypeName = translateFn('default.longDateFormat');
return getDateTimeFormat(translateFn, datetimeConstants.allLongDateFormat, datetimeConstants.allLongDateFormatArray, 'format.longYearMonth', defaultLongDateFormatTypeName, datetimeConstants.defaultLongDateFormat, formatTypeValue);
return getDateTimeFormat(translateFn, LongDateFormat.all(), LongDateFormat.values(), 'format.longYearMonth', defaultLongDateFormatTypeName, LongDateFormat.Default, formatTypeValue);
}
function getI18nShortYearMonthFormat(translateFn, formatTypeValue) {
const defaultShortDateFormatTypeName = translateFn('default.shortDateFormat');
return getDateTimeFormat(translateFn, datetimeConstants.allShortDateFormat, datetimeConstants.allShortDateFormatArray, 'format.shortYearMonth', defaultShortDateFormatTypeName, datetimeConstants.defaultShortDateFormat, formatTypeValue);
return getDateTimeFormat(translateFn, ShortDateFormat.all(), ShortDateFormat.values(), 'format.shortYearMonth', defaultShortDateFormatTypeName, ShortDateFormat.Default, formatTypeValue);
}
function getI18nLongMonthDayFormat(translateFn, formatTypeValue) {
const defaultLongDateFormatTypeName = translateFn('default.longDateFormat');
return getDateTimeFormat(translateFn, datetimeConstants.allLongDateFormat, datetimeConstants.allLongDateFormatArray, 'format.longMonthDay', defaultLongDateFormatTypeName, datetimeConstants.defaultLongDateFormat, formatTypeValue);
return getDateTimeFormat(translateFn, LongDateFormat.all(), LongDateFormat.values(), 'format.longMonthDay', defaultLongDateFormatTypeName, LongDateFormat.Default, formatTypeValue);
}
function getI18nShortMonthDayFormat(translateFn, formatTypeValue) {
const defaultShortDateFormatTypeName = translateFn('default.shortDateFormat');
return getDateTimeFormat(translateFn, datetimeConstants.allShortDateFormat, datetimeConstants.allShortDateFormatArray, 'format.shortMonthDay', defaultShortDateFormatTypeName, datetimeConstants.defaultShortDateFormat, formatTypeValue);
return getDateTimeFormat(translateFn, ShortDateFormat.all(), ShortDateFormat.values(), 'format.shortMonthDay', defaultShortDateFormatTypeName, ShortDateFormat.Default, formatTypeValue);
}
function isLongDateMonthAfterYear(translateFn, formatTypeValue) {
const defaultLongDateFormatTypeName = translateFn('default.longDateFormat');
const type = getDateTimeFormatType(datetimeConstants.allLongDateFormat, datetimeConstants.allLongDateFormatArray, defaultLongDateFormatTypeName, datetimeConstants.defaultLongDateFormat, formatTypeValue);
const type = getDateTimeFormatType(LongDateFormat.all(), LongDateFormat.values(), defaultLongDateFormatTypeName, LongDateFormat.Default, formatTypeValue);
return type.isMonthAfterYear;
}
function isShortDateMonthAfterYear(translateFn, formatTypeValue) {
const defaultShortDateFormatTypeName = translateFn('default.shortDateFormat');
const type = getDateTimeFormatType(datetimeConstants.allShortDateFormat, datetimeConstants.allShortDateFormatArray, defaultShortDateFormatTypeName, datetimeConstants.defaultShortDateFormat, formatTypeValue);
const type = getDateTimeFormatType(ShortDateFormat.all(), ShortDateFormat.values(), defaultShortDateFormatTypeName, ShortDateFormat.Default, formatTypeValue);
return type.isMonthAfterYear;
}
function getI18nLongTimeFormat(translateFn, formatTypeValue) {
const defaultLongTimeFormatTypeName = translateFn('default.longTimeFormat');
return getDateTimeFormat(translateFn, datetimeConstants.allLongTimeFormat, datetimeConstants.allLongTimeFormatArray, 'format.longTime', defaultLongTimeFormatTypeName, datetimeConstants.defaultLongTimeFormat, formatTypeValue);
return getDateTimeFormat(translateFn, LongTimeFormat.values(), LongTimeFormat.values(), 'format.longTime', defaultLongTimeFormatTypeName, LongTimeFormat.Default, formatTypeValue);
}
function getI18nShortTimeFormat(translateFn, formatTypeValue) {
const defaultShortTimeFormatTypeName = translateFn('default.shortTimeFormat');
return getDateTimeFormat(translateFn, datetimeConstants.allShortTimeFormat, datetimeConstants.allShortTimeFormatArray, 'format.shortTime', defaultShortTimeFormatTypeName, datetimeConstants.defaultShortTimeFormat, formatTypeValue);
return getDateTimeFormat(translateFn, ShortTimeFormat.values(), ShortTimeFormat.values(), 'format.shortTime', defaultShortTimeFormatTypeName, ShortTimeFormat.Default, formatTypeValue);
}
function formatYearQuarter(translateFn, year, quarter) {
@@ -485,35 +489,35 @@ function formatYearQuarter(translateFn, year, quarter) {
function isLongTime24HourFormat(translateFn, formatTypeValue) {
const defaultLongTimeFormatTypeName = translateFn('default.longTimeFormat');
const type = getDateTimeFormatType(datetimeConstants.allLongTimeFormat, datetimeConstants.allLongTimeFormatArray, defaultLongTimeFormatTypeName, datetimeConstants.defaultLongTimeFormat, formatTypeValue);
const type = getDateTimeFormatType(LongTimeFormat.values(), LongTimeFormat.values(), defaultLongTimeFormatTypeName, LongTimeFormat.Default, formatTypeValue);
return type.is24HourFormat;
}
function isLongTimeMeridiemIndicatorFirst(translateFn, formatTypeValue) {
const defaultLongTimeFormatTypeName = translateFn('default.longTimeFormat');
const type = getDateTimeFormatType(datetimeConstants.allLongTimeFormat, datetimeConstants.allLongTimeFormatArray, defaultLongTimeFormatTypeName, datetimeConstants.defaultLongTimeFormat, formatTypeValue);
const type = getDateTimeFormatType(LongTimeFormat.values(), LongTimeFormat.values(), defaultLongTimeFormatTypeName, LongTimeFormat.Default, formatTypeValue);
return type.isMeridiemIndicatorFirst;
}
function isShortTime24HourFormat(translateFn, formatTypeValue) {
const defaultShortTimeFormatTypeName = translateFn('default.shortTimeFormat');
const type = getDateTimeFormatType(datetimeConstants.allShortTimeFormat, datetimeConstants.allShortTimeFormatArray, defaultShortTimeFormatTypeName, datetimeConstants.defaultShortTimeFormat, formatTypeValue);
const type = getDateTimeFormatType(ShortTimeFormat.values(), ShortTimeFormat.values(), defaultShortTimeFormatTypeName, ShortTimeFormat.Default, formatTypeValue);
return type.is24HourFormat;
}
function isShortTimeMeridiemIndicatorFirst(translateFn, formatTypeValue) {
const defaultShortTimeFormatTypeName = translateFn('default.shortTimeFormat');
const type = getDateTimeFormatType(datetimeConstants.allShortTimeFormat, datetimeConstants.allShortTimeFormatArray, defaultShortTimeFormatTypeName, datetimeConstants.defaultShortTimeFormat, formatTypeValue);
const type = getDateTimeFormatType(ShortTimeFormat.values(), ShortTimeFormat.values(), defaultShortTimeFormatTypeName, ShortTimeFormat.Default, formatTypeValue);
return type.isMeridiemIndicatorFirst;
}
function getDateTimeFormats(translateFn, allFormatMap, allFormatArray, localeFormatPathPrefix, localeDefaultFormatTypeName, systemDefaultFormatType) {
const defaultFormat = getDateTimeFormat(translateFn, allFormatMap, allFormatArray,
localeFormatPathPrefix, localeDefaultFormatTypeName, systemDefaultFormatType, datetimeConstants.defaultDateTimeFormatValue);
localeFormatPathPrefix, localeDefaultFormatTypeName, systemDefaultFormatType, LANGUAGE_DEFAULT_DATE_TIME_FORMAT_VALUE);
const ret = [];
ret.push({
type: datetimeConstants.defaultDateTimeFormatValue,
type: LANGUAGE_DEFAULT_DATE_TIME_FORMAT_VALUE,
format: defaultFormat,
displayName: `${translateFn('Language Default')} (${formatCurrentTime(defaultFormat)})`
});
@@ -635,68 +639,66 @@ function getAllCurrencies(translateFn) {
}
function getAllWeekDays(firstDayOfWeek, translateFn) {
const allWeekDays = [];
const ret = [];
const allWeekDays = WeekDay.values();
if (!isNumber(firstDayOfWeek)) {
firstDayOfWeek = datetimeConstants.allWeekDays.Sunday.type;
firstDayOfWeek = WeekDay.DefaultFirstDay.type;
}
for (let i = firstDayOfWeek; i < datetimeConstants.allWeekDaysArray.length; i++) {
const weekDay = datetimeConstants.allWeekDaysArray[i];
for (let i = firstDayOfWeek; i < allWeekDays.length; i++) {
const weekDay = allWeekDays[i];
allWeekDays.push({
ret.push({
type: weekDay.type,
displayName: translateFn(`datetime.${weekDay.name}.long`)
});
}
for (let i = 0; i < firstDayOfWeek; i++) {
const weekDay = datetimeConstants.allWeekDaysArray[i];
const weekDay = allWeekDays[i];
allWeekDays.push({
ret.push({
type: weekDay.type,
displayName: translateFn(`datetime.${weekDay.name}.long`)
});
}
return allWeekDays;
return ret;
}
function getAllDateRanges(scene, includeCustom, includeBillingCycle, translateFn) {
const allDateRanges = [];
const ret = [];
const allDateRanges = DateRange.values();
for (let dateRangeField in datetimeConstants.allDateRanges) {
if (!Object.prototype.hasOwnProperty.call(datetimeConstants.allDateRanges, dateRangeField)) {
for (let i = 0; i < allDateRanges.length; i++) {
const dateRange = allDateRanges[i];
if (!dateRange.isAvailableForScene(scene)) {
continue;
}
const dateRangeType = datetimeConstants.allDateRanges[dateRangeField];
if (!dateRangeType.availableScenes[scene]) {
continue;
}
if (dateRangeType.isBillingCycle) {
if (dateRange.isBillingCycle) {
if (includeBillingCycle) {
allDateRanges.push({
type: dateRangeType.type,
displayName: translateFn(dateRangeType.name),
isBillingCycle: dateRangeType.isBillingCycle
ret.push({
type: dateRange.type,
displayName: translateFn(dateRange.name),
isBillingCycle: dateRange.isBillingCycle
});
}
continue;
}
if (includeCustom || dateRangeType.type !== datetimeConstants.allDateRanges.Custom.type) {
allDateRanges.push({
type: dateRangeType.type,
displayName: translateFn(dateRangeType.name)
if (includeCustom || dateRange.type !== DateRange.Custom.type) {
ret.push({
type: dateRange.type,
displayName: translateFn(dateRange.name)
});
}
}
return allDateRanges;
return ret;
}
function getAllRecentMonthDateRanges(userStore, includeAll, includeCustom, translateFn) {
@@ -705,7 +707,7 @@ function getAllRecentMonthDateRanges(userStore, includeAll, includeCustom, trans
if (includeAll) {
allRecentMonthDateRanges.push({
dateType: datetimeConstants.allDateRanges.All.type,
dateType: DateRange.All.type,
minTime: 0,
maxTime: 0,
displayName: translateFn('All')
@@ -728,7 +730,7 @@ function getAllRecentMonthDateRanges(userStore, includeAll, includeCustom, trans
if (includeCustom) {
allRecentMonthDateRanges.push({
dateType: datetimeConstants.allDateRanges.Custom.type,
dateType: DateRange.Custom.type,
minTime: 0,
maxTime: 0,
displayName: translateFn('Custom Date')
@@ -739,18 +741,16 @@ function getAllRecentMonthDateRanges(userStore, includeAll, includeCustom, trans
}
function getDateRangeDisplayName(userStore, dateType, startTime, endTime, translateFn) {
if (dateType === datetimeConstants.allDateRanges.All.type) {
return translateFn(datetimeConstants.allDateRanges.All.name);
if (dateType === DateRange.All.type) {
return translateFn(DateRange.All.name);
}
for (let dateRangeField in datetimeConstants.allDateRanges) {
if (!Object.prototype.hasOwnProperty.call(datetimeConstants.allDateRanges, dateRangeField)) {
continue;
}
const allDateRanges = DateRange.values();
const dateRange = datetimeConstants.allDateRanges[dateRangeField];
for (let i = 0; i < allDateRanges.length; i++) {
const dateRange = allDateRanges[i];
if (dateRange && dateRange.type !== datetimeConstants.allDateRanges.Custom.type && dateRange.type === dateType && dateRange.name) {
if (dateRange && dateRange.type !== DateRange.Custom.type && dateRange.type === dateType && dateRange.name) {
return translateFn(dateRange.name);
}
}
@@ -1560,9 +1560,9 @@ function setLanguage(i18nGlobal, locale, force) {
weekdaysMin : getAllMinWeekdayNames(i18nGlobal.t),
meridiem: function (hours) {
if (isPM(hours)) {
return i18nGlobal.t(`datetime.${datetimeConstants.allMeridiemIndicators.PM}.content`);
return i18nGlobal.t(`datetime.${MeridiemIndicator.PM.name}.content`);
} else {
return i18nGlobal.t(`datetime.${datetimeConstants.allMeridiemIndicators.AM}.content`);
return i18nGlobal.t(`datetime.${MeridiemIndicator.AM.name}.content`);
}
}
});
@@ -1572,10 +1572,10 @@ function setLanguage(i18nGlobal, locale, force) {
const defaultCurrency = getDefaultCurrency(i18nGlobal.t);
const defaultFirstDayOfWeekName = getDefaultFirstDayOfWeek(i18nGlobal.t);
let defaultFirstDayOfWeek = datetimeConstants.defaultFirstDayOfWeek;
let defaultFirstDayOfWeek = WeekDay.DefaultFirstDay.type;
if (datetimeConstants.allWeekDays[defaultFirstDayOfWeekName]) {
defaultFirstDayOfWeek = datetimeConstants.allWeekDays[defaultFirstDayOfWeekName].type;
if (WeekDay.parse(defaultFirstDayOfWeekName)) {
defaultFirstDayOfWeek = WeekDay.parse(defaultFirstDayOfWeekName).type;
}
return {
@@ -1666,7 +1666,7 @@ export function i18nFunctions(i18nGlobal) {
getDefaultCurrency: () => getDefaultCurrency(i18nGlobal.t),
getDefaultFirstDayOfWeek: () => getDefaultFirstDayOfWeek(i18nGlobal.t),
getCurrencyName: (currencyCode) => getCurrencyName(currencyCode, i18nGlobal.t),
getAllMeridiemIndicatorNames: () => getAllMeridiemIndicatorNames(i18nGlobal.t),
getAllMeridiemIndicators: () => getAllMeridiemIndicators(i18nGlobal.t),
getAllLongMonthNames: () => getAllLongMonthNames(i18nGlobal.t),
getAllShortMonthNames: () => getAllShortMonthNames(i18nGlobal.t),
getAllLongWeekdayNames: () => getAllLongWeekdayNames(i18nGlobal.t),
+2 -2
View File
@@ -1,7 +1,7 @@
import { defineStore } from 'pinia';
import { WeekDay } from '@/core/datetime.ts';
import { DEFAULT_CURRENCY_CODE } from '@/consts/currency.ts';
import datetimeConstants from '@/consts/datetime.js';
import * as settings from '@/lib/settings.js';
export const useSettingsStore = defineStore('settings', {
@@ -37,7 +37,7 @@ export const useSettingsStore = defineStore('settings', {
},
localeDefaultSettings: {
currency: DEFAULT_CURRENCY_CODE,
firstDayOfWeek: datetimeConstants.defaultFirstDayOfWeek
firstDayOfWeek: WeekDay.DefaultFirstDay.type
}
}),
actions: {
+8 -10
View File
@@ -6,9 +6,9 @@ import { useAccountsStore } from './account.js';
import { useTransactionCategoriesStore } from './transactionCategory.js';
import { useExchangeRatesStore } from './exchangeRates.js';
import { DateRangeScene, DateRange } from '@/core/datetime';
import { CategoryType } from '@/core/category.ts';
import { TransactionTagFilterType } from '@/core/transaction.ts';
import datetimeConstants from '@/consts/datetime.js';
import statisticsConstants from '@/consts/statistics.js';
import { DEFAULT_ACCOUNT_ICON, DEFAULT_CATEGORY_ICON } from '@/consts/icon.ts';
import { DEFAULT_ACCOUNT_COLOR, DEFAULT_CATEGORY_COLOR } from '@/consts/color.ts';
@@ -605,13 +605,12 @@ export const useStatisticsStore = defineStore('statistics', {
let categoricalChartDateTypeValid = true;
if (!datetimeConstants.allDateRangesMap[this.transactionStatisticsFilter.categoricalChartDateType] ||
!datetimeConstants.allDateRangesMap[this.transactionStatisticsFilter.categoricalChartDateType].availableScenes[datetimeConstants.allDateRangeScenes.Normal]) {
if (!DateRange.isAvailableForScene(this.transactionStatisticsFilter.categoricalChartDateType, DateRangeScene.Normal)) {
this.transactionStatisticsFilter.categoricalChartDateType = statisticsConstants.defaultCategoricalChartDataRangeType;
categoricalChartDateTypeValid = false;
}
if (categoricalChartDateTypeValid && this.transactionStatisticsFilter.categoricalChartDateType === datetimeConstants.allDateRanges.Custom.type) {
if (categoricalChartDateTypeValid && this.transactionStatisticsFilter.categoricalChartDateType === DateRange.Custom.type) {
if (filter && isInteger(filter.categoricalChartStartTime)) {
this.transactionStatisticsFilter.categoricalChartStartTime = filter.categoricalChartStartTime;
} else {
@@ -648,13 +647,12 @@ export const useStatisticsStore = defineStore('statistics', {
let trendChartDateTypeValid = true;
if (!datetimeConstants.allDateRangesMap[this.transactionStatisticsFilter.trendChartDateType] ||
!datetimeConstants.allDateRangesMap[this.transactionStatisticsFilter.trendChartDateType].availableScenes[datetimeConstants.allDateRangeScenes.TrendAnalysis]) {
if (!DateRange.isAvailableForScene(this.transactionStatisticsFilter.trendChartDateType, DateRangeScene.TrendAnalysis)) {
this.transactionStatisticsFilter.trendChartDateType = statisticsConstants.defaultTrendChartDataRangeType;
trendChartDateTypeValid = false;
}
if (trendChartDateTypeValid && this.transactionStatisticsFilter.trendChartDateType === datetimeConstants.allDateRanges.Custom.type) {
if (trendChartDateTypeValid && this.transactionStatisticsFilter.trendChartDateType === DateRange.Custom.type) {
if (filter && isYearMonth(filter.trendChartStartYearMonth)) {
this.transactionStatisticsFilter.trendChartStartYearMonth = filter.trendChartStartYearMonth;
} else {
@@ -792,7 +790,7 @@ export const useStatisticsStore = defineStore('statistics', {
querys.push('chartType=' + this.transactionStatisticsFilter.categoricalChartType);
querys.push('chartDateType=' + this.transactionStatisticsFilter.categoricalChartDateType);
if (this.transactionStatisticsFilter.categoricalChartDateType === datetimeConstants.allDateRanges.Custom.type) {
if (this.transactionStatisticsFilter.categoricalChartDateType === DateRange.Custom.type) {
querys.push('startTime=' + this.transactionStatisticsFilter.categoricalChartStartTime);
querys.push('endTime=' + this.transactionStatisticsFilter.categoricalChartEndTime);
}
@@ -800,7 +798,7 @@ export const useStatisticsStore = defineStore('statistics', {
querys.push('chartType=' + this.transactionStatisticsFilter.trendChartType);
querys.push('chartDateType=' + this.transactionStatisticsFilter.trendChartDateType);
if (this.transactionStatisticsFilter.trendChartDateType === datetimeConstants.allDateRanges.Custom.type) {
if (this.transactionStatisticsFilter.trendChartDateType === DateRange.Custom.type) {
querys.push('startTime=' + this.transactionStatisticsFilter.trendChartStartYearMonth);
querys.push('endTime=' + this.transactionStatisticsFilter.trendChartEndYearMonth);
}
@@ -896,7 +894,7 @@ export const useStatisticsStore = defineStore('statistics', {
&& this.transactionStatisticsFilter.chartDataType !== statisticsConstants.allChartDataTypes.AccountTotalLiabilities.type) {
querys.push('dateType=' + this.transactionStatisticsFilter.categoricalChartDateType);
if (this.transactionStatisticsFilter.categoricalChartDateType === datetimeConstants.allDateRanges.Custom.type) {
if (this.transactionStatisticsFilter.categoricalChartDateType === DateRange.Custom.type) {
querys.push('minTime=' + this.transactionStatisticsFilter.categoricalChartStartTime);
querys.push('maxTime=' + this.transactionStatisticsFilter.categoricalChartEndTime);
}
+7 -7
View File
@@ -8,10 +8,10 @@ import { useOverviewStore } from './overview.js';
import { useStatisticsStore } from './statistics.js';
import { useExchangeRatesStore } from './exchangeRates.js';
import { DateRange } from '@/core/datetime.ts';
import { CategoryType } from '@/core/category.ts';
import { TransactionType, TransactionTagFilterType } from '@/core/transaction.ts';
import { TRANSACTION_MIN_AMOUNT, TRANSACTION_MAX_AMOUNT } from '@/consts/transaction.ts';
import datetimeConstants from '@/consts/datetime.js';
import userState from '@/lib/userstate.js';
import services from '@/lib/services.js';
import logger from '@/lib/logger.js';
@@ -368,7 +368,7 @@ export const useTransactionsStore = defineStore('transactions', {
state: () => ({
transactionDraft: userState.getUserTransactionDraft(),
transactionsFilter: {
dateType: datetimeConstants.allDateRanges.All.type,
dateType: DateRange.All.type,
maxTime: 0,
minTime: 0,
type: 0,
@@ -666,7 +666,7 @@ export const useTransactionsStore = defineStore('transactions', {
this.transactionListStateInvalid = invalidState;
},
resetTransactions() {
this.transactionsFilter.dateType = datetimeConstants.allDateRanges.All.type;
this.transactionsFilter.dateType = DateRange.All.type;
this.transactionsFilter.maxTime = 0;
this.transactionsFilter.minTime = 0;
this.transactionsFilter.type = 0;
@@ -689,7 +689,7 @@ export const useTransactionsStore = defineStore('transactions', {
if (filter && isNumber(filter.dateType)) {
this.transactionsFilter.dateType = filter.dateType;
} else {
this.transactionsFilter.dateType = datetimeConstants.allDateRanges.All.type;
this.transactionsFilter.dateType = DateRange.All.type;
}
if (filter && isNumber(filter.maxTime)) {
@@ -776,9 +776,9 @@ export const useTransactionsStore = defineStore('transactions', {
}
if (filter && isString(filter.accountIds) && this.transactionsFilter.accountIds !== filter.accountIds) {
if (datetimeConstants.allBillingCycleDateRangesMap[this.transactionsFilter.dateType] &&
if (DateRange.isBillingCycle(this.transactionsFilter.dateType) &&
(!accountsStore.getAccountStatementDate(filter.accountIds) || accountsStore.getAccountStatementDate(filter.accountIds) !== accountsStore.getAccountStatementDate(this.transactionsFilter.accountIds))) {
this.transactionsFilter.dateType = datetimeConstants.allDateRanges.Custom.type;
this.transactionsFilter.dateType = DateRange.Custom.type;
}
this.transactionsFilter.accountIds = filter.accountIds;
@@ -833,7 +833,7 @@ export const useTransactionsStore = defineStore('transactions', {
querys.push('dateType=' + this.transactionsFilter.dateType);
if (datetimeConstants.allBillingCycleDateRangesMap[this.transactionsFilter.dateType] || this.transactionsFilter.dateType === datetimeConstants.allDateRanges.Custom.type) {
if (DateRange.isBillingCycle(this.transactionsFilter.dateType) || this.transactionsFilter.dateType === DateRange.Custom.type) {
querys.push('maxTime=' + this.transactionsFilter.maxTime);
querys.push('minTime=' + this.transactionsFilter.minTime);
}
+3 -3
View File
@@ -196,7 +196,7 @@ import { useUserStore } from '@/stores/user.js';
import { useAccountsStore } from '@/stores/account.js';
import { useOverviewStore } from '@/stores/overview.js';
import datetimeConstants from '@/consts/datetime.js';
import { DateRange } from '@/core/datetime.ts';
import { ThemeType } from '@/core/theme.ts';
import {
formatUnixTime,
@@ -260,7 +260,7 @@ export default {
return this.userStore.currentUserDefaultCurrency;
},
allDateRanges() {
return datetimeConstants.allDateRanges;
return DateRange.all();
},
allAccounts() {
return this.accountsStore.allAccounts;
@@ -389,7 +389,7 @@ export default {
const maxTime = getUnixTimeBeforeUnixTime(getUnixTimeAfterUnixTime(minTime, 1, 'months'), 1, 'seconds');
const type = e.transactionType;
this.$router.push(`/transaction/list?type=${type}&dateType=${datetimeConstants.allDateRanges.Custom.type}&maxTime=${maxTime}&minTime=${minTime}`);
this.$router.push(`/transaction/list?type=${type}&dateType=${DateRange.Custom.type}&maxTime=${maxTime}&minTime=${minTime}`);
},
getDisplayCurrency(value, currencyCode) {
return this.$locale.formatAmountWithCurrency(this.settingsStore, this.userStore, value, currencyCode);
@@ -128,7 +128,7 @@
import { mapStores } from 'pinia';
import { useSettingsStore } from '@/stores/setting.js';
import datetimeConstants from '@/consts/datetime.js';
import { DateRangeScene } from '@/core/datetime.ts';
import statisticsConstants from '@/consts/statistics.js';
import AccountFilterSettingsCard from '@/views/desktop/common/cards/AccountFilterSettingsCard.vue';
@@ -154,13 +154,13 @@ export default {
return this.$locale.getAllCategoricalChartTypes();
},
allCategoricalChartDateRanges() {
return this.$locale.getAllDateRanges(datetimeConstants.allDateRangeScenes.Normal, false);
return this.$locale.getAllDateRanges(DateRangeScene.Normal, false);
},
allTrendChartTypes() {
return this.$locale.getAllTrendChartTypes();
},
allTrendChartDateRanges() {
return this.$locale.getAllDateRanges(datetimeConstants.allDateRangeScenes.TrendAnalysis, false);
return this.$locale.getAllDateRanges(DateRangeScene.TrendAnalysis, false);
},
defaultChartDataType: {
get: function () {
@@ -323,9 +323,9 @@ import { useAccountsStore } from '@/stores/account.js';
import { useTransactionCategoriesStore } from '@/stores/transactionCategory.js';
import { useStatisticsStore } from '@/stores/statistics.js';
import datetimeConstants from '@/consts/datetime.js';
import statisticsConstants from '@/consts/statistics.js';
import { DateRangeScene, DateRange } from '@/core/datetime.ts';
import { ThemeType } from '@/core/theme.ts';
import statisticsConstants from '@/consts/statistics.js';
import {
isDefined,
limitText,
@@ -525,13 +525,13 @@ export default {
return this.$locale.getAllStatisticsDateAggregationTypes();
},
allDateRanges() {
return datetimeConstants.allDateRanges;
return DateRange.all();
},
allDateRangesArray() {
if (this.queryAnalysisType === statisticsConstants.allAnalysisTypes.CategoricalAnalysis) {
return this.$locale.getAllDateRanges(datetimeConstants.allDateRangeScenes.Normal, true);
return this.$locale.getAllDateRanges(DateRangeScene.Normal, true);
} else if (this.queryAnalysisType === statisticsConstants.allAnalysisTypes.TrendAnalysis) {
return this.$locale.getAllDateRanges(datetimeConstants.allDateRangeScenes.TrendAnalysis, true);
return this.$locale.getAllDateRanges(DateRangeScene.TrendAnalysis, true);
} else {
return [];
}
@@ -670,7 +670,7 @@ export default {
if (filter.categoricalChartDateType !== self.query.categoricalChartDateType) {
needReload = true;
} else if (filter.categoricalChartDateType === datetimeConstants.allDateRanges.Custom.type) {
} else if (filter.categoricalChartDateType === DateRange.Custom.type) {
if (filter.categoricalChartStartTime !== self.query.categoricalChartStartTime
|| filter.categoricalChartEndTime !== self.query.categoricalChartEndTime) {
needReload = true;
@@ -689,7 +689,7 @@ export default {
if (filter.trendChartDateType !== self.query.trendChartDateType) {
needReload = true;
} else if (filter.trendChartDateType === datetimeConstants.allDateRanges.Custom.type) {
} else if (filter.trendChartDateType === DateRange.Custom.type) {
if (filter.trendChartStartYearMonth !== self.query.trendChartStartYearMonth
|| filter.trendChartEndYearMonth !== self.query.trendChartEndYearMonth) {
needReload = true;
@@ -913,7 +913,7 @@ export default {
let changed = false;
if (this.queryAnalysisType === statisticsConstants.allAnalysisTypes.CategoricalAnalysis) {
const chartDateType = getDateTypeByDateRange(startTime, endTime, this.firstDayOfWeek, datetimeConstants.allDateRangeScenes.Normal);
const chartDateType = getDateTypeByDateRange(startTime, endTime, this.firstDayOfWeek, DateRangeScene.Normal);
changed = this.statisticsStore.updateTransactionStatisticsFilter({
categoricalChartDateType: chartDateType,
@@ -923,7 +923,7 @@ export default {
this.showCustomDateRangeDialog = false;
} else if (this.queryAnalysisType === statisticsConstants.allAnalysisTypes.TrendAnalysis) {
const chartDateType = getDateTypeByDateRange(getYearMonthFirstUnixTime(startTime), getYearMonthLastUnixTime(endTime), this.firstDayOfWeek, datetimeConstants.allDateRangeScenes.TrendAnalysis);
const chartDateType = getDateTypeByDateRange(getYearMonthFirstUnixTime(startTime), getYearMonthLastUnixTime(endTime), this.firstDayOfWeek, DateRangeScene.TrendAnalysis);
changed = this.statisticsStore.updateTransactionStatisticsFilter({
trendChartDateType: chartDateType,
@@ -970,7 +970,7 @@ export default {
let changed = false;
if (this.queryAnalysisType === statisticsConstants.allAnalysisTypes.CategoricalAnalysis) {
const newDateRange = getShiftedDateRangeAndDateType(this.query.categoricalChartStartTime, this.query.categoricalChartEndTime, scale, this.firstDayOfWeek, datetimeConstants.allDateRangeScenes.Normal);
const newDateRange = getShiftedDateRangeAndDateType(this.query.categoricalChartStartTime, this.query.categoricalChartEndTime, scale, this.firstDayOfWeek, DateRangeScene.Normal);
changed = this.statisticsStore.updateTransactionStatisticsFilter({
categoricalChartDateType: newDateRange.dateType,
@@ -978,7 +978,7 @@ export default {
categoricalChartEndTime: newDateRange.maxTime
});
} else if (this.queryAnalysisType === statisticsConstants.allAnalysisTypes.TrendAnalysis) {
const newDateRange = getShiftedDateRangeAndDateType(getYearMonthFirstUnixTime(this.query.trendChartStartYearMonth), getYearMonthLastUnixTime(this.query.trendChartEndYearMonth), scale, this.firstDayOfWeek, datetimeConstants.allDateRangeScenes.TrendAnalysis);
const newDateRange = getShiftedDateRangeAndDateType(getYearMonthFirstUnixTime(this.query.trendChartStartYearMonth), getYearMonthLastUnixTime(this.query.trendChartEndYearMonth), scale, this.firstDayOfWeek, DateRangeScene.TrendAnalysis);
changed = this.statisticsStore.updateTransactionStatisticsFilter({
trendChartDateType: newDateRange.dateType,
+12 -12
View File
@@ -595,11 +595,11 @@ import { useTransactionTagsStore } from '@/stores/transactionTag.js';
import { useTransactionsStore } from '@/stores/transaction.js';
import { useTransactionTemplatesStore } from '@/stores/transactionTemplate.js';
import { DateRangeScene, DateRange } from '@/core/datetime.ts';
import { AccountType } from '@/core/account.ts';
import { TransactionType, TransactionTagFilterType } from '@/core/transaction.ts';
import { TemplateType } from '@/core/template.ts';
import numeralConstants from '@/consts/numeral.js';
import datetimeConstants from '@/consts/datetime.js';
import { isString, isNumber, getNameByKeyValue } from '@/lib/common.ts';
import logger from '@/lib/logger.js';
import {
@@ -746,10 +746,10 @@ export default {
return this.userStore.currentUserFirstDayOfWeek;
},
allDateRangesArray() {
return this.$locale.getAllDateRanges(datetimeConstants.allDateRangeScenes.Normal, true, !!this.accountsStore.getAccountStatementDate(this.query.accountIds));
return this.$locale.getAllDateRanges(DateRangeScene.Normal, true, !!this.accountsStore.getAccountStatementDate(this.query.accountIds));
},
allDateRanges() {
return datetimeConstants.allDateRanges;
return DateRange.all();
},
recentDateRangeType: {
get: function () {
@@ -1118,7 +1118,7 @@ export default {
let dateRange = getDateRangeByDateType(query.dateType ? parseInt(query.dateType) : undefined, this.firstDayOfWeek);
if (!dateRange &&
(datetimeConstants.allBillingCycleDateRangesMap[query.dateType] || query.dateType === datetimeConstants.allDateRanges.Custom.type.toString()) &&
(DateRange.isBillingCycle(query.dateType) || query.dateType === DateRange.Custom.type.toString()) &&
parseInt(query.maxTime) > 0 && parseInt(query.minTime) > 0) {
dateRange = {
dateType: parseInt(query.dateType),
@@ -1208,18 +1208,18 @@ export default {
});
},
shiftDateRange(startTime, endTime, scale) {
if (this.recentDateRangeType === datetimeConstants.allDateRanges.All.type) {
if (this.recentDateRangeType === DateRange.All.type) {
return;
}
let newDateRange = null;
if (datetimeConstants.allBillingCycleDateRangesMap[this.query.dateType] || this.query.dateType === this.allDateRanges.Custom.type) {
newDateRange = getShiftedDateRangeAndDateTypeForBillingCycle(startTime, endTime, scale, this.firstDayOfWeek, datetimeConstants.allDateRangeScenes.Normal, this.accountsStore.getAccountStatementDate(this.query.accountIds));
if (DateRange.isBillingCycle(this.query.dateType) || this.query.dateType === this.allDateRanges.Custom.type) {
newDateRange = getShiftedDateRangeAndDateTypeForBillingCycle(startTime, endTime, scale, this.firstDayOfWeek, DateRangeScene.Normal, this.accountsStore.getAccountStatementDate(this.query.accountIds));
}
if (!newDateRange) {
newDateRange = getShiftedDateRangeAndDateType(startTime, endTime, scale, this.firstDayOfWeek, datetimeConstants.allDateRangeScenes.Normal);
newDateRange = getShiftedDateRangeAndDateType(startTime, endTime, scale, this.firstDayOfWeek, DateRangeScene.Normal);
}
const changed = this.transactionsStore.updateTransactionListFilter({
@@ -1237,14 +1237,14 @@ export default {
},
changeDateFilter(dateRange) {
if (isNumber(dateRange)) {
if (datetimeConstants.allBillingCycleDateRangesMap[dateRange]) {
if (DateRange.isBillingCycle(dateRange)) {
dateRange = getDateRangeByBillingCycleDateType(dateRange, this.firstDayOfWeek, this.accountsStore.getAccountStatementDate(this.query.accountIds));
} else {
dateRange = getDateRangeByDateType(dateRange, this.firstDayOfWeek);
}
}
if (dateRange.dateType === datetimeConstants.allDateRanges.Custom.type &&
if (dateRange.dateType === DateRange.Custom.type &&
!dateRange.minTime && !dateRange.maxTime) { // Custom
if (!this.query.minTime || !this.query.maxTime) {
this.customMaxDatetime = getActualUnixTimeForStore(getCurrentUnixTime(), this.currentTimezoneOffsetMinutes, getBrowserTimezoneOffsetMinutes());
@@ -1280,10 +1280,10 @@ export default {
return;
}
let dateType = getDateTypeByBillingCycleDateRange(minTime, maxTime, this.firstDayOfWeek, datetimeConstants.allDateRangeScenes.Normal, this.accountsStore.getAccountStatementDate(this.query.accountIds));
let dateType = getDateTypeByBillingCycleDateRange(minTime, maxTime, this.firstDayOfWeek, DateRangeScene.Normal, this.accountsStore.getAccountStatementDate(this.query.accountIds));
if (!dateType) {
dateType = getDateTypeByDateRange(minTime, maxTime, this.firstDayOfWeek, datetimeConstants.allDateRangeScenes.Normal);
dateType = getDateTypeByDateRange(minTime, maxTime, this.firstDayOfWeek, DateRangeScene.Normal);
}
if (this.query.dateType === dateType && this.query.maxTime === maxTime && this.query.minTime === minTime) {
@@ -337,7 +337,7 @@ import { useUserStore } from '@/stores/user.js';
import { useAccountsStore } from '@/stores/account.js';
import { useOverviewStore } from '@/stores/overview.js';
import datetimeConstants from '@/consts/datetime.js';
import { WeekDay } from '@/core/datetime.ts';
import { SUPPORTED_IMAGE_EXTENSIONS } from '@/consts/file.ts';
import { getNameByKeyValue } from '@/lib/common.ts';
import { generateRandomUUID } from '@/lib/misc.ts';
@@ -354,7 +354,7 @@ export default {
data() {
const self = this;
const defaultFirstDayOfWeekName = self.$locale.getDefaultFirstDayOfWeek();
const defaultFirstDayOfWeek = datetimeConstants.allWeekDays[defaultFirstDayOfWeekName] ? datetimeConstants.allWeekDays[defaultFirstDayOfWeekName].type : datetimeConstants.defaultFirstDayOfWeek;
const defaultFirstDayOfWeek = WeekDay.parse(defaultFirstDayOfWeekName) ? WeekDay.parse(defaultFirstDayOfWeekName).type : WeekDay.DefaultFirstDay.type;
return {
newProfile: {
+2 -2
View File
@@ -207,7 +207,7 @@ import { useUserStore } from '@/stores/user.js';
import { useTransactionTemplatesStore } from '@/stores/transactionTemplate.js';
import { useOverviewStore } from '@/stores/overview.js';
import datetimeConstants from '@/consts/datetime.js';
import { DateRange } from '@/core/datetime.ts';
import { TemplateType } from '@/core/template.ts';
import { formatUnixTime } from '@/lib/datetime.js';
@@ -239,7 +239,7 @@ export default {
return allTemplates[TemplateType.Normal.type] || [];
},
allDateRanges() {
return datetimeConstants.allDateRanges;
return DateRange.all();
},
displayDateRange() {
const self = this;
+3 -3
View File
@@ -91,7 +91,7 @@
import { mapStores } from 'pinia';
import { useSettingsStore } from '@/stores/setting.js';
import datetimeConstants from '@/consts/datetime.js';
import { DateRangeScene } from '@/core/datetime.ts';
import statisticsConstants from '@/consts/statistics.js';
export default {
@@ -110,13 +110,13 @@ export default {
return this.$locale.getAllCategoricalChartTypes();
},
allCategoricalChartDateRanges() {
return this.$locale.getAllDateRanges(datetimeConstants.allDateRangeScenes.Normal, false);
return this.$locale.getAllDateRanges(DateRangeScene.Normal, false);
},
allTrendChartTypes() {
return this.$locale.getAllTrendChartTypes();
},
allTrendChartDateRanges() {
return this.$locale.getAllDateRanges(datetimeConstants.allDateRangeScenes.TrendAnalysis, false);
return this.$locale.getAllDateRanges(DateRangeScene.TrendAnalysis, false);
},
defaultChartDataType: {
get: function () {
@@ -331,7 +331,7 @@ import { useAccountsStore } from '@/stores/account.js';
import { useTransactionCategoriesStore } from '@/stores/transactionCategory.js';
import { useStatisticsStore } from '@/stores/statistics.js';
import datetimeConstants from '@/consts/datetime.js';
import { DateRangeScene, DateRange } from '@/core/datetime.ts';
import statisticsConstants from '@/consts/statistics.js';
import { getNameByKeyValue, limitText } from '@/lib/common.ts';
import { formatPercent } from '@/lib/numeral.js';
@@ -458,13 +458,13 @@ export default {
return this.$locale.getAllStatisticsDateAggregationTypes();
},
allDateRanges() {
return datetimeConstants.allDateRanges;
return DateRange.all();
},
allDateRangesArray() {
if (this.analysisType === statisticsConstants.allAnalysisTypes.CategoricalAnalysis) {
return this.$locale.getAllDateRanges(datetimeConstants.allDateRangeScenes.Normal, true);
return this.$locale.getAllDateRanges(DateRangeScene.Normal, true);
} else if (this.analysisType === statisticsConstants.allAnalysisTypes.TrendAnalysis) {
return this.$locale.getAllDateRanges(datetimeConstants.allDateRangeScenes.TrendAnalysis, true);
return this.$locale.getAllDateRanges(DateRangeScene.TrendAnalysis, true);
} else {
return [];
}
@@ -711,7 +711,7 @@ export default {
let changed = false;
if (this.analysisType === statisticsConstants.allAnalysisTypes.CategoricalAnalysis) {
const chartDateType = getDateTypeByDateRange(startTime, endTime, this.firstDayOfWeek, datetimeConstants.allDateRangeScenes.Normal);
const chartDateType = getDateTypeByDateRange(startTime, endTime, this.firstDayOfWeek, DateRangeScene.Normal);
changed = this.statisticsStore.updateTransactionStatisticsFilter({
categoricalChartDateType: chartDateType,
@@ -721,7 +721,7 @@ export default {
this.showCustomDateRangeSheet = false;
} else if (this.analysisType === statisticsConstants.allAnalysisTypes.TrendAnalysis) {
const chartDateType = getDateTypeByDateRange(getYearMonthFirstUnixTime(startTime), getYearMonthLastUnixTime(endTime), this.firstDayOfWeek, datetimeConstants.allDateRangeScenes.TrendAnalysis);
const chartDateType = getDateTypeByDateRange(getYearMonthFirstUnixTime(startTime), getYearMonthLastUnixTime(endTime), this.firstDayOfWeek, DateRangeScene.TrendAnalysis);
this.statisticsStore.updateTransactionStatisticsFilter({
trendChartDateType: chartDateType,
@@ -766,7 +766,7 @@ export default {
let changed = false;
if (this.analysisType === statisticsConstants.allAnalysisTypes.CategoricalAnalysis) {
const newDateRange = getShiftedDateRangeAndDateType(query.categoricalChartStartTime, query.categoricalChartEndTime, scale, this.firstDayOfWeek, datetimeConstants.allDateRangeScenes.Normal);
const newDateRange = getShiftedDateRangeAndDateType(query.categoricalChartStartTime, query.categoricalChartEndTime, scale, this.firstDayOfWeek, DateRangeScene.Normal);
changed = this.statisticsStore.updateTransactionStatisticsFilter({
categoricalChartDateType: newDateRange.dateType,
@@ -774,7 +774,7 @@ export default {
categoricalChartEndTime: newDateRange.maxTime
});
} else if (this.analysisType === statisticsConstants.allAnalysisTypes.TrendAnalysis) {
const newDateRange = getShiftedDateRangeAndDateType(getYearMonthFirstUnixTime(query.trendChartStartYearMonth), getYearMonthLastUnixTime(query.trendChartEndYearMonth), scale, this.firstDayOfWeek, datetimeConstants.allDateRangeScenes.TrendAnalysis);
const newDateRange = getShiftedDateRangeAndDateType(getYearMonthFirstUnixTime(query.trendChartStartYearMonth), getYearMonthLastUnixTime(query.trendChartEndYearMonth), scale, this.firstDayOfWeek, DateRangeScene.TrendAnalysis);
changed = this.statisticsStore.updateTransactionStatisticsFilter({
trendChartDateType: newDateRange.dateType,
+10 -10
View File
@@ -528,10 +528,10 @@ import { useTransactionCategoriesStore } from '@/stores/transactionCategory.js';
import { useTransactionTagsStore } from '@/stores/transactionTag.js';
import { useTransactionsStore } from '@/stores/transaction.js';
import { DateRangeScene, DateRange } from '@/core/datetime.ts';
import { AccountType } from '@/core/account.ts';
import { TransactionType } from '@/core/transaction.ts';
import numeralConstants from '@/consts/numeral.js';
import datetimeConstants from '@/consts/datetime.js';
import { getNameByKeyValue } from '@/lib/common.ts';
import {
getCurrentUnixTime,
@@ -737,10 +737,10 @@ export default {
return this.transactionTagsStore.allAvailableTagsCount;
},
allDateRanges() {
return datetimeConstants.allDateRanges;
return DateRange.all();
},
allDateRangesArray() {
return this.$locale.getAllDateRanges(datetimeConstants.allDateRangeScenes.Normal, true, !!this.accountsStore.getAccountStatementDate(this.query.accountIds));
return this.$locale.getAllDateRanges(DateRangeScene.Normal, true, !!this.accountsStore.getAccountStatementDate(this.query.accountIds));
},
showTotalAmountInTransactionListPage() {
return this.settingsStore.appSettings.showTotalAmountInTransactionListPage;
@@ -756,7 +756,7 @@ export default {
let dateRange = getDateRangeByDateType(query.dateType ? parseInt(query.dateType) : undefined, self.firstDayOfWeek);
if (!dateRange &&
(datetimeConstants.allBillingCycleDateRangesMap[query.dateType] || query.dateType === datetimeConstants.allDateRanges.Custom.type.toString()) &&
(DateRange.isBillingCycle(query.dateType) || query.dateType === DateRange.Custom.type.toString()) &&
parseInt(query.maxTime) > 0 && parseInt(query.minTime) > 0) {
dateRange = {
dateType: parseInt(query.dateType),
@@ -885,7 +885,7 @@ export default {
let dateRange = null;
if (datetimeConstants.allBillingCycleDateRangesMap[dateType]) {
if (DateRange.isBillingCycle(dateType)) {
dateRange = getDateRangeByBillingCycleDateType(dateType, this.firstDayOfWeek, this.accountsStore.getAccountStatementDate(this.query.accountIds));
} else {
dateRange = getDateRangeByDateType(dateType, this.firstDayOfWeek);
@@ -912,10 +912,10 @@ export default {
return;
}
let dateType = getDateTypeByBillingCycleDateRange(minTime, maxTime, this.firstDayOfWeek, datetimeConstants.allDateRangeScenes.Normal, this.accountsStore.getAccountStatementDate(this.query.accountIds));
let dateType = getDateTypeByBillingCycleDateRange(minTime, maxTime, this.firstDayOfWeek, DateRangeScene.Normal, this.accountsStore.getAccountStatementDate(this.query.accountIds));
if (!dateType) {
dateType = getDateTypeByDateRange(minTime, maxTime, this.firstDayOfWeek, datetimeConstants.allDateRangeScenes.Normal);
dateType = getDateTypeByDateRange(minTime, maxTime, this.firstDayOfWeek, DateRangeScene.Normal);
}
const changed = this.transactionsStore.updateTransactionListFilter({
@@ -1124,12 +1124,12 @@ export default {
let newDateRange = null;
if (datetimeConstants.allBillingCycleDateRangesMap[this.query.dateType] || this.query.dateType === this.allDateRanges.Custom.type) {
newDateRange = getShiftedDateRangeAndDateTypeForBillingCycle(minTime, maxTime, scale, this.firstDayOfWeek, datetimeConstants.allDateRangeScenes.Normal, this.accountsStore.getAccountStatementDate(this.query.accountIds));
if (DateRange.isBillingCycle(this.query.dateType) || this.query.dateType === this.allDateRanges.Custom.type) {
newDateRange = getShiftedDateRangeAndDateTypeForBillingCycle(minTime, maxTime, scale, this.firstDayOfWeek, DateRangeScene.Normal, this.accountsStore.getAccountStatementDate(this.query.accountIds));
}
if (!newDateRange) {
newDateRange = getShiftedDateRangeAndDateType(minTime, maxTime, scale, this.firstDayOfWeek, datetimeConstants.allDateRangeScenes.Normal);
newDateRange = getShiftedDateRangeAndDateType(minTime, maxTime, scale, this.firstDayOfWeek, DateRangeScene.Normal);
}
const changed = this.transactionsStore.updateTransactionListFilter({