mirror of
https://gitee.com/dapppp/ruoyi-plus-vben5.git
synced 2026-03-08 07:31:09 +08:00
feat: increase support for multiple time zones
This commit is contained in:
@@ -1,4 +1,9 @@
|
||||
import dayjs from 'dayjs';
|
||||
import timezone from 'dayjs/plugin/timezone';
|
||||
import utc from 'dayjs/plugin/utc';
|
||||
|
||||
dayjs.extend(utc);
|
||||
dayjs.extend(timezone);
|
||||
|
||||
export function formatDate(time: number | string, format = 'YYYY-MM-DD') {
|
||||
try {
|
||||
@@ -6,7 +11,7 @@ export function formatDate(time: number | string, format = 'YYYY-MM-DD') {
|
||||
if (!date.isValid()) {
|
||||
throw new Error('Invalid date');
|
||||
}
|
||||
return date.format(format);
|
||||
return date.tz().format(format);
|
||||
} catch (error) {
|
||||
console.error(`Error formatting date: ${error}`);
|
||||
return time;
|
||||
@@ -24,3 +29,19 @@ export function isDate(value: any): value is Date {
|
||||
export function isDayjsObject(value: any): value is dayjs.Dayjs {
|
||||
return dayjs.isDayjs(value);
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置默认时区
|
||||
* @param timezone
|
||||
*/
|
||||
export const setDefaultTimezone = (timezone?: string) => {
|
||||
timezone ? dayjs.tz.setDefault(timezone) : dayjs.tz.setDefault();
|
||||
};
|
||||
|
||||
/**
|
||||
* 获取当前时区
|
||||
* @returns 当前时区
|
||||
*/
|
||||
export const getTimezone = () => {
|
||||
return dayjs.tz.guess();
|
||||
};
|
||||
|
||||
@@ -3,4 +3,5 @@ export type * from './basic';
|
||||
export type * from './helper';
|
||||
export type * from './menu-record';
|
||||
export type * from './tabs';
|
||||
export type * from './user-profile';
|
||||
export type * from './vue-router';
|
||||
|
||||
9
packages/@core/base/typings/src/user-profile.d.ts
vendored
Normal file
9
packages/@core/base/typings/src/user-profile.d.ts
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
/**
|
||||
* 时区选项
|
||||
*/
|
||||
interface TimezoneOption {
|
||||
offset: number;
|
||||
timezone: string;
|
||||
}
|
||||
|
||||
export type { TimezoneOption };
|
||||
Reference in New Issue
Block a user