Skip to content
This repository was archived by the owner on May 20, 2023. It is now read-only.

Conversation

@lejard-h
Copy link
Contributor

use the given dateFormat to decode the input value.

for the following format dd/mm/yy, the parser was inversing month and days, 08/12/2018 -> 12/08/2018

@nshahan
Copy link
Contributor

nshahan commented Dec 4, 2018

@lejard-h Could you provide a minimal repro of the issue so we can see how the issue appears?

@lejard-h
Copy link
Contributor Author

DateFormat format = DateFormat('dd/MM/y');

<material-datepicker [outputFormat]="format"></material-datepicker>

and try to select October 8 for example, after you will need to double click on input to open dialog, and the date will be August 10

@lejard-h
Copy link
Contributor Author

lejard-h commented Jan 8, 2019

This does not seem to handle every case, it works on my timezone but this is probably an intl issue.

if you take the following code

  final format = DateFormat('dd/MM/y');

  final str = '05/08/2018';
  final date = format.parseLoose(str);

  print(date);
  print(format.format(date));

it print 2018-08-05 00:00:00.000 and 05/08/2018 with Europe/Paris timezone

but with America/Denver

FormatException: Error parsing 05/08/2018, invalid hour value: 0. Expected value between 15 and 15. Date parsed as 2018-08-04 15:00:00.000. at package:intl/src/intl/date_format_helpers.dart 130:7

I will follow the bug to intl package

Copy link
Contributor

@cpelling cpelling left a comment

Choose a reason for hiding this comment

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

Thanks for the PR. The general approach looks good, but I'd want to see a regression test before merging this. Left a couple of other comments also.

/// Returns the parsed date, or null if the string didn't match any format.
Date _parseDateUsingFormatList(String input, List<DateFormat> formatList) {
Date date;
formatList.any((format) {
Copy link
Contributor

Choose a reason for hiding this comment

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

While you're here, can you replace this .any() call with a regular for loop? This construction is pretty odd.

// DateTime's max allowed time
return false;
}
date = _parseDateUsingFormat(input, format);
Copy link
Contributor

Choose a reason for hiding this comment

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

Careful - this is the member variable date, not a local. We should define a local variable to avoid interfering with the state of the component.

Ideally this method would be static.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes I just had an issue about this, this should be fix now but I will do some renaming work to avoid it and make it static

nshahan pushed a commit that referenced this pull request May 31, 2019
fix date_input not using dateFormat to parse
use the given `dateFormat` to decode the input value.

for the following format `dd/mm/yy`, the parser was inversing month and days, `08/12/2018` -> `12/08/2018`

Closes #360

PiperOrigin-RevId: 244367402
@nshahan nshahan closed this in 967171d May 31, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants