Repository navigation
feat(datepicker): add dateFormat prop #1700
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
Open
NokNok-0
wants to merge
6
commits into
themesberg:main
Choose a base branch
from
NokNok-0:feat/datepicker-date-format
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
265e9b8
feat(datepicker): add dateFormat prop
NokNok-0 188fb91
fix(datepicker): keep the selected day when dateFormat sets a timeZone
NokNok-0 ac7d0a4
fix(datepicker): correct the timeZone day-anchoring edge cases
NokNok-0 5ec582b
fix(datepicker): handle time fields, BCE years and the max Date with …
NokNok-0 c19c8b3
fix(datepicker): drive the timeZone correction by zoned wall clock
NokNok-0 ef7ea7f
fix(datepicker): guard the shifted timeZone anchor against overflow
NokNok-0 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| import { Datepicker } from "flowbite-react"; | ||
| import type { CodeData } from "~/components/code-demo"; | ||
|
|
||
| const code = ` | ||
| import { Datepicker } from "flowbite-react"; | ||
|
|
||
| export function Component() { | ||
| return ( | ||
| <Datepicker | ||
| defaultValue={new Date(2026, 0, 15)} | ||
| language="en-GB" | ||
| dateFormat={{ day: "2-digit", month: "2-digit", year: "numeric" }} | ||
| /> | ||
| ); | ||
| } | ||
| `; | ||
|
|
||
| export function Component() { | ||
| return ( | ||
| <Datepicker | ||
| defaultValue={new Date(2026, 0, 15)} | ||
| language="en-GB" | ||
| dateFormat={{ day: "2-digit", month: "2-digit", year: "numeric" }} | ||
| /> | ||
| ); | ||
| } | ||
|
|
||
| export const format: CodeData = { | ||
| type: "single", | ||
| code: { | ||
| fileName: "index", | ||
| language: "tsx", | ||
| code, | ||
| }, | ||
| githubSlug: "datepicker/datepicker.format.tsx", | ||
| component: <Component />, | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Script executed:
rg -n 'changeSelectedDate|setSelectedDate|new Date\(' packages/ui/src/components/Datepicker/DatepickerViewsDays.tsx packages/ui/src/components/DatepickerRepository: themesberg/flowbite-react
Length of output: 12861
Script executed:
Repository: themesberg/flowbite-react
Length of output: 14625
Keep the selected calendar day when
dateFormatsetstimeZone.With a
timeZoneindateFormat, the input can show the previous calendar day. The selection is stored as local midnight, andIntlconverts that instant into the requested zone. The highlighted day and the input text then disagree. Decide whethertimeZoneshould shift the displayed day or be applied to the calendar day only. Then document that behavior, or convert the selected day before formatting.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed in 188fb91.
getFormattedDatenow anchors the date to UTC noon of the selected calendar day and corrects the offset when a zone would shift the day, so the input always shows the selected day regardless of thetimeZoneindateFormat. Covered by a deterministic unit test formatting a local date inUTC.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Analysis chain
Script executed:
Length of output: 4693
@NokNok-0Thanks for the update. The UTC-noon anchor fixes the reported UTC case, but the correction still fails at month boundaries.In
helpers.ts, Line 139 compares day-of-month numbers to choose the adjustment direction. For January 31 inPacific/Kiritimati(UTC+14), the anchor formats as February 1. Since1 > 31is false, the loop moves forward instead of backward.Compare complete calendar dates when choosing the adjustment direction. Add a regression test for January 31 with
timeZone: "Pacific/Kiritimati". The current UTC test does not exercise the correction branch.I inspected the implementation and test source. I did not run repository tests. This finding remains open.
If you found this review helpful, would you consider giving us a shout-out on X?
Thank you for using CodeRabbit!
You are interacting with an AI system.