Skip to content

Commit

Permalink
fix: unknown tz (#34)
Browse files Browse the repository at this point in the history
* chore: add comment and type

* fix: This code ensures that if tz is undefined, the toLowerCase function is not called.
  • Loading branch information
mori-hisayuki authored Mar 7, 2024
1 parent 980428e commit 0245e40
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
4 changes: 3 additions & 1 deletion src/deviceTZ.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
/**
* Get the timezone of the device.
*
* * Note: If the environment variable TZ is not set, it will return undefined.
*/
export function deviceTZ() {
export function deviceTZ(): string | undefined {
return Intl.DateTimeFormat().resolvedOptions().timeZone
}
2 changes: 1 addition & 1 deletion src/format.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ export function format(

// We need to apply an offset to the date so that it can be formatted as UTC.
tz ??= deviceTZ()
if (tz.toLowerCase() !== "utc") {
if (tz?.toLowerCase() !== "utc") {
inputDateOrOptions = removeOffset(
inputDateOrOptions,
offset(inputDateOrOptions, tz, "utc")
Expand Down

0 comments on commit 0245e40

Please sign in to comment.