mirror of
https://github.com/mayswind/ezbookkeeping.git
synced 2026-05-16 07:57:33 +08:00
use the daylight saving time zone as default time zone rather than the current standard time zone during the DST
This commit is contained in:
@@ -17,6 +17,7 @@ import type { TransactionReconciliationStatementResponseItem } from '@/models/tr
|
||||
import { isArray } from '@/lib/common.ts';
|
||||
import { sumAmounts } from '@/lib/numeral.ts';
|
||||
import {
|
||||
parseDateTimeFromUnixTime,
|
||||
getGregorianCalendarYearAndMonthFromUnixTime,
|
||||
getYearFirstUnixTimeBySpecifiedUnixTime,
|
||||
getQuarterFirstUnixTimeBySpecifiedUnixTime,
|
||||
@@ -52,11 +53,11 @@ export interface CommonAccountBalanceTrendsChartProps {
|
||||
|
||||
export function useAccountBalanceTrendsChartBase(props: CommonAccountBalanceTrendsChartProps) {
|
||||
const {
|
||||
formatUnixTimeToShortDate,
|
||||
formatUnixTimeToGregorianLikeShortYear,
|
||||
formatUnixTimeToGregorianLikeShortYearMonth,
|
||||
formatUnixTimeToGregorianLikeYearQuarter,
|
||||
formatUnixTimeToGregorianLikeFiscalYear
|
||||
formatDateTimeToShortDate,
|
||||
formatDateTimeToGregorianLikeShortYear,
|
||||
formatDateTimeToGregorianLikeShortYearMonth,
|
||||
formatDateTimeToGregorianLikeYearQuarter,
|
||||
formatDateTimeToGregorianLikeFiscalYear
|
||||
} = useI18n();
|
||||
|
||||
const dataDateRange = computed<AccountBalanceUnixTimeAndBalanceRange | null>(() => {
|
||||
@@ -150,19 +151,20 @@ export function useAccountBalanceTrendsChartBase(props: CommonAccountBalanceTren
|
||||
|
||||
for (const dateRange of allDateRanges.value) {
|
||||
const dataItems = dayDataItemsMap[dateRange.minUnixTime];
|
||||
const minDateTime = parseDateTimeFromUnixTime(dateRange.minUnixTime);
|
||||
|
||||
let displayDate = '';
|
||||
|
||||
if (props.dateAggregationType === ChartDateAggregationType.Year.type) {
|
||||
displayDate = formatUnixTimeToGregorianLikeShortYear(dateRange.minUnixTime);
|
||||
displayDate = formatDateTimeToGregorianLikeShortYear(minDateTime);
|
||||
} else if (props.dateAggregationType === ChartDateAggregationType.FiscalYear.type) {
|
||||
displayDate = formatUnixTimeToGregorianLikeFiscalYear(dateRange.minUnixTime);
|
||||
displayDate = formatDateTimeToGregorianLikeFiscalYear(minDateTime);
|
||||
} else if (props.dateAggregationType === ChartDateAggregationType.Quarter.type) {
|
||||
displayDate = formatUnixTimeToGregorianLikeYearQuarter(dateRange.minUnixTime);
|
||||
displayDate = formatDateTimeToGregorianLikeYearQuarter(minDateTime);
|
||||
} else if (props.dateAggregationType === ChartDateAggregationType.Month.type) {
|
||||
displayDate = formatUnixTimeToGregorianLikeShortYearMonth(dateRange.minUnixTime);
|
||||
displayDate = formatDateTimeToGregorianLikeShortYearMonth(minDateTime);
|
||||
} else if (props.dateAggregationType === ChartDateAggregationType.Day.type) {
|
||||
displayDate = formatUnixTimeToShortDate(dateRange.minUnixTime);
|
||||
displayDate = formatDateTimeToShortDate(minDateTime);
|
||||
} else {
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -1,16 +1,23 @@
|
||||
import { ref, computed } from 'vue';
|
||||
|
||||
import { type TimeRangeAndDateType, type PresetDateRange, type UnixTimeRange, type WeekDayValue, DateRange } from '@/core/datetime.ts';
|
||||
import {
|
||||
type DateTime,
|
||||
type UnixTimeRange,
|
||||
type TimeRangeAndDateType,
|
||||
type PresetDateRange,
|
||||
type WeekDayValue,
|
||||
DateRange,
|
||||
} from '@/core/datetime.ts';
|
||||
|
||||
import {
|
||||
getCurrentUnixTime,
|
||||
getLocalDatetimeFromUnixTime,
|
||||
getUnixTimeFromLocalDatetime,
|
||||
getTodayFirstUnixTime,
|
||||
getDummyUnixTimeForLocalUsage,
|
||||
getActualUnixTimeForStore,
|
||||
getTimezoneOffsetMinutes,
|
||||
getBrowserTimezoneOffsetMinutes,
|
||||
getSameDateTimeWithCurrentTimezone,
|
||||
getSameDateTimeWithBrowserTimezone,
|
||||
parseDateTimeFromUnixTime,
|
||||
parseDateTimeFromUnixTimeWithBrowserTimezone,
|
||||
getDateRangeByDateType
|
||||
} from '@/lib/datetime.ts';
|
||||
|
||||
@@ -45,23 +52,21 @@ function getDateRangeFromProps(props: CommonDateRangeSelectionProps): { minDate:
|
||||
}
|
||||
|
||||
export function useDateRangeSelectionBase(props: CommonDateRangeSelectionProps) {
|
||||
const { tt, formatUnixTimeToLongDateTime } = useI18n();
|
||||
const { tt, formatDateTimeToLongDateTime } = useI18n();
|
||||
const userStore = useUserStore();
|
||||
const { minDate, maxDate } = getDateRangeFromProps(props);
|
||||
|
||||
const dateRange = ref<Date[]>([
|
||||
getLocalDatetimeFromUnixTime(getDummyUnixTimeForLocalUsage(minDate, getTimezoneOffsetMinutes(), getBrowserTimezoneOffsetMinutes())),
|
||||
getLocalDatetimeFromUnixTime(getDummyUnixTimeForLocalUsage(maxDate, getTimezoneOffsetMinutes(), getBrowserTimezoneOffsetMinutes()))
|
||||
getLocalDatetimeFromSameDateTimeOfUnixTime(minDate),
|
||||
getLocalDatetimeFromSameDateTimeOfUnixTime(maxDate)
|
||||
]);
|
||||
|
||||
const firstDayOfWeek = computed<WeekDayValue>(() => userStore.currentUserFirstDayOfWeek);
|
||||
const beginDateTime = computed<string>(() => {
|
||||
const actualBeginUnixTime = getActualUnixTimeForStore(getUnixTimeFromLocalDatetime(dateRange.value[0] as Date), getTimezoneOffsetMinutes(), getBrowserTimezoneOffsetMinutes());
|
||||
return formatUnixTimeToLongDateTime(actualBeginUnixTime);
|
||||
return formatDateTimeToLongDateTime(getDateTimeFromSameDateTimeOfLocalDatetime(dateRange.value[0] as Date));
|
||||
});
|
||||
const endDateTime = computed<string>(() => {
|
||||
const actualEndUnixTime = getActualUnixTimeForStore(getUnixTimeFromLocalDatetime(dateRange.value[1] as Date), getTimezoneOffsetMinutes(), getBrowserTimezoneOffsetMinutes());
|
||||
return formatUnixTimeToLongDateTime(actualEndUnixTime);
|
||||
return formatDateTimeToLongDateTime(getDateTimeFromSameDateTimeOfLocalDatetime(dateRange.value[1] as Date));
|
||||
});
|
||||
const presetRanges = computed<PresetDateRange[]>(() => {
|
||||
const presetRanges:PresetDateRange[] = [];
|
||||
@@ -82,8 +87,8 @@ export function useDateRangeSelectionBase(props: CommonDateRangeSelectionProps)
|
||||
presetRanges.push({
|
||||
label: tt(dateRangeType.name),
|
||||
value: [
|
||||
getLocalDatetimeFromUnixTime(getDummyUnixTimeForLocalUsage(dateRange.minTime, getTimezoneOffsetMinutes(), getBrowserTimezoneOffsetMinutes())),
|
||||
getLocalDatetimeFromUnixTime(getDummyUnixTimeForLocalUsage(dateRange.maxTime, getTimezoneOffsetMinutes(), getBrowserTimezoneOffsetMinutes()))
|
||||
getLocalDatetimeFromSameDateTimeOfUnixTime(dateRange.minTime),
|
||||
getLocalDatetimeFromSameDateTimeOfUnixTime(dateRange.maxTime)
|
||||
]
|
||||
});
|
||||
});
|
||||
@@ -91,6 +96,14 @@ export function useDateRangeSelectionBase(props: CommonDateRangeSelectionProps)
|
||||
return presetRanges;
|
||||
});
|
||||
|
||||
function getLocalDatetimeFromSameDateTimeOfUnixTime(unixTime: number): Date {
|
||||
return getLocalDatetimeFromUnixTime(getSameDateTimeWithBrowserTimezone(parseDateTimeFromUnixTime(unixTime)).getUnixTime());
|
||||
}
|
||||
|
||||
function getDateTimeFromSameDateTimeOfLocalDatetime(localDatetime: Date): DateTime {
|
||||
return getSameDateTimeWithCurrentTimezone(parseDateTimeFromUnixTimeWithBrowserTimezone(getUnixTimeFromLocalDatetime(localDatetime)));
|
||||
}
|
||||
|
||||
function getFinalDateRange(): UnixTimeRange | null {
|
||||
if (!dateRange.value[0] || !dateRange.value[1]) {
|
||||
return null;
|
||||
@@ -99,16 +112,13 @@ export function useDateRangeSelectionBase(props: CommonDateRangeSelectionProps)
|
||||
const currentMinDate = dateRange.value[0];
|
||||
const currentMaxDate = dateRange.value[1];
|
||||
|
||||
let minUnixTime = getUnixTimeFromLocalDatetime(currentMinDate);
|
||||
let maxUnixTime = getUnixTimeFromLocalDatetime(currentMaxDate);
|
||||
const minUnixTime = getDateTimeFromSameDateTimeOfLocalDatetime(currentMinDate).getUnixTime();
|
||||
const maxUnixTime = getDateTimeFromSameDateTimeOfLocalDatetime(currentMaxDate).getUnixTime();
|
||||
|
||||
if (minUnixTime < 0 || maxUnixTime < 0) {
|
||||
throw new Error('Date is too early');
|
||||
}
|
||||
|
||||
minUnixTime = getActualUnixTimeForStore(minUnixTime, getTimezoneOffsetMinutes(), getBrowserTimezoneOffsetMinutes());
|
||||
maxUnixTime = getActualUnixTimeForStore(maxUnixTime, getTimezoneOffsetMinutes(), getBrowserTimezoneOffsetMinutes());
|
||||
|
||||
return {
|
||||
minUnixTime,
|
||||
maxUnixTime
|
||||
@@ -123,6 +133,8 @@ export function useDateRangeSelectionBase(props: CommonDateRangeSelectionProps)
|
||||
endDateTime,
|
||||
presetRanges,
|
||||
// functions
|
||||
getLocalDatetimeFromSameDateTimeOfUnixTime,
|
||||
getDateTimeFromSameDateTimeOfLocalDatetime,
|
||||
getFinalDateRange
|
||||
};
|
||||
}
|
||||
|
||||
@@ -5,6 +5,15 @@ import { useI18n } from '@/locales/helpers.ts';
|
||||
import { type NameValue } from '@/core/base.ts';
|
||||
import { NumeralSystem } from '@/core/numeral.ts';
|
||||
|
||||
import {
|
||||
getLocalDatetimeFromUnixTime,
|
||||
getUnixTimeFromLocalDatetime,
|
||||
getSameDateTimeWithBrowserTimezone,
|
||||
getSameDateTimeWithTimezoneOffset,
|
||||
parseDateTimeFromUnixTimeWithBrowserTimezone,
|
||||
parseDateTimeFromUnixTimeWithTimezoneOffset
|
||||
} from '@/lib/datetime.ts';
|
||||
|
||||
export interface TimePickerValue {
|
||||
value: string;
|
||||
itemsIndex: number;
|
||||
@@ -30,6 +39,14 @@ export function useDateTimeSelectionBase() {
|
||||
const numeralSystem = computed<NumeralSystem>(() => getCurrentNumeralSystemType());
|
||||
const meridiemItems = computed<NameValue[]>(() => getAllMeridiemIndicators());
|
||||
|
||||
function getLocalDatetimeFromSameDateTimeOfUnixTime(unixTime: number, utcOffset: number): Date {
|
||||
return getLocalDatetimeFromUnixTime(getSameDateTimeWithBrowserTimezone(parseDateTimeFromUnixTimeWithTimezoneOffset(unixTime, utcOffset)).getUnixTime());
|
||||
}
|
||||
|
||||
function getUnixTimeFromSameDateTimeOfLocalDatetime(localDatetime: Date, utcOffset: number): number {
|
||||
return getSameDateTimeWithTimezoneOffset(parseDateTimeFromUnixTimeWithBrowserTimezone(getUnixTimeFromLocalDatetime(localDatetime)), utcOffset).getUnixTime();
|
||||
}
|
||||
|
||||
function getDisplayTimeValue(value: number, forceTwoDigits: boolean): string {
|
||||
let textualValue = value.toString();
|
||||
|
||||
@@ -89,6 +106,8 @@ export function useDateTimeSelectionBase() {
|
||||
// computed
|
||||
meridiemItems,
|
||||
// functions
|
||||
getLocalDatetimeFromSameDateTimeOfUnixTime,
|
||||
getUnixTimeFromSameDateTimeOfLocalDatetime,
|
||||
getDisplayTimeValue,
|
||||
generateAllHours,
|
||||
generateAllMinutesOrSeconds
|
||||
|
||||
@@ -7,6 +7,7 @@ import {
|
||||
getYear0BasedMonthObjectFromString,
|
||||
getYearMonthStringFromYear0BasedMonthObject,
|
||||
getCurrentUnixTime,
|
||||
parseDateTimeFromUnixTime,
|
||||
getThisYearFirstUnixTime,
|
||||
getYearMonthFirstUnixTime,
|
||||
getYearMonthLastUnixTime
|
||||
@@ -49,7 +50,7 @@ function getMonthRangeFromProps(props: CommonMonthRangeSelectionProps): { minDat
|
||||
}
|
||||
|
||||
export function useMonthRangeSelectionBase(props: CommonMonthRangeSelectionProps) {
|
||||
const { formatUnixTimeToGregorianLikeLongYearMonth } = useI18n();
|
||||
const { formatDateTimeToGregorianLikeLongYearMonth } = useI18n();
|
||||
const { minDate, maxDate } = getMonthRangeFromProps(props);
|
||||
|
||||
const dateRange = ref<Year0BasedMonth[]>([
|
||||
@@ -57,8 +58,8 @@ export function useMonthRangeSelectionBase(props: CommonMonthRangeSelectionProps
|
||||
maxDate
|
||||
]);
|
||||
|
||||
const beginDateTime = computed<string>(() => formatUnixTimeToGregorianLikeLongYearMonth(getYearMonthFirstUnixTime(dateRange.value[0] as Year0BasedMonth)));
|
||||
const endDateTime = computed<string>(() => formatUnixTimeToGregorianLikeLongYearMonth(getYearMonthLastUnixTime(dateRange.value[1] as Year0BasedMonth)));
|
||||
const beginDateTime = computed<string>(() => formatDateTimeToGregorianLikeLongYearMonth(parseDateTimeFromUnixTime(getYearMonthFirstUnixTime(dateRange.value[0] as Year0BasedMonth))));
|
||||
const endDateTime = computed<string>(() => formatDateTimeToGregorianLikeLongYearMonth(parseDateTimeFromUnixTime(getYearMonthLastUnixTime(dateRange.value[1] as Year0BasedMonth))));
|
||||
|
||||
function getFinalMonthRange(): { minYearMonth: TextualYearMonth | '', maxYearMonth: TextualYearMonth | '' } | null {
|
||||
if (!dateRange.value[0] || !dateRange.value[1]) {
|
||||
|
||||
@@ -88,9 +88,9 @@ const {
|
||||
getCurrentNumeralSystemType,
|
||||
isLongDateMonthAfterYear,
|
||||
isLongTime24HourFormat,
|
||||
getCalendarDisplayShortYearFromUnixTime,
|
||||
getCalendarDisplayShortMonthFromUnixTime,
|
||||
getCalendarDisplayDayOfMonthFromUnixTime,
|
||||
getCalendarDisplayShortYearFromDateTime,
|
||||
getCalendarDisplayShortMonthFromDateTime,
|
||||
getCalendarDisplayDayOfMonthFromDateTime,
|
||||
getCalendarAlternateDate
|
||||
} = useI18n();
|
||||
|
||||
@@ -138,21 +138,21 @@ function switchView(viewType: MenuView): void {
|
||||
}
|
||||
|
||||
function getDisplayYear(year: number): string {
|
||||
return getCalendarDisplayShortYearFromUnixTime(getYearMonthDayDateTime(year, 1, 1).getUnixTime(), actualNumeralSystem.value);
|
||||
return getCalendarDisplayShortYearFromDateTime(getYearMonthDayDateTime(year, 1, 1), actualNumeralSystem.value);
|
||||
}
|
||||
|
||||
function getDisplayMonth(month: number): string {
|
||||
if (isArray(dateTime.value)) {
|
||||
return getCalendarDisplayShortMonthFromUnixTime(getYearMonthDayDateTime(dateTime.value[0]!.getFullYear(), month + 1, 1).getUnixTime(), actualNumeralSystem.value);
|
||||
return getCalendarDisplayShortMonthFromDateTime(getYearMonthDayDateTime(dateTime.value[0]!.getFullYear(), month + 1, 1), actualNumeralSystem.value);
|
||||
} else if (dateTime.value) {
|
||||
return getCalendarDisplayShortMonthFromUnixTime(getYearMonthDayDateTime(dateTime.value.getFullYear(), month + 1, 1).getUnixTime(), actualNumeralSystem.value);
|
||||
return getCalendarDisplayShortMonthFromDateTime(getYearMonthDayDateTime(dateTime.value.getFullYear(), month + 1, 1), actualNumeralSystem.value);
|
||||
} else {
|
||||
return getCalendarDisplayShortMonthFromUnixTime(getYearMonthDayDateTime(new Date().getFullYear(), month + 1, 1).getUnixTime(), actualNumeralSystem.value);
|
||||
return getCalendarDisplayShortMonthFromDateTime(getYearMonthDayDateTime(new Date().getFullYear(), month + 1, 1), actualNumeralSystem.value);
|
||||
}
|
||||
}
|
||||
|
||||
function getDisplayDay(date: Date): string {
|
||||
return getCalendarDisplayDayOfMonthFromUnixTime(getYearMonthDayDateTime(date.getFullYear(), date.getMonth() + 1, date.getDate()).getUnixTime(), actualNumeralSystem.value);
|
||||
return getCalendarDisplayDayOfMonthFromDateTime(getYearMonthDayDateTime(date.getFullYear(), date.getMonth() + 1, date.getDate()), actualNumeralSystem.value);
|
||||
}
|
||||
|
||||
defineExpose({
|
||||
|
||||
@@ -54,8 +54,8 @@ const emit = defineEmits<{
|
||||
|
||||
const {
|
||||
isLongDateMonthAfterYear,
|
||||
getCalendarDisplayShortYearFromUnixTime,
|
||||
getCalendarDisplayShortMonthFromUnixTime
|
||||
getCalendarDisplayShortYearFromDateTime,
|
||||
getCalendarDisplayShortMonthFromDateTime
|
||||
} = useI18n();
|
||||
|
||||
const yearRange = getAllowedYearRange();
|
||||
@@ -96,14 +96,14 @@ function getYear0BasedMonthFromMonthSelectionValue(value: MonthSelectionValue):
|
||||
}
|
||||
|
||||
function getDisplayYear(year: number): string {
|
||||
return getCalendarDisplayShortYearFromUnixTime(getYearMonthDayDateTime(year, 1, 1).getUnixTime());
|
||||
return getCalendarDisplayShortYearFromDateTime(getYearMonthDayDateTime(year, 1, 1));
|
||||
}
|
||||
|
||||
function getDisplayMonth(month: number): string {
|
||||
if (isArray(dateTime.value)) {
|
||||
return getCalendarDisplayShortMonthFromUnixTime(getYearMonthDayDateTime(dateTime.value[0]!.year, month + 1, 1).getUnixTime());
|
||||
return getCalendarDisplayShortMonthFromDateTime(getYearMonthDayDateTime(dateTime.value[0]!.year, month + 1, 1));
|
||||
} else {
|
||||
return getCalendarDisplayShortMonthFromUnixTime(getYearMonthDayDateTime(dateTime.value.year, month + 1, 1).getUnixTime());
|
||||
return getCalendarDisplayShortMonthFromDateTime(getYearMonthDayDateTime(dateTime.value.year, month + 1, 1));
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
@@ -38,14 +38,7 @@ import type { CalendarAlternateDate, TextualYearMonthDay, WeekDayValue } from '@
|
||||
import { INCOMPLETE_AMOUNT_SUFFIX } from '@/consts/numeral.ts';
|
||||
|
||||
import { arrangeArrayWithNewStartIndex } from '@/lib/common.ts';
|
||||
import {
|
||||
getTimezoneOffsetMinutes,
|
||||
getBrowserTimezoneOffsetMinutes,
|
||||
getUnixTimeFromLocalDatetime,
|
||||
getActualUnixTimeForStore,
|
||||
getYearMonthDayDateTime,
|
||||
parseDateTimeFromUnixTime
|
||||
} from '@/lib/datetime.ts';
|
||||
import { getYearMonthDayDateTime } from '@/lib/datetime.ts';
|
||||
|
||||
const props = defineProps<{
|
||||
modelValue: TextualYearMonthDay | '';
|
||||
@@ -67,7 +60,7 @@ const emit = defineEmits<{
|
||||
const {
|
||||
getAllLongWeekdayNames,
|
||||
getAllShortWeekdayNames,
|
||||
getCalendarDisplayDayOfMonthFromUnixTime,
|
||||
getCalendarDisplayDayOfMonthFromDateTime,
|
||||
getCalendarAlternateDates,
|
||||
formatAmountToLocalizedNumeralsWithCurrency
|
||||
} = useI18n();
|
||||
@@ -105,8 +98,7 @@ const alternateDates = computed<Record<TextualYearMonthDay, string> | undefined>
|
||||
});
|
||||
|
||||
function noTransactionInMonthDay(date: Date): boolean {
|
||||
const dateTime = parseDateTimeFromUnixTime(getActualUnixTimeForStore(getUnixTimeFromLocalDatetime(date), getTimezoneOffsetMinutes(), getBrowserTimezoneOffsetMinutes()));
|
||||
return !props.dailyTotalAmounts || !props.dailyTotalAmounts[dateTime.getGregorianCalendarDay()];
|
||||
return !props.dailyTotalAmounts || !props.dailyTotalAmounts[date.getDate()];
|
||||
}
|
||||
|
||||
function getDisplayMonthTotalAmount(amount: number, currency: string | false, symbol: string, incomplete: boolean): string {
|
||||
@@ -115,7 +107,7 @@ function getDisplayMonthTotalAmount(amount: number, currency: string | false, sy
|
||||
}
|
||||
|
||||
function getDisplayDay(date: Date): string {
|
||||
return getCalendarDisplayDayOfMonthFromUnixTime(getYearMonthDayDateTime(date.getFullYear(), date.getMonth() + 1, date.getDate()).getUnixTime());
|
||||
return getCalendarDisplayDayOfMonthFromDateTime(getYearMonthDayDateTime(date.getFullYear(), date.getMonth() + 1, date.getDate()));
|
||||
}
|
||||
</script>
|
||||
|
||||
|
||||
@@ -43,13 +43,6 @@ import { type CommonDateRangeSelectionProps, useDateRangeSelectionBase } from '@
|
||||
|
||||
import { ThemeType } from '@/core/theme.ts';
|
||||
|
||||
import {
|
||||
getLocalDatetimeFromUnixTime,
|
||||
getDummyUnixTimeForLocalUsage,
|
||||
getTimezoneOffsetMinutes,
|
||||
getBrowserTimezoneOffsetMinutes
|
||||
} from '@/lib/datetime.ts';
|
||||
|
||||
interface DesktopDateRangeSelectionProps extends CommonDateRangeSelectionProps {
|
||||
persistent?: boolean;
|
||||
}
|
||||
@@ -64,7 +57,14 @@ const emit = defineEmits<{
|
||||
const theme = useTheme();
|
||||
|
||||
const { tt } = useI18n();
|
||||
const { dateRange, beginDateTime, endDateTime, presetRanges, getFinalDateRange } = useDateRangeSelectionBase(props);
|
||||
const {
|
||||
dateRange,
|
||||
beginDateTime,
|
||||
endDateTime,
|
||||
presetRanges,
|
||||
getLocalDatetimeFromSameDateTimeOfUnixTime,
|
||||
getFinalDateRange
|
||||
} = useDateRangeSelectionBase(props);
|
||||
|
||||
const isDarkMode = computed<boolean>(() => theme.global.name.value === ThemeType.Dark);
|
||||
const showState = computed<boolean>({
|
||||
@@ -94,13 +94,13 @@ function cancel(): void {
|
||||
|
||||
watch(() => props.minTime, (newValue) => {
|
||||
if (newValue) {
|
||||
dateRange.value[0] = getLocalDatetimeFromUnixTime(getDummyUnixTimeForLocalUsage(newValue, getTimezoneOffsetMinutes(), getBrowserTimezoneOffsetMinutes()));
|
||||
dateRange.value[0] = getLocalDatetimeFromSameDateTimeOfUnixTime(newValue);
|
||||
}
|
||||
});
|
||||
|
||||
watch(() => props.maxTime, (newValue) => {
|
||||
if (newValue) {
|
||||
dateRange.value[1] = getLocalDatetimeFromUnixTime(getDummyUnixTimeForLocalUsage(newValue, getTimezoneOffsetMinutes(), getBrowserTimezoneOffsetMinutes()));
|
||||
dateRange.value[1] = getLocalDatetimeFromSameDateTimeOfUnixTime(newValue);
|
||||
}
|
||||
});
|
||||
</script>
|
||||
|
||||
@@ -94,12 +94,9 @@ import {
|
||||
} from '@/core/datetime.ts';
|
||||
import {
|
||||
getHourIn12HourFormat,
|
||||
getTimezoneOffsetMinutes,
|
||||
getBrowserTimezoneOffsetMinutes,
|
||||
getLocalDatetimeFromUnixTime,
|
||||
getUnixTimeFromLocalDatetime,
|
||||
getActualUnixTimeForStore,
|
||||
getDummyUnixTimeForLocalUsage,
|
||||
getSameDateTimeWithBrowserTimezone,
|
||||
parseDateTimeFromUnixTimeWithTimezoneOffset,
|
||||
parseDateTimeFromKnownDateTimeFormat,
|
||||
getAMOrPM,
|
||||
getCombinedDateAndTimeValues
|
||||
@@ -108,6 +105,7 @@ import { setChildInputFocus } from '@/lib/ui/desktop.ts';
|
||||
|
||||
const props = defineProps<{
|
||||
modelValue: number;
|
||||
timezoneUtcOffset: number;
|
||||
disabled?: boolean;
|
||||
readonly?: boolean;
|
||||
label?: string;
|
||||
@@ -124,7 +122,7 @@ const {
|
||||
getCurrentNumeralSystemType,
|
||||
parseDateTimeFromLongDateTime,
|
||||
parseDateTimeFromShortDateTime,
|
||||
formatUnixTimeToLongDateTime
|
||||
formatDateTimeToLongDateTime
|
||||
} = useI18n();
|
||||
|
||||
const {
|
||||
@@ -133,6 +131,8 @@ const {
|
||||
isMinuteTwoDigits,
|
||||
isSecondTwoDigits,
|
||||
isMeridiemIndicatorFirst,
|
||||
getLocalDatetimeFromSameDateTimeOfUnixTime,
|
||||
getUnixTimeFromSameDateTimeOfLocalDatetime,
|
||||
getDisplayTimeValue,
|
||||
generateAllHours,
|
||||
generateAllMinutesOrSeconds
|
||||
@@ -147,10 +147,10 @@ const numeralSystem = computed<NumeralSystem>(() => getCurrentNumeralSystemType(
|
||||
|
||||
const dateTime = computed<Date>({
|
||||
get: () => {
|
||||
return getLocalDatetimeFromUnixTime(props.modelValue);
|
||||
return getLocalDatetimeFromSameDateTimeOfUnixTime(props.modelValue, props.timezoneUtcOffset);
|
||||
},
|
||||
set: (value: Date) => {
|
||||
const unixTime = getUnixTimeFromLocalDatetime(value);
|
||||
const unixTime = getUnixTimeFromSameDateTimeOfLocalDatetime(value, props.timezoneUtcOffset);
|
||||
|
||||
if (unixTime < 0) {
|
||||
emit('error', 'Date is too early');
|
||||
@@ -161,7 +161,7 @@ const dateTime = computed<Date>({
|
||||
}
|
||||
});
|
||||
|
||||
const displayTime = computed<string>(() => formatUnixTimeToLongDateTime(getActualUnixTimeForStore(getUnixTimeFromLocalDatetime(dateTime.value), getTimezoneOffsetMinutes(), getBrowserTimezoneOffsetMinutes())));
|
||||
const displayTime = computed<string>(() => formatDateTimeToLongDateTime(parseDateTimeFromUnixTimeWithTimezoneOffset(props.modelValue, props.timezoneUtcOffset)));
|
||||
|
||||
const hourItems = computed<TimePickerValue[]>(() => generateAllHours(1, isHourTwoDigits.value));
|
||||
const minuteItems = computed<TimePickerValue[]>(() => generateAllMinutesOrSeconds(1, isMinuteTwoDigits.value));
|
||||
@@ -252,7 +252,7 @@ function onPaste(event: ClipboardEvent): void {
|
||||
dt = parseDateTimeFromKnownDateTimeFormat(text, formats[0] as KnownDateTimeFormat);
|
||||
|
||||
if (dt) {
|
||||
dateTime.value = getLocalDatetimeFromUnixTime(getDummyUnixTimeForLocalUsage(dt.getUnixTime(), getTimezoneOffsetMinutes(), getBrowserTimezoneOffsetMinutes()));
|
||||
dateTime.value = getLocalDatetimeFromUnixTime(getSameDateTimeWithBrowserTimezone(dt).getUnixTime());
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -260,14 +260,14 @@ function onPaste(event: ClipboardEvent): void {
|
||||
dt = parseDateTimeFromLongDateTime(text);
|
||||
|
||||
if (dt) {
|
||||
dateTime.value = getLocalDatetimeFromUnixTime(getDummyUnixTimeForLocalUsage(dt.getUnixTime(), getTimezoneOffsetMinutes(), getBrowserTimezoneOffsetMinutes()));
|
||||
dateTime.value = getLocalDatetimeFromUnixTime(getSameDateTimeWithBrowserTimezone(dt).getUnixTime());
|
||||
return;
|
||||
}
|
||||
|
||||
dt = parseDateTimeFromShortDateTime(text);
|
||||
|
||||
if (dt) {
|
||||
dateTime.value = getLocalDatetimeFromUnixTime(getDummyUnixTimeForLocalUsage(dt.getUnixTime(), getTimezoneOffsetMinutes(), getBrowserTimezoneOffsetMinutes()));
|
||||
dateTime.value = getLocalDatetimeFromUnixTime(getSameDateTimeWithBrowserTimezone(dt).getUnixTime());
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -43,6 +43,7 @@ import {
|
||||
isNumber
|
||||
} from '@/lib/common.ts';
|
||||
import {
|
||||
parseDateTimeFromUnixTime,
|
||||
getYearMonthFirstUnixTime,
|
||||
getYearMonthLastUnixTime,
|
||||
getDateTypeByDateRange,
|
||||
@@ -95,11 +96,11 @@ const theme = useTheme();
|
||||
const {
|
||||
tt,
|
||||
getCurrentLanguageTextDirection,
|
||||
formatUnixTimeToShortDate,
|
||||
formatUnixTimeToGregorianLikeShortYear,
|
||||
formatUnixTimeToGregorianLikeShortYearMonth,
|
||||
formatDateTimeToShortDate,
|
||||
formatDateTimeToGregorianLikeShortYear,
|
||||
formatDateTimeToGregorianLikeShortYearMonth,
|
||||
formatYearQuarterToGregorianLikeYearQuarter,
|
||||
formatUnixTimeToGregorianLikeFiscalYear,
|
||||
formatDateTimeToGregorianLikeFiscalYear,
|
||||
formatAmountToWesternArabicNumeralsWithoutDigitGrouping,
|
||||
formatAmountToLocalizedNumeralsWithCurrency
|
||||
} = useI18n();
|
||||
@@ -151,16 +152,18 @@ const allDisplayDateRanges = computed<string[]>(() => {
|
||||
const allDisplayDateRanges: string[] = [];
|
||||
|
||||
for (const dateRange of allDateRanges.value) {
|
||||
const minDateTime = parseDateTimeFromUnixTime(dateRange.minUnixTime);
|
||||
|
||||
if (props.dateAggregationType === ChartDateAggregationType.Year.type) {
|
||||
allDisplayDateRanges.push(formatUnixTimeToGregorianLikeShortYear(dateRange.minUnixTime));
|
||||
allDisplayDateRanges.push(formatDateTimeToGregorianLikeShortYear(minDateTime));
|
||||
} else if (props.dateAggregationType === ChartDateAggregationType.FiscalYear.type && 'year' in dateRange) {
|
||||
allDisplayDateRanges.push(formatUnixTimeToGregorianLikeFiscalYear(dateRange.minUnixTime));
|
||||
allDisplayDateRanges.push(formatDateTimeToGregorianLikeFiscalYear(minDateTime));
|
||||
} else if (props.dateAggregationType === ChartDateAggregationType.Quarter.type && 'quarter' in dateRange) {
|
||||
allDisplayDateRanges.push(formatYearQuarterToGregorianLikeYearQuarter(dateRange.year, dateRange.quarter));
|
||||
} else if (props.dateAggregationType === ChartDateAggregationType.Month.type) {
|
||||
allDisplayDateRanges.push(formatUnixTimeToGregorianLikeShortYearMonth(dateRange.minUnixTime));
|
||||
allDisplayDateRanges.push(formatDateTimeToGregorianLikeShortYearMonth(minDateTime));
|
||||
} else if (props.dateAggregationType === ChartDateAggregationType.Day.type && props.chartMode === 'daily') {
|
||||
allDisplayDateRanges.push(formatUnixTimeToShortDate(dateRange.minUnixTime));
|
||||
allDisplayDateRanges.push(formatDateTimeToShortDate(minDateTime));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -45,13 +45,6 @@ import { type CommonDateRangeSelectionProps, useDateRangeSelectionBase } from '@
|
||||
|
||||
import { useEnvironmentsStore } from '@/stores/environment.ts';
|
||||
|
||||
import {
|
||||
getLocalDatetimeFromUnixTime,
|
||||
getDummyUnixTimeForLocalUsage,
|
||||
getTimezoneOffsetMinutes,
|
||||
getBrowserTimezoneOffsetMinutes
|
||||
} from '@/lib/datetime.ts';
|
||||
|
||||
type DateTimePickerType = InstanceType<typeof DateTimePicker>;
|
||||
|
||||
const props = defineProps<CommonDateRangeSelectionProps>();
|
||||
@@ -62,7 +55,14 @@ const emit = defineEmits<{
|
||||
|
||||
const { tt } = useI18n();
|
||||
const { showToast } = useI18nUIComponents();
|
||||
const { dateRange, beginDateTime, endDateTime, presetRanges, getFinalDateRange } = useDateRangeSelectionBase(props);
|
||||
const {
|
||||
dateRange,
|
||||
beginDateTime,
|
||||
endDateTime,
|
||||
presetRanges,
|
||||
getLocalDatetimeFromSameDateTimeOfUnixTime,
|
||||
getFinalDateRange
|
||||
} = useDateRangeSelectionBase(props);
|
||||
|
||||
const environmentsStore = useEnvironmentsStore();
|
||||
|
||||
@@ -91,11 +91,11 @@ function cancel(): void {
|
||||
|
||||
function onSheetOpen(): void {
|
||||
if (props.minTime) {
|
||||
dateRange.value[0] = getLocalDatetimeFromUnixTime(getDummyUnixTimeForLocalUsage(props.minTime, getTimezoneOffsetMinutes(), getBrowserTimezoneOffsetMinutes()));
|
||||
dateRange.value[0] = getLocalDatetimeFromSameDateTimeOfUnixTime(props.minTime);
|
||||
}
|
||||
|
||||
if (props.maxTime) {
|
||||
dateRange.value[1] = getLocalDatetimeFromUnixTime(getDummyUnixTimeForLocalUsage(props.maxTime, getTimezoneOffsetMinutes(), getBrowserTimezoneOffsetMinutes()));
|
||||
dateRange.value[1] = getLocalDatetimeFromSameDateTimeOfUnixTime(props.maxTime);
|
||||
}
|
||||
|
||||
window.dispatchEvent(new Event('resize')); // fix vue-datepicker preset max-width
|
||||
|
||||
@@ -111,9 +111,7 @@ import { NumeralSystem } from '@/core/numeral.ts';
|
||||
import { isDefined } from '@/lib/common.ts';
|
||||
import {
|
||||
getHourIn12HourFormat,
|
||||
getLocalDatetimeFromUnixTime,
|
||||
getCurrentUnixTime,
|
||||
getUnixTimeFromLocalDatetime,
|
||||
getAMOrPM,
|
||||
getCombinedDateAndTimeValues
|
||||
} from '@/lib/datetime.ts';
|
||||
@@ -122,6 +120,7 @@ type DateTimePickerType = InstanceType<typeof DateTimePicker>;
|
||||
|
||||
const props = defineProps<{
|
||||
modelValue: number;
|
||||
timezoneUtcOffset: number;
|
||||
initMode?: string;
|
||||
show: boolean;
|
||||
}>();
|
||||
@@ -144,6 +143,8 @@ const {
|
||||
isSecondTwoDigits,
|
||||
isMeridiemIndicatorFirst,
|
||||
meridiemItems,
|
||||
getLocalDatetimeFromSameDateTimeOfUnixTime,
|
||||
getUnixTimeFromSameDateTimeOfLocalDatetime,
|
||||
getDisplayTimeValue,
|
||||
generateAllHours,
|
||||
generateAllMinutesOrSeconds
|
||||
@@ -160,7 +161,7 @@ let resetTimePickerItemPositionItemsLastOffsetTop: number | undefined = undefine
|
||||
let resetTimePickerItemPositionCheckedFrames: number | undefined = undefined;
|
||||
|
||||
const mode = ref<string>(props.initMode || 'time');
|
||||
const dateTime = ref<Date>(getLocalDatetimeFromUnixTime(props.modelValue || getCurrentUnixTime()));
|
||||
const dateTime = ref<Date>(getLocalDatetimeFromSameDateTimeOfUnixTime(props.modelValue || getCurrentUnixTime(), props.timezoneUtcOffset));
|
||||
const timePickerContainerHeight = ref<number | undefined>(undefined);
|
||||
const timePickerItemHeight = ref<number | undefined>(undefined);
|
||||
|
||||
@@ -213,7 +214,7 @@ function switchMode(): void {
|
||||
}
|
||||
|
||||
function setCurrentTime(): void {
|
||||
dateTime.value = getLocalDatetimeFromUnixTime(getCurrentUnixTime());
|
||||
dateTime.value = getLocalDatetimeFromSameDateTimeOfUnixTime(getCurrentUnixTime(), props.timezoneUtcOffset);
|
||||
|
||||
if (mode.value === 'time') {
|
||||
scrollAllTimeSelectedItems();
|
||||
@@ -225,7 +226,7 @@ function confirm(): void {
|
||||
return;
|
||||
}
|
||||
|
||||
const unixTime = getUnixTimeFromLocalDatetime(dateTime.value);
|
||||
const unixTime = getUnixTimeFromSameDateTimeOfLocalDatetime(dateTime.value, props.timezoneUtcOffset);
|
||||
|
||||
if (unixTime < 0) {
|
||||
showToast('Date is too early');
|
||||
@@ -420,7 +421,7 @@ function onSheetOpen(): void {
|
||||
mode.value = props.initMode || 'time';
|
||||
|
||||
if (props.modelValue) {
|
||||
dateTime.value = getLocalDatetimeFromUnixTime(props.modelValue);
|
||||
dateTime.value = getLocalDatetimeFromSameDateTimeOfUnixTime(props.modelValue, props.timezoneUtcOffset);
|
||||
}
|
||||
|
||||
if (mode.value === 'time') {
|
||||
|
||||
@@ -144,6 +144,7 @@ import {
|
||||
isNumber
|
||||
} from '@/lib/common.ts';
|
||||
import {
|
||||
parseDateTimeFromUnixTime,
|
||||
getYearMonthFirstUnixTime,
|
||||
getYearMonthLastUnixTime,
|
||||
getDateTypeByDateRange,
|
||||
@@ -200,11 +201,11 @@ const emit = defineEmits<{
|
||||
|
||||
const {
|
||||
tt,
|
||||
formatUnixTimeToShortDate,
|
||||
formatUnixTimeToGregorianLikeShortYear,
|
||||
formatUnixTimeToGregorianLikeShortYearMonth,
|
||||
formatDateTimeToShortDate,
|
||||
formatDateTimeToGregorianLikeShortYear,
|
||||
formatDateTimeToGregorianLikeShortYearMonth,
|
||||
formatYearQuarterToGregorianLikeYearQuarter,
|
||||
formatUnixTimeToGregorianLikeFiscalYear,
|
||||
formatDateTimeToGregorianLikeFiscalYear,
|
||||
formatAmountToLocalizedNumeralsWithCurrency
|
||||
} = useI18n();
|
||||
|
||||
@@ -324,18 +325,19 @@ const allDisplayDataItems = computed<TrendsBarChartData>(() => {
|
||||
dateRangeKey = `${dateRange.year}-${dateRange.month}-${dateRange.day}`;
|
||||
}
|
||||
|
||||
const minDateTime = parseDateTimeFromUnixTime(dateRange.minUnixTime);
|
||||
let displayDateRange = '';
|
||||
|
||||
if (props.dateAggregationType === ChartDateAggregationType.Year.type) {
|
||||
displayDateRange = formatUnixTimeToGregorianLikeShortYear(dateRange.minUnixTime);
|
||||
displayDateRange = formatDateTimeToGregorianLikeShortYear(minDateTime);
|
||||
} else if (props.dateAggregationType === ChartDateAggregationType.FiscalYear.type) {
|
||||
displayDateRange = formatUnixTimeToGregorianLikeFiscalYear(dateRange.minUnixTime);
|
||||
displayDateRange = formatDateTimeToGregorianLikeFiscalYear(minDateTime);
|
||||
} else if (props.dateAggregationType === ChartDateAggregationType.Quarter.type && 'quarter' in dateRange) {
|
||||
displayDateRange = formatYearQuarterToGregorianLikeYearQuarter(dateRange.year, dateRange.quarter);
|
||||
} else if (props.dateAggregationType === ChartDateAggregationType.Month.type) {
|
||||
displayDateRange = formatUnixTimeToGregorianLikeShortYearMonth(dateRange.minUnixTime);
|
||||
displayDateRange = formatDateTimeToGregorianLikeShortYearMonth(minDateTime);
|
||||
} else if (props.dateAggregationType === ChartDateAggregationType.Day.type && props.chartMode === 'daily') {
|
||||
displayDateRange = formatUnixTimeToShortDate(dateRange.minUnixTime);
|
||||
displayDateRange = formatDateTimeToShortDate(minDateTime);
|
||||
}
|
||||
|
||||
const dataItems = allDateRangeItemsMap[dateRangeKey] || [];
|
||||
|
||||
Reference in New Issue
Block a user