Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: use system timezone in gr.DateTime with include_time=False #9825

Merged
merged 3 commits into from
Oct 24, 2024

Conversation

lcian
Copy link
Contributor

@lcian lcian commented Oct 23, 2024

Description

When using gr.DateTime with include_time=False, the frontend code creates a new Date object out of the chosen date string.

There is a discrepancy in the way date-only and date-time strings are dealt with in JS by the Date constructor, which causes the date string to be interpreted as if it specified a time in the UTC timezone (source):

When the time zone offset is absent, date-only forms are interpreted as a UTC time and date-time forms are interpreted as a local time. The interpretation as a UTC time is due to a historical spec error that was not consistent with ISO 8601 but could not be changed due to web compatibility.

Due to this behavior, if the user's system timezone is one which has a negative offset with respect to UTC, the date returned by a gr.DateTime component with include_time=False would correspond to the day preceding the one selected by the user, which is wrong.

By appending "T00:00:00", we turn the date-only string into a date-time string, which will be parsed correctly as per the user's system timezone (not necessarily UTC).

Closes: #9573

@gradio-pr-bot
Copy link
Collaborator

gradio-pr-bot commented Oct 23, 2024

🪼 branch checks and previews

Name Status URL
Spaces ready! Spaces preview
Storybook ready! Storybook preview
🦄 Changes detecting...

Install Gradio from this PR

pip install https://gradio-pypi-previews.s3.amazonaws.com/cfd44d54e87e9521245ec077871b238adc0fde3a/gradio-5.3.0-py3-none-any.whl

Install Gradio Python Client from this PR

pip install "gradio-client @ git+https://github.com/gradio-app/gradio@cfd44d54e87e9521245ec077871b238adc0fde3a#subdirectory=client/python"

Install Gradio JS Client from this PR

npm install https://gradio-npm-previews.s3.amazonaws.com/cfd44d54e87e9521245ec077871b238adc0fde3a/gradio-client-1.7.0.tgz

Use Lite from this PR

<script type="module" src="https://gradio-lite-previews.s3.amazonaws.com/cfd44d54e87e9521245ec077871b238adc0fde3a/dist/lite.js""></script>

@gradio-pr-bot
Copy link
Collaborator

🦄 change detected

This Pull Request includes changes to the following packages.

Package Version
@gradio/datetime patch
gradio patch
  • Maintainers can select this checkbox to manually select packages to update.

With the following changelog entry.

fix: use system timezone in gr.DateTime with include_time=False

Maintainers or the PR author can modify the PR title to modify this entry.

Something isn't right?

  • Maintainers can change the version label to modify the version bump.
  • If the bot has failed to detect any changes, or if this pull request needs to update multiple packages to different versions or requires a more comprehensive changelog entry, maintainers can update the changelog file directly.

Copy link
Collaborator

@aliabid94 aliabid94 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Beautiful, thanks!

@freddyaboulton freddyaboulton merged commit f15808e into gradio-app:main Oct 24, 2024
23 of 24 checks passed
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.

DateTime returns off-by-one date
5 participants