mirror of
https://github.com/denoland/std.git
synced 2024-11-21 20:50:22 +00:00
BREAKING(datetime): replace utc
with timeZone
option (#5647)
initial commit
This commit is contained in:
parent
d93b33aff8
commit
4ec7dd4be9
@ -6,11 +6,11 @@ import { DateTimeFormatter } from "./_date_time_formatter.ts";
|
||||
/** Options for {@linkcode format}. */
|
||||
export interface FormatOptions {
|
||||
/**
|
||||
* Whether returns the formatted date in UTC instead of local time.
|
||||
* The timezone the formatted date should be in.
|
||||
*
|
||||
* @default {false}
|
||||
* @default {undefined}
|
||||
*/
|
||||
utc?: boolean;
|
||||
timeZone?: "UTC";
|
||||
}
|
||||
|
||||
/**
|
||||
@ -69,7 +69,7 @@ export interface FormatOptions {
|
||||
*
|
||||
* const date = new Date(2019, 0, 20, 16, 34, 23, 123);
|
||||
*
|
||||
* assertEquals(format(date, "yyyy-MM-dd HH:mm:ss", { utc: true }), "2019-01-20 05:34:23");
|
||||
* assertEquals(format(date, "yyyy-MM-dd HH:mm:ss", { timeZone: "UTC" }), "2019-01-20 05:34:23");
|
||||
* ```
|
||||
*/
|
||||
export function format(
|
||||
@ -78,8 +78,5 @@ export function format(
|
||||
options: FormatOptions = {},
|
||||
): string {
|
||||
const formatter = new DateTimeFormatter(formatString);
|
||||
return formatter.format(
|
||||
date,
|
||||
options.utc ? { timeZone: "UTC" } : undefined,
|
||||
);
|
||||
return formatter.format(date, options);
|
||||
}
|
||||
|
@ -108,7 +108,7 @@ Deno.test({
|
||||
format(
|
||||
new Date("2019-01-01T13:00:00.000+09:00"),
|
||||
"yyyy-MM-dd HH:mm:ss.SSS",
|
||||
{ utc: true },
|
||||
{ timeZone: "UTC" },
|
||||
),
|
||||
);
|
||||
|
||||
@ -117,7 +117,7 @@ Deno.test({
|
||||
format(
|
||||
new Date("2019-01-01T13:00:00.000-05:00"),
|
||||
"yyyy-MM-dd HH:mm:ss.SSS",
|
||||
{ utc: true },
|
||||
{ timeZone: "UTC" },
|
||||
),
|
||||
);
|
||||
},
|
||||
|
Loading…
Reference in New Issue
Block a user