统一页面时间为东八区并调整活动条数
This commit is contained in:
+37
-3
@@ -1,14 +1,34 @@
|
||||
export function formatDateTime(value?: string) {
|
||||
const DISPLAY_TIME_ZONE = 'Asia/Shanghai';
|
||||
|
||||
type DateInput = string | number | Date | undefined;
|
||||
|
||||
function normalizeTimestamp(value?: DateInput) {
|
||||
if (!value) {
|
||||
return '';
|
||||
}
|
||||
|
||||
const time = Date.parse(value);
|
||||
const time =
|
||||
value instanceof Date
|
||||
? value.getTime()
|
||||
: typeof value === 'number'
|
||||
? value
|
||||
: Date.parse(value);
|
||||
|
||||
if (Number.isNaN(time)) {
|
||||
return value;
|
||||
return typeof value === 'string' ? value : '';
|
||||
}
|
||||
|
||||
return time;
|
||||
}
|
||||
|
||||
export function formatDateTime(value?: DateInput) {
|
||||
const time = normalizeTimestamp(value);
|
||||
if (time === '') {
|
||||
return '';
|
||||
}
|
||||
|
||||
return new Intl.DateTimeFormat('zh-CN', {
|
||||
timeZone: DISPLAY_TIME_ZONE,
|
||||
year: 'numeric',
|
||||
month: '2-digit',
|
||||
day: '2-digit',
|
||||
@@ -18,6 +38,20 @@ export function formatDateTime(value?: string) {
|
||||
}).format(new Date(time));
|
||||
}
|
||||
|
||||
export function formatDate(value?: DateInput) {
|
||||
const time = normalizeTimestamp(value);
|
||||
if (time === '') {
|
||||
return '';
|
||||
}
|
||||
|
||||
return new Intl.DateTimeFormat('zh-CN', {
|
||||
timeZone: DISPLAY_TIME_ZONE,
|
||||
year: 'numeric',
|
||||
month: '2-digit',
|
||||
day: '2-digit',
|
||||
}).format(new Date(time));
|
||||
}
|
||||
|
||||
export function getLatestDate(values: string[]) {
|
||||
const timestamps = values.map((value) => Date.parse(value)).filter((value) => !Number.isNaN(value));
|
||||
if (timestamps.length === 0) {
|
||||
|
||||
Reference in New Issue
Block a user