add explicit type for string-based datetimes, replacing third-party datetime type with internal DateTime type

This commit is contained in:
MaysWind
2025-08-25 00:31:30 +08:00
parent f196ce969b
commit 25681f622d
35 changed files with 423 additions and 404 deletions
+6 -9
View File
@@ -45,17 +45,17 @@ import { useI18n } from '@/locales/helpers.ts';
import { useEnvironmentsStore } from '@/stores/environment.ts';
import { useUserStore } from '@/stores/user.ts';
import { type WeekDayValue } from '@/core/datetime.ts';
import { type TextualYearMonthDay, type WeekDayValue } from '@/core/datetime.ts';
import { arrangeArrayWithNewStartIndex } from '@/lib/common.ts';
import { getCurrentYear } from '@/lib/datetime.ts';
import { getAllowedYearRange } from '@/lib/datetime.ts';
const props = defineProps<{
modelValue?: string;
modelValue?: TextualYearMonthDay;
show: boolean;
}>();
const emit = defineEmits<{
(e: 'update:modelValue', value: string): void;
(e: 'update:modelValue', value: TextualYearMonthDay): void;
(e: 'update:show', value: boolean): void;
}>();
@@ -64,10 +64,7 @@ const { tt, getAllMinWeekdayNames, getMonthShortName, isLongDateMonthAfterYear }
const environmentsStore = useEnvironmentsStore();
const userStore = useUserStore();
const yearRange = ref<number[]>([
2000,
getCurrentYear() + 1
]);
const yearRange = ref<number[]>(getAllowedYearRange());
const dateTime = ref<string>('');
const isDarkMode = computed<boolean>(() => environmentsStore.framework7DarkMode || false);
@@ -81,7 +78,7 @@ function clear(): void {
}
function confirm(): void {
emit('update:modelValue', dateTime.value);
emit('update:modelValue', dateTime.value as TextualYearMonthDay);
emit('update:show', false);
}
@@ -132,7 +132,7 @@ import {
getLocalDatetimeFromUnixTime,
getActualUnixTimeForStore,
getCurrentUnixTime,
getUnixTime,
getUnixTimeFromLocalDatetime,
getAMOrPM,
getCombinedDateAndTimeValues
} from '@/lib/datetime.ts';
@@ -225,7 +225,7 @@ const currentSecond = computed<string>({
});
const isDarkMode = computed<boolean>(() => environmentsStore.framework7DarkMode || false);
const displayTime = computed<string>(() => formatUnixTimeToLongDateTime(getActualUnixTimeForStore(getUnixTime(dateTime.value), getTimezoneOffsetMinutes(), getBrowserTimezoneOffsetMinutes())));
const displayTime = computed<string>(() => formatUnixTimeToLongDateTime(getActualUnixTimeForStore(getUnixTimeFromLocalDatetime(dateTime.value), getTimezoneOffsetMinutes(), getBrowserTimezoneOffsetMinutes())));
const switchButtonTitle = computed<string>(() => mode.value === 'time' ? 'Date' : 'Time');
function switchMode(): void {
@@ -249,7 +249,7 @@ function confirm(): void {
return;
}
const unixTime = getUnixTime(dateTime.value);
const unixTime = getUnixTimeFromLocalDatetime(dateTime.value);
if (unixTime < 0) {
showToast('Date is too early');
@@ -52,10 +52,12 @@ import { type CommonMonthRangeSelectionProps, useMonthRangeSelectionBase } from
import { useEnvironmentsStore } from '@/stores/environment.ts';
import { type TextualYearMonth } from '@/core/datetime.ts';
const props = defineProps<CommonMonthRangeSelectionProps>();
const emit = defineEmits<{
(e: 'update:show', value: boolean): void;
(e: 'dateRange:change', minYearMonth: string, maxYearMonth: string): void;
(e: 'dateRange:change', minYearMonth: TextualYearMonth | '', maxYearMonth: TextualYearMonth | ''): void;
}>();
const { tt, getMonthShortName } = useI18n();
@@ -44,17 +44,18 @@ import { useI18n } from '@/locales/helpers.ts';
import { useI18nUIComponents } from '@/lib/ui/mobile.ts';
import { type CommonMonthSelectionProps, useMonthSelectionBase } from '@/components/base/MonthSelectionBase.ts';
import type { Year0BasedMonth } from '@/core/datetime.ts';
import { useEnvironmentsStore } from '@/stores/environment.ts';
const props = defineProps<CommonMonthSelectionProps>();
const emit = defineEmits<{
(e: 'update:modelValue', value: string): void;
(e: 'update:modelValue', value: Year0BasedMonth): void;
(e: 'update:show', value: boolean): void;
}>();
const { tt, getMonthShortName } = useI18n();
const { showToast } = useI18nUIComponents();
const { yearRange, monthValue, isYearFirst, getMonthSelectionValue, getTextualYearMonth } = useMonthSelectionBase(props);
const { yearRange, monthValue, isYearFirst, getMonthSelectionValue, getYear0BasedMonth } = useMonthSelectionBase(props);
const environmentsStore = useEnvironmentsStore();
@@ -62,7 +63,7 @@ const isDarkMode = computed<boolean>(() => environmentsStore.framework7DarkMode
function confirm(): void {
try {
const finalMonthRange = getTextualYearMonth();
const finalMonthRange = getYear0BasedMonth();
if (!finalMonthRange) {
return;