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

DateTimePicker switches month/day on manual input #1095

Closed
RicoNL opened this issue Jan 17, 2022 · 4 comments · Fixed by #1471
Closed

DateTimePicker switches month/day on manual input #1095

RicoNL opened this issue Jan 17, 2022 · 4 comments · Fixed by #1471
Assignees
Labels
status:fixed-next-drop Issue will be fixed in upcoming release. type:bug
Milestone

Comments

@RicoNL
Copy link
Contributor

RicoNL commented Jan 17, 2022

Category

[ ] Enhancement

[X] Bug

[ ] Question

Version

Please specify what version of the library you are using: [ 3.5.0 ]

If you are not using the latest release, please update and see if the issue is resolved before submitting an issue.

Expected / Desired Behavior / Question

Manual input on DateTimePicker respects locale settings for day/month

Observed Behavior

When using manual input of date, the day and month are switched when locale settings are set to Dutch and using Dutch input format (dd-mm-yyyy).

Steps to Reproduce

  • create empty spfx webpart 1.13.1

  • add datetimepicker with dutch locale
    image

  • test the datetimepicker
    05-11-2022 should be translated as 05 nov. 2022,
    image

but is set as 11 mei (may) 2022
image

@ghost
Copy link

ghost commented Jan 17, 2022

Thank you for reporting this issue. We will be triaging your incoming issue as soon as possible.

@ghost ghost added the Needs: Triage 🔍 label Jan 17, 2022
@joelfmrodrigues
Copy link
Collaborator

@RicoNL sorry for the very long delay on this. Could you please double-check with the latest release? If still an issue, would you be able to try to fix and submit a pull-request?

@RicoNL
Copy link
Contributor Author

RicoNL commented Nov 14, 2022

@joelfmrodrigues I will look into it.

@RicoNL
Copy link
Contributor Author

RicoNL commented Feb 21, 2023

Utilizing the parseDateFromString-property (see PR #1465), the correct date can be parsed. Sample code:

private onParseDateFromString(dateStr: string): Date {
let locale = this.props.context.pageContext.cultureInfo.currentCultureName;

let dateArray: string[];
let day: string = null;
let month: string = null;
let year: string = null;
let date: Date = null;

if (locale.toLowerCase() === "nl-nl") {
  // based on date-notation 'dd-mm-yyyy'
  dateArray = dateStr.split("-");
  day = dateArray[0].length === 1 ? `0${dateArray[0]}` : dateArray[0];
  month = dateArray[1].length === 1 ? `0${dateArray[1]}` : dateArray[1];
  year = dateArray[2].length === 2 ? `20${dateArray[2]}` : dateArray[2];

  date = new Date(year + "-" + month + "-" + day + "T00:00:00" ); 
} else {
  date = new Date(dateStr); 
}

return date;

}

@joaojmendes joaojmendes self-assigned this Feb 21, 2023
@joaojmendes joaojmendes added the status:fixed-next-drop Issue will be fixed in upcoming release. label Feb 21, 2023
@joaojmendes joaojmendes added this to the 3.13.0 milestone Feb 21, 2023
@AJIXuMuK AJIXuMuK mentioned this issue Feb 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status:fixed-next-drop Issue will be fixed in upcoming release. type:bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants