Skip to content
This repository has been archived by the owner on Sep 11, 2024. It is now read-only.

Fix jump to future dates #8013

Closed
wants to merge 1 commit into from
Closed

Conversation

aman-godara
Copy link

@aman-godara aman-godara commented Mar 9, 2022

Fixes: 20800


Here's what your changelog entry will look like:

🐛 Bug Fixes

@@ -85,6 +85,7 @@ const JumpToDatePicker: React.FC<IProps> = ({ ts, onDatePicked }: IProps) => {
onInput={onDateValueInput}
onKeyDown={onDateInputKeyDown}
value={dateValue}
max={(new Date()).toISOString().substring(0, 10)}
Copy link
Contributor

Choose a reason for hiding this comment

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

In order to craft dateDefaultValue above we do something a bit different. We should align whatever we choose here with that.

  1. new Date().toISOString().substring(0, 10)
    • This does not work when the year is 99000: (new Date('99000-05-05').toISOString().substring(0, 10) -> '+099000-05')
    • This also feels ripe for the same problem that user-agent parsers had when Chrome went from 99 to 100
  2. new Date().toISOString().split('T')[0]
    • This does better when the year is 99000 but it's not in the format that the date <input> wants: new Date('99000-05-05').toISOString().split('T')[0] -> '+099000-05-05'

Those options are considerably simpler than the current code but this always does the right thing. We probably just need to package this logic up into a function at the top called formatDateForInput and re-use it in both places.

    const date = new Date(ts);
    const year = date.getFullYear();
    const month = `${date.getMonth() + 1}`.padStart(2, "0");
    const day = `${date.getDate()}`.padStart(2, "0");
    const dateDefaultValue = `${year}-${month}-${day}`;

@@ -85,6 +85,7 @@ const JumpToDatePicker: React.FC<IProps> = ({ ts, onDatePicked }: IProps) => {
onInput={onDateValueInput}
Copy link
Contributor

Choose a reason for hiding this comment

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

@aman-godara Is this PR meant to be in draft? Draft means you're still working on it and it's not ready for review yet.

Copy link
Author

@aman-godara aman-godara May 11, 2022

Choose a reason for hiding this comment

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

I was trying to test this on my local machine, hence I keep it under draft. The coding part is done unless testing fails.

@MadLittleMods MadLittleMods added the T-Defect Bugs, crashes, hangs, vulnerabilities, or other reported problems label May 11, 2022
@MadLittleMods MadLittleMods added the Z-Community-PR Issue is solved by a community member's PR label Jun 1, 2022
@aman-godara
Copy link
Author

Closing PR

@aman-godara aman-godara closed this Jun 3, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
T-Defect Bugs, crashes, hangs, vulnerabilities, or other reported problems Z-Community-PR Issue is solved by a community member's PR
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Jump to date picker lets you try to jump into the future
2 participants