Skip to content

Conversation

@lovebuizel
Copy link
Contributor

@lovebuizel lovebuizel commented Sep 26, 2025

What's Changed

  • Add matcherWithTimeZone utility for timezone-aware date conversions
  • Integrate timezone conversion for disabled, hidden, and custom modifiers
  • Ensure consistent date comparisons across different timezones

Problem Description:

When using a timezone that converts today to a different day, the disabled and hidden properties do not update according to the timezone conversion. For example, when today is September 26th in Taipei timezone and I convert to Hawaii timezone (which becomes September 25th), the September 25th date on the DayPicker still remains disabled, but I expect that day should not be disabled.

image
import React, { useState } from "react";

import { DayPicker, TZDate } from "react-day-picker";

export function TimeZone() {
  const timeZone = "Pacific/Honolulu";
  const [selected, setSelected] = useState<Date | undefined>(
    TZDate.tz(timeZone),
  );
  const now = new Date();
  return (
    <div>
      <h3>{TZDate.tz("Asia/Taipei", now).toString()}</h3>
      <h3>{TZDate.tz(timeZone, now).toString()}</h3>
      <DayPicker
        mode="single"
        timeZone={timeZone}
        selected={selected}
        onSelect={setSelected}
        disabled={{
          before: now,
        }}
        footer={
          selected
            ? selected.toString()
            : `Pick a day to see it is in ${timeZone} time zone.`
        }
      />
    </div>
  );
}

Solution:

Implemented timezone-aware conversion for disabled, hidden, and custom modifiers properties in DayPicker. The fix ensures that all date matchers are properly converted to the specified timezone before being applied, maintaining consistent date comparisons across different timezones.

image

Type of Change

  • Bug fix
  • New feature
  • Breaking change
  • Documentation update

@lovebuizel lovebuizel requested a review from gpbl as a code owner September 26, 2025 07:06
@lovebuizel lovebuizel force-pushed the fix/timezone-matcher-support branch from 748dae6 to fcfa5b1 Compare September 30, 2025 03:57
- Add matchersWithTimeZone utility for timezone-aware date conversions
- Integrate timezone conversion for disabled, hidden, and custom modifiers
- Ensure consistent date comparisons across different timezones
@lovebuizel lovebuizel force-pushed the fix/timezone-matcher-support branch from fcfa5b1 to 5a85843 Compare September 30, 2025 04:01
@gpbl
Copy link
Owner

gpbl commented Sep 30, 2025

Thanks @lovebuizel for your contribution!

I see the issue: passing a regular Date to the "matchers" wouldn't apply the timezone provided via the prop. A solution here would be to use a timezone-aware date for now, but I agree this behavior is unexpected.

I’ve reviewed the PR, but I’m not sure it’s the right approach. Instead, we should normalize the matchers when used, applying the proper timezone to them. Let me work on this!

@lovebuizel
Copy link
Contributor Author

Thanks @gpbl for the feedback, I understand! Looking forward to your implementation.

gpbl added a commit that referenced this pull request Nov 20, 2025
@gpbl
Copy link
Owner

gpbl commented Nov 20, 2025

@lovebuizel Thanks for your patience — I was finally able to make some progress. The hardest part was reproducing the bug. I’ll close this in favor of #2849.

@gpbl gpbl closed this Nov 20, 2025
gpbl added a commit that referenced this pull request Nov 21, 2025
* Add test case for #2833

Signed-off-by: gpbl <[email protected]>

* Add test for timezones

Signed-off-by: gpbl <[email protected]>

* Add utilities to convert into timezone

Signed-off-by: gpbl <[email protected]>

* Lint files

Signed-off-by: gpbl <[email protected]>

* Lint file

Signed-off-by: gpbl <[email protected]>

* Update timezones

Signed-off-by: gpbl <[email protected]>

* Add testPathIgnorePatterns, remove log

Signed-off-by: gpbl <[email protected]>

* Add test for current date to be different

Signed-off-by: gpbl <[email protected]>

* Add comment

Signed-off-by: gpbl <[email protected]>

* Cleanup code

Signed-off-by: gpbl <[email protected]>

* Revert "Cleanup code”, update test to use proper attribute

This reverts commit 469df6e.

Signed-off-by: gpbl <[email protected]>

---------

Signed-off-by: gpbl <[email protected]>
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