@waiting/shared-core
Advanced tools
Comparing version 23.0.2 to 23.1.0
@@ -9,2 +9,5 @@ import { ISO8601String } from '@waiting/shared-types'; | ||
export declare function genISO8601String(date?: Date): ISO8601String; | ||
export declare const defaultDateTimeFormatOptions: Intl.DateTimeFormatOptions; | ||
export declare const dateTimeFormatterCN: Intl.DateTimeFormat; | ||
export declare function formatDateTime(input: number | string | Date, locales?: string | string[], options?: Intl.DateTimeFormatOptions): any; | ||
//# sourceMappingURL=date.d.ts.map |
@@ -26,2 +26,33 @@ /** | ||
} | ||
export const defaultDateTimeFormatOptions = { | ||
year: 'numeric', | ||
month: '2-digit', | ||
day: '2-digit', | ||
hour: '2-digit', | ||
minute: '2-digit', | ||
second: '2-digit', | ||
timeZone: 'Asia/Shanghai', | ||
}; | ||
export const dateTimeFormatterCN = new Intl.DateTimeFormat('zh-CN', defaultDateTimeFormatOptions); | ||
// const date = new Date(Date.UTC(2020, 11, 20, 3, 23, 16, 738)) | ||
// dateFormatterCN.format(date) // "2020/12/20 11:23:16" | ||
export function formatDateTime(input, locales = 'zh-CN', options) { | ||
const dateFormatter = locales && options | ||
? new Intl.DateTimeFormat(locales, options) | ||
: dateTimeFormatterCN; | ||
if (input instanceof Date) { | ||
return dateFormatter.format(input); | ||
} | ||
else if (typeof input === 'number') { | ||
const val = new Date(input); | ||
return dateFormatter.format(val); | ||
} | ||
else if (typeof input === 'string') { | ||
const val = new Date(input); | ||
return dateFormatter.format(val); | ||
} | ||
else { | ||
throw new Error('input is invalid'); | ||
} | ||
} | ||
//# sourceMappingURL=date.js.map |
{ | ||
"name": "@waiting/shared-core", | ||
"author": "waiting", | ||
"version": "23.0.2", | ||
"version": "23.1.0", | ||
"description": "node core function re export with Promise or Observable", | ||
@@ -77,3 +77,3 @@ "keywords": [ | ||
}, | ||
"gitHead": "557438667960683a01d6c720e29ebc4a559b61e2" | ||
"gitHead": "d1e6ffd6ca253e27f5aabd6a70554f35c3fd5587" | ||
} |
@@ -0,1 +1,2 @@ | ||
/* eslint-disable @typescript-eslint/no-explicit-any */ | ||
import { ISO8601String } from '@waiting/shared-types' | ||
@@ -33,1 +34,44 @@ | ||
export const defaultDateTimeFormatOptions: Intl.DateTimeFormatOptions = { | ||
year: 'numeric', | ||
month: '2-digit', | ||
day: '2-digit', | ||
hour: '2-digit', | ||
minute: '2-digit', | ||
second: '2-digit', | ||
timeZone: 'Asia/Shanghai', | ||
} | ||
export const dateTimeFormatterCN = new Intl.DateTimeFormat('zh-CN', defaultDateTimeFormatOptions) | ||
// const date = new Date(Date.UTC(2020, 11, 20, 3, 23, 16, 738)) | ||
// dateFormatterCN.format(date) // "2020/12/20 11:23:16" | ||
export function formatDateTime( | ||
input: number | string | Date, | ||
locales: string | string[] = 'zh-CN', | ||
options?: Intl.DateTimeFormatOptions, | ||
): any { | ||
const dateFormatter = locales && options | ||
? new Intl.DateTimeFormat(locales, options) | ||
: dateTimeFormatterCN | ||
if (input instanceof Date) { | ||
return dateFormatter.format(input) | ||
} | ||
else if (typeof input === 'number') { | ||
const val = new Date(input) | ||
return dateFormatter.format(val) | ||
} | ||
else if (typeof input === 'string') { | ||
const val = new Date(input) | ||
return dateFormatter.format(val) | ||
} | ||
else { | ||
throw new Error('input is invalid') | ||
} | ||
} | ||
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
132690
2746