Skip to content

Fix datetime shift in job filter for non-UTC timezones#278

Merged
rosa merged 4 commits intorails:mainfrom
otariidae:fix-job-filters-timezone
Aug 2, 2025
Merged

Fix datetime shift in job filter for non-UTC timezones#278
rosa merged 4 commits intorails:mainfrom
otariidae:fix-job-filters-timezone

Conversation

@otariidae
Copy link
Copy Markdown
Contributor

Problem

When Rails.application.config.time_zone is set to anything other than UTC, the datetime in the job filter shifts incorrectly each time it's edited.

For example, in my application where the timezone is set to Asia/Tokyo (+09:00), the time increases by 9 hours with every input.

time-zone-auto-shift.mov

Cause

The likely cause is how the datetime string is parsed.

The form.datetime_field submits a datetime string in the %Y-%m-%dT%H:%M format, which is then parsed by DateTime.parse. However, regardless of the application's time zone setting, this method defaults to parsing the string as UTC when no time zone information is provided.

Solution

This pull request fixes the issue by parsing the datetime string in the application's configured time zone.

Copy link
Copy Markdown
Member

@rosa rosa left a comment

Choose a reason for hiding this comment

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

Good catch, thank you!

@rosa rosa merged commit 7ac3835 into rails:main Aug 2, 2025
3 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.

2 participants