Skip to content

Fix timezone setting ignored when formatting dates#992

Merged
estruyf merged 2 commits intobetafrom
copilot/fix-timezone-issue
Mar 6, 2026
Merged

Fix timezone setting ignored when formatting dates#992
estruyf merged 2 commits intobetafrom
copilot/fix-timezone-issue

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Dec 3, 2025

PR Details

Description

When Settings.get<string>(SETTING_GLOBAL_TIMEZONE) returns undefined, DateHelper.formatInTimezone() receives a falsy value and falls back to format() instead of formatInTimeZone(), using local system time rather than the configured timezone.

Changes:

  • src/utils/formatInTimezone.ts: Default to 'UTC' when timezone setting is undefined
  • src/helpers/PanelSettings.ts: Default to 'UTC' when timezone setting is undefined

Before:

const timezone = Settings.get<string>(SETTING_GLOBAL_TIMEZONE);
// undefined → DateHelper uses format() → local system time

After:

const timezone = Settings.get<string>(SETTING_GLOBAL_TIMEZONE) || 'UTC';
// undefined → 'UTC' → DateHelper uses formatInTimeZone() → configured timezone

Related Issue

Fixes issue where "frontMatter.global.timezone": "Asia/Shanghai" was being ignored and dates were updated in UTC instead of the specified timezone.

Motivation and Context

The ternary operator in DateHelper.formatInTimezone() treats undefined/empty string as falsy, causing it to bypass formatInTimeZone() from date-fns-tz. This affects all date operations: auto-update, manual updates, and template placeholders.

How Has This Been Tested

  • Extension builds successfully
  • Timezone setting now properly applied to date formatting
  • Defaults to UTC when setting is not explicitly configured

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • Docs change / refactoring / dependency upgrade
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
Original prompt

This section details on the original issue you should resolve

<issue_title>Issue: "frontMatter.global.timezone" is invalid</issue_title>
<issue_description>Describe the bug
"frontMatter.global.timezone": "Asia/Shanghai" is invalid and it always update the UTC time.

Expected behavior
I expect to update the update date in front matter in Asia/Shanghai timezone

</issue_description>

Comments on the Issue (you are @copilot in this section)


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Co-authored-by: estruyf <2900833+estruyf@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix invalid timezone in front matter Fix timezone setting ignored when formatting dates Dec 3, 2025
Copilot AI requested a review from estruyf December 3, 2025 15:09
@estruyf estruyf marked this pull request as ready for review March 6, 2026 15:27
@estruyf estruyf merged commit 648541d into beta Mar 6, 2026
1 check passed
@estruyf estruyf deleted the copilot/fix-timezone-issue branch March 6, 2026 15:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants