From 4ec7dd4be99049e6721d4bf41b5a4d3ded7770b2 Mon Sep 17 00:00:00 2001 From: Tim Reichen Date: Thu, 8 Aug 2024 17:55:15 +0200 Subject: [PATCH] BREAKING(datetime): replace `utc` with `timeZone` option (#5647) initial commit --- datetime/format.ts | 13 +++++-------- datetime/format_test.ts | 4 ++-- 2 files changed, 7 insertions(+), 10 deletions(-) diff --git a/datetime/format.ts b/datetime/format.ts index 39a0c7619..1e18bdbb6 100644 --- a/datetime/format.ts +++ b/datetime/format.ts @@ -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); } diff --git a/datetime/format_test.ts b/datetime/format_test.ts index 425895c6a..e9da4efe1 100644 --- a/datetime/format_test.ts +++ b/datetime/format_test.ts @@ -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" }, ), ); },