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

[DatePicker] Default to ISO-8601 DateTimeFormat & firstDayOfWeek #3417

Merged
merged 1 commit into from
Feb 26, 2016
Merged

[DatePicker] Default to ISO-8601 DateTimeFormat & firstDayOfWeek #3417

merged 1 commit into from
Feb 26, 2016

Conversation

mbrookes
Copy link
Member

Closes #1839 #2980.

path.resolve(__dirname, '../src/svg-icons'),
],
},

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, let's kill this 😁.

Copy link
Member

Choose a reason for hiding this comment

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

I couldn't find a way to just output warnings without blocking the build.

Copy link
Member

Choose a reason for hiding this comment

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

I wanted to try to make it optional, but then I see it doesn't work well with docs either, so: npm start !== npm run lint. Let's kill it before it lays eggs 🙀

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, let's kill this 😁.

Oops! Must have git commit -am after carefully adding the individual files.

If you;re serious about killing this though, I'll leave it. 👍

Copy link
Member

Choose a reason for hiding this comment

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

Count me in 👿 🔫 😎

Copy link
Member Author

Choose a reason for hiding this comment

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

I decided to put it back, and I'll kill it in a separate PR, as we reference it in contributing.md, so a separate PR will be cleaner as I can edit that at the same time. When I do, should I remove the whole preloaders section, or leave it empty for future reference?

Copy link
Member

Choose a reason for hiding this comment

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

I'd say remove it. like how we should remove unused vars. less clutter = less confusion 👍

@mbrookes
Copy link
Member Author

Okay, moved the ISO date formatter to DateTime.format, which also solves the docs issue.

The linter is throwing a fit though...

@oliviertassinari
Copy link
Member

@mbrookes That looks good so far 👍. Side question. What are we going to do with the documentation? Is this ok to have Monday as the default starting day?

@mbrookes
Copy link
Member Author

Good point. Well, we no longer need to change the firstDayOfWeek for the fr example, but maybe we can have a US locale example that sets firstDayOfWeek to Sunday, and reinstates the wonky US date format ;-)

@oliviertassinari oliviertassinari added PR: needs revision The pull request can't be merged. More details is available on the code review or fails in the CI PR: Needs Review and removed PR: needs revision The pull request can't be merged. More details is available on the code review or fails in the CI labels Feb 22, 2016
/>
<DatePicker
hintText="en-US version"
formatDate={(date) => date.toLocaleDateString()}
Copy link
Member Author

Choose a reason for hiding this comment

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

While toLocaleDateString() doesn't reliably convert the date to the user's locale across all browsers (some return US date format regardless), it should reliably show US date format for US users. Is that sufficient?

Copy link
Member

Choose a reason for hiding this comment

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

I don't get it, why can't we use the default formatDate?

Copy link
Member Author

Choose a reason for hiding this comment

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

Because the default is ISO 8601? That's kind of the point of this PR. 😉

Copy link
Member

Choose a reason for hiding this comment

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

Good point! So, what about

new DateTimeFormat('en-US', {
    day: 'numeric',
    month: 'numeric',
    year: 'numeric',
  }).format(date) // 2/25/2016
``

Copy link
Member Author

Choose a reason for hiding this comment

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

But I can use your DateTimeFormat example as a safer alternative to date.toLocaleDateString().

@mbrookes
Copy link
Member Author

What do you think about the idea of modifying formatDate to pass the locale if present, as well as the date to format?

Alternatively / additionally, what if we internalised that, so that defaultDate uses the provided locale and DateTimeFormat if an alternative formatDate isn't provided?

@oliviertassinari
Copy link
Member

What do you think about the idea of modifying formatDate to pass the locale if present, as well as the date to format?

I don't really mind. This has advantages and drawbacks.

@mbrookes
Copy link
Member Author

This has advantages and drawbacks.

What drawbacks specifically?

Also:

Alternatively / additionally, what if we internalised that, so that defaultDate uses the provided locale and DateTimeFormat if an alternative formatDate isn't provided?

Any thoughts?

@oliviertassinari
Copy link
Member

This new local argument would make the life easier for someone how want to implement the formatDate. However, that's adding a bit of complexity to the DatePicker component.
I feel like the advantage outperform the drawback 👍.

Any thoughts?

That sounds like an excellent idea. I wouldn't say it's a breaking changes, I see more this like an improvement. That would also make our i18n examples simpler 👍.

@mbrookes
Copy link
Member Author

That would also make our i18n examples simpler.

Exactly! 👌 (I realised when I started to update the examples...)

@mbrookes mbrookes added PR: needs revision The pull request can't be merged. More details is available on the code review or fails in the CI PR: Needs Review and removed PR: Needs Review PR: needs revision The pull request can't be merged. More details is available on the code review or fails in the CI labels Feb 25, 2016
@mbrookes
Copy link
Member Author

I've added localised formatting.

I also coded up adding locale to the formatDate parameters (it really doesn't add any complexity internally to DatePicker), but then realised that if locale is being set programatically from state or store, then the user's formatDate function could take it from there, and it probably doesn't need it to be passed in as a param.

Does that make sense?

// Use the native Intl if available
/**
* Use the native Intl.DateTimeFormat if available, or a polyfill if not.
*/
if (areIntlLocalesSupported('fr')) {
Copy link
Member

Choose a reason for hiding this comment

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

if (areIntlLocalesSupported(['fr', 'en-US'])) {

Copy link
Member Author

Choose a reason for hiding this comment

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

How did I miss that?! Although when I tested in Safari, which is the only mainstream desktop browser that doesn't support Intl, it worked fine (presumably since it's a binary condition).

Anyway, good catch (as always!). Updating now.

Copy link
Member

Choose a reason for hiding this comment

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

Well, that's not a big deal. I'm pretty sure that if fr is available, en-US is also available.

@oliviertassinari
Copy link
Member

it probably doesn't need it to be passed in as a param

That's the complexity I was talking about 😁.

@mbrookes Could you have a look at my comment? Otherwise, that looks awesome 👍!

@mbrookes
Copy link
Member Author

Updated. Thanks!

@oliviertassinari
Copy link
Member

Could you squash down?

@mbrookes
Copy link
Member Author

Done. 👍

@alitaheri
Copy link
Member

This was a great work @mbrookes 👍 👍 Thanks a lot 😁

alitaheri added a commit that referenced this pull request Feb 26, 2016
[DatePicker] Default to ISO-8601 DateTimeFormat & firstDayOfWeek
@alitaheri alitaheri merged commit 100dfa2 into mui:master Feb 26, 2016
@mbrookes mbrookes deleted the datepicker-iso8601 branch March 19, 2016 01:25
@zannager zannager added component: date picker This is the name of the generic UI component, not the React module! component: pickers This is the name of the generic UI component, not the React module! labels Mar 15, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: date picker This is the name of the generic UI component, not the React module! component: pickers This is the name of the generic UI component, not the React module!
Projects
None yet
Development

Successfully merging this pull request may close these issues.

DatePicker textfiled value should follow ISO 8601 by default
4 participants