UNPKG

@aplus-frontend/utils

Version:

Utils for Aplus frontend team.

138 lines (137 loc) 4.86 kB
import dayjs, { Dayjs } from 'dayjs'; import { LiteralUnion } from '../vue/types'; export declare const userTimezone: string; /** * @description: 时区映射表 * @example: ZoneMap.LA = 'America/Los_Angeles' * @example: ZoneMap.SH = 'Asia/Shanghai' */ export declare enum ZoneMap { /** * 冰岛 UTC+0 */ RJ = "Atlantic/Reykjavik", /** * 巴黎 UTC+1 */ PR = "Europe/Paris", /** * 佛得角 UTC-1 */ VD = "Atlantic/Cape_Verde", /** * 哥本哈根 UTC+2 */ CP = "Europe/Copenhagen", /** * 巴西 UTC-2 */ BS = "America/Sao_Paulo", /** * 莫斯科 UTC+3 */ MS = "Europe/Moscow", /** * 圣保罗 UTC-3 */ SP = "America/Sao_Paulo", /** * 迪拜 UTC+4 */ DB = "Asia/Dubai", /** * 纽约 UTC-4 */ NY = "America/New_York", /** * 卡拉奇 UTC+5 */ KR = "Asia/Karachi", /** * 芝加哥 UTC-5 */ CG = "America/Chicago", /** * 不丹 UTC+6 */ TM = "Asia/Thimphu", /** * 丹佛 UTC-6 */ DV = "America/Denver", /** * 首尔 UTC+7 */ SU = "Asia/Seoul", /** /** * 洛杉矶 UTC-7 */ LA = "America/Los_Angeles", /** * 上海 UTC+8 */ SH = "Asia/Shanghai", /** * 阿拉斯加 UTC-8 */ ALS = "America/Juneau" } export type ZoneAlias = keyof typeof ZoneMap; /** * @description: 根据时区别名获取特定时区时间 * @param {number | undefined | null} timeStamp 时间戳 * @param {string} zoneAlias 时区别名(详见时区表),默认 'LA' * @param {string} format 格式,默认 'YYYY-MM-DD HH:mm:ss' * @returns {string} 格式化后的时区时间 */ export declare function getTimeFormatToZone(timeStamp: number | undefined | null, zoneAlias?: LiteralUnion<ZoneAlias, string>, format?: string): string; /** * @description: 获取特定UTC偏移量的时间(系统里默认用UTC-7时区) * @param timeStamp * @param {number} utc UTC偏移量,默认 -7 * @param {string} format 格式,默认 'YYYY-MM-DD HH:mm:ss' * @returns {string} 格式化后的时区时间 */ export declare function getUTCTimeFormat(timeStamp: number | undefined | null, utc?: number, format?: string): string | null; /** * @description: 带UTC偏移量后缀的时区时间(系统里默认用UTC-7时区) * @param timeStamp * @param {number} utc 时区,默认 -7 * @param {string} format 格式 * @returns {string} 格式化后的时区时间 例如:2022-01-01 00:00:00(UTC+8) */ export declare function getUTCTimeFormatWithZone(timeStamp: number | undefined | null, utc?: number, format?: string): string; /** * @description 根据传入的时间拿到目标时区的时间戳 * @param {string | Date | number} time 时间 * @param {string} targetZoneAlias 目标时区,默认'LA', 别名枚举值:LA = 'America/Los_Angeles' | NY ='America/New_York' | SH = 'Asia/Shanghai'... * @param {string} currentZoneAlias 当前时区,默认本地时区, 别名枚举值:LA = 'America/Los_Angeles' | NY ='America/New_York' | SH = 'Asia/Shanghai'... * @param {boolean} returnDayjs 是否返回dayjs对象,默认为false * @returns {number | Dayjs | null} 目标时区时间戳 | dayjs对象 */ export declare function getUtcTimestamp<TimeType extends string | Date | number | Dayjs | undefined | null>(config: { time: TimeType; targetZoneAlias?: LiteralUnion<ZoneAlias, string>; currentZoneAlias?: LiteralUnion<ZoneAlias, string>; returnDayjs?: false; }): TimeType extends undefined | null ? null : number; export declare function getUtcTimestamp<TimeType extends string | Date | number | Dayjs | undefined | null>(config: { time: TimeType; targetZoneAlias?: LiteralUnion<ZoneAlias, string>; currentZoneAlias?: LiteralUnion<ZoneAlias, string>; returnDayjs?: true; }): TimeType extends undefined | null ? null : Dayjs; export declare function getUtcTimestamp<TimeType extends string | Date | number | Dayjs | undefined | null>(time: TimeType, targetZoneAlias?: LiteralUnion<ZoneAlias, string>, currentZoneAlias?: LiteralUnion<ZoneAlias, string>): TimeType extends undefined | null ? null : number; /** * @description: 获取历史到现在或现在到未来的某天的开始和结束时间戳(以天为单位,时区为相对转换) * @param timezone 转换的时区,默认LA * @param step 时间间隔,默认-3 * @param unit 时间间隔单位,仅支持'day' | 'week' | 'month' | 'year',默认month(月) * @returns {number[]} 开始和结束时间戳 */ export declare function getDateIntervalUnit(params?: { timezone?: LiteralUnion<ZoneAlias, string>; step?: number; unit?: Extract<dayjs.ManipulateType, 'day' | 'week' | 'month' | 'year'>; }): number[] | null;