Skip to content

Conversation

@ggdouglas
Copy link
Contributor

@ggdouglas ggdouglas commented Nov 12, 2025

Builds on #7632 (upgrade to date-fns v3), related to #6744

Summary

Upgrades date-fns from v3.6.0 to v4.1.0 and migrates from the third-party date-fns-tz package to the official @date-fns/tz package with first-class timezone support.

Changes

Package Updates

  • @blueprintjs/datetime: date-fns ^3.6.0 → ^4.1.0, removed date-fns-tz, added @date-fns/tz ^1.2.0
  • @blueprintjs/datetime2: date-fns ^3.6.0 → ^4.1.0
  • @blueprintjs/docs-app: date-fns ^3.6.0 → ^4.1.0

Migration to @date-fns/tz

Replaced the third-party date-fns-tz package with the official @date-fns/tz package, which provides first-class timezone support in date-fns v4.

1. Timezone Formatting

- import { formatInTimeZone } from "date-fns-tz";
+ import { tz } from "@date-fns/tz";
+ import { format } from "date-fns";

- formatInTimeZone(date, timezone, formatStr)
+ format(date, formatStr, { in: tz(timezone) })

2. Timezone Offset Calculation

The API changed from returning milliseconds to returning minutes:

- import { getTimezoneOffset } from "date-fns-tz";
+ import { tzOffset } from "@date-fns/tz";

- const offsetInMs = getTimezoneOffset(timezone, date);
- const offsetInMinutes = offsetInMs / 1000 / 60;
+ const offsetInMinutes = tzOffset(timezone, date);
+ const offsetInMs = offsetInMinutes * 60 * 1000;

3. Timezone Conversion Functions

Reimplemented convertLocalDateToTimezoneTime and convertDateToLocalEquivalentOfTimezoneTime using tzOffset instead of toZonedTime/fromZonedTime:

// Equivalent to the old toZonedTime
export function convertLocalDateToTimezoneTime(date: Date, newTimezone: string) {
    const currentOffset = tzOffset(getCurrentTimezone(), date);
    const newOffset = tzOffset(newTimezone, date);
    const offsetDiff = newOffset - currentOffset;
    return new Date(date.getTime() + offsetDiff * 60 * 1000);
}

// Equivalent to the old fromZonedTime
export function convertDateToLocalEquivalentOfTimezoneTime(date: Date, newTimezone: string) {
    const currentOffset = tzOffset(getCurrentTimezone(), date);
    const newOffset = tzOffset(newTimezone, date);
    const offsetDiff = newOffset - currentOffset;
    return new Date(date.getTime() - offsetDiff * 60 * 1000);
}

Breaking Changes

None for consumers of @blueprintjs/datetime. All changes are internal implementation details. The public API remains unchanged.

Documentation

@changelog-app
Copy link

changelog-app bot commented Nov 12, 2025

Generate changelog in packages/datetime/changelog/@unreleased

Type (Select exactly one)

  • Feature (Adding new functionality)
  • Improvement (Improving existing functionality)
  • Fix (Fixing an issue with existing functionality)
  • Break (Creating a new major version by breaking public APIs)
  • Deprecation (Removing functionality in a non-breaking way)
  • Migration (Automatically moving data/functionality to a new system)

Description

[chore] Upgrade date-fns to v4


Generate changelog in packages/datetime2/changelog/@unreleased

Type (Select exactly one)

  • Feature (Adding new functionality)
  • Improvement (Improving existing functionality)
  • Fix (Fixing an issue with existing functionality)
  • Break (Creating a new major version by breaking public APIs)
  • Deprecation (Removing functionality in a non-breaking way)
  • Migration (Automatically moving data/functionality to a new system)

Description

[chore] Upgrade date-fns to v4


Generate changelog in packages/docs-app/changelog/@unreleased

Type (Select exactly one)

  • Feature (Adding new functionality)
  • Improvement (Improving existing functionality)
  • Fix (Fixing an issue with existing functionality)
  • Break (Creating a new major version by breaking public APIs)
  • Deprecation (Removing functionality in a non-breaking way)
  • Migration (Automatically moving data/functionality to a new system)

Description

[chore] Upgrade date-fns to v4


Check the box to generate changelog(s)

  • Generate changelog entry

@ggdouglas ggdouglas force-pushed the gdouglas/date-fns-v4 branch from ec7ea04 to 9d0c18c Compare November 12, 2025 17:13
@ggdouglas ggdouglas changed the base branch from develop to gdouglas/date-fns-v3 November 12, 2025 17:14
@svc-palantir-github
Copy link

Update `date-fns` to v4

Build artifact links for this commit: documentation | landing | table | demo

This is an automated comment from the deploy-preview CircleCI job.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants