BREAKING(datetime): replace utc with timeZone option (#5647)

initial commit
This commit is contained in:
Tim Reichen 2024-08-08 17:55:15 +02:00 committed by GitHub
parent d93b33aff8
commit 4ec7dd4be9
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 7 additions and 10 deletions

View File

@ -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);
}

View File

@ -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" },
),
);
},