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

feat(calendar): add firstDayOfWeek and days abbreviations #2899

Merged
merged 1 commit into from
Jan 18, 2016

Conversation

balthazar
Copy link
Contributor

This commit adds the ability to set the firstDayOfWeek for Europeans that often starts on monday rather than sunday, and to set a days abbreviations array for days first letter.

This part could be improved though, but don't really know how, feel free to tell me if you got an idea.

Related to #2099.

* Used to change the first day of week
* Defaults to 0 (Sunday)
*/
firstDayOfWeek: React.PropTypes.number,
Copy link
Member

Choose a reason for hiding this comment

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

Can't we use Intl to do this work for us?
This can help #2282

@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 and removed PR: Needs Review labels Jan 17, 2016
@balthazar
Copy link
Contributor Author

@oliviertassinari Thanks, I will update my PR and ping again

@balthazar
Copy link
Contributor Author

I though it would be a little overkill to create 7 dates only to find a char, don't we have any way to access the Intl locales without having to do this?

@balthazar
Copy link
Contributor Author

@oliviertassinari I got the Intl for the days abbreviations, but I dunno how to get the first day of the week without having to rely on the getDate method of the Date object, which doesn't seems to follow the current locale.

@oliviertassinari
Copy link
Member

Sorry, this diff is unavailable.

😁

I got the Intl for the days abbreviations

Awesome!

but I dunno how to get the first day of the week without having to rely on the getDate method of the Date object, which doesn't seems to follow the current locale.

Yeah, I think that it's the most difficult point.

@balthazar
Copy link
Contributor Author

Ah sorry, I thought rebasing would be better.

Any idea why the build cannot seems to find the Intl variable?

@oliviertassinari
Copy link
Member

Any idea why the build cannot seems to find the Intl variable?

I can't see the line changes right now.

Regarding the latest point. Basically, we are looking for something like: http://momentjs.com/docs/#/get-set/iso-weekday/.

@balthazar
Copy link
Contributor Author

Will try to fix the commit.

Hum yeah, I thought you didn't want to add an extra dependency like moment, but it would be pretty easy with it yes

@oliviertassinari
Copy link
Member

I thought you didn't want to add an extra dependency like moment

I definitely want to avoid this. Here is their implementation https://github.com/moment/moment/blob/11b18a8c5e8a7970d38352f96f226c3351b89a43/src/lib/units/day-of-week.js#L154.

@balthazar
Copy link
Contributor Author

Okay the commit is now fixed, I removed the merge so you can see the diff.

Also I looked a bit this method and actually don't know how we can use it to fit our needs (my mind is really bad with dates and timezone 😄), and do we really will have to re-implement each method we need to not include a library?

@balthazar
Copy link
Contributor Author

@oliviertassinari I updated the changes to handle the build issue and use a fallback when Intl is not available. Would you consider merge this PR with the firstDayOfWeek parameter?

I'm thinking the changes with our own implementation of the first day detection would be out-of-range of this PR and might need a closer look to the possibilities

@oliviertassinari
Copy link
Member

Would you consider merge this PR with the firstDayOfWeek parameter?

If we don't have better option, yes, and in this case, It would be great to update the fr example of the documentation with firstDayOfWeek=1.

return new Date(now.setDate(now.getDate() - now.getDay()));
},

getWeekArray(d, firstDayOfWeek = 0) {
Copy link
Member

Choose a reason for hiding this comment

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

Can you set the default value in the getDefaultProps of the DateTimePicker component?
This will automatically be used by the documentation.

@balthazar
Copy link
Contributor Author

@oliviertassinari I changed the things you pointed out ;)

@balthazar
Copy link
Contributor Author

Wait I need to change something

@balthazar
Copy link
Contributor Author

@oliviertassinari All good 👌 I didn't worked when you didn't provided a DateTimeFormat.

Sorry for all the pings 😕

@@ -59,6 +60,7 @@ const Calendar = React.createClass({
selectedDate: this.props.initialDate,
transitionDirection: 'left',
transitionEnter: true,
daysArray: [...Array(7)],
Copy link
Member

Choose a reason for hiding this comment

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

This will be allocated for each instance of the component. Why not simply move daysArray outside of the component?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Like a global variable? Where do you want to put it exactly?

Copy link
Member

Choose a reason for hiding this comment

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

Yes, you can do something like:

....
import ThemeManager from '../styles/theme-manager';
import DefaultRawTheme from '../styles/raw-themes/light-raw-theme';

const daysArray = [...Array(7)];

const Calendar = React.createClass({
...

@oliviertassinari
Copy link
Member

Could you add firstDayOfWeek={1} to the DatePickerExampleInternational example?
That we improve our current french example.

Regarding firstDayOfWeek:

I'm thinking the changes with our own implementation of the first day detection would be out-of-range of this PR and might need a closer look to the possibilities

I agree, this is a related issue: tc39/ecma402#6.

@@ -43,6 +43,11 @@ const DatePicker = React.createClass({
disableYearSelection: React.PropTypes.bool,

/**
* Used to change the first day of week.
*/
firstDayOfWeek: React.PropTypes.number,
Copy link
Member

Choose a reason for hiding this comment

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

I think it would be good to add something link:
The first day of the week drastically varies between Saturday, Sunday, or Monday (or even Friday) between different locales.

@balthazar
Copy link
Contributor Author

@oliviertassinari I changed the docs, comments and the daysArray variable.

Nice catch for ecma the issue, really interesting

@oliviertassinari
Copy link
Member

@apercu Really nice PR 👍
@alitaheri @newoga Do you want to do a final review before merging?

@oliviertassinari oliviertassinari added 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 Jan 18, 2016
@mbrookes
Copy link
Member

Please could you note the use of the firstDayOfWeek property in docs/src/app/components/pages/components/DatePicker/Page.jsx in descriptions.localised?

* Used to change the first day of week. It drastically varies from
* Saturday to Monday (could even be Friday) between different locales.
*/
firstDayOfWeek: React.PropTypes.number,
Copy link
Member

Choose a reason for hiding this comment

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

Might not be a bad idea to clarify what the default value, 0 means Sunday.

Copy link
Member

Choose a reason for hiding this comment

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

I haven't though about this. I agree 😁

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Grrrr 😁 that's what I did in my first commit! 😄

Copy link
Member

Choose a reason for hiding this comment

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

Sorry 💫 !

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Haha no problem I'm kidding

@alitaheri
Copy link
Member

Great work @apercu, That one thing is my only concern. In my country the first day of week is Saturday. Although I know how america works. But I had to check the source to be sure. So a simple clarification can save the users a bit of time. Thanks for the awesome work 👍 👍

@mbrookes
Copy link
Member

@alitaheri - that's an interesting point. IMHO without localisation applied, I believe Material-UI date handling should be "international" by default. There's an open issue to make the default date displayed follow ISO8601 (YYYY-MM-DD), as the US format is ambiguous everywhere, including in the US!

By the same token, I think the default the first day of the week should be also follow ISO8601. This happens to be Monday for better or worse, but at least it would be consistent with a standard, rather than following one country's cultural norm.

@oliviertassinari
Copy link
Member

By the same token, I think the default the first day of the week should be also follow ISO8601. This happens to be Monday for better or worse, but at least it would be consistent with a standard

I agree, but we have to wait for the next breaking changes release.

@alitaheri
Copy link
Member

@mbrookes I completely agree. Following the standard is the best possible way to tackle this. But as @oliviertassinari said, it will have to wait since it's a breaking change. so we need to find a way to ease into it or find a way to warn the users ahead of time if transition is not possible.

@mbrookes
Copy link
Member

Yeah, don't want to stand in the way of this PR. Great work BTW @apercu!

@newoga
Copy link
Contributor

newoga commented Jan 18, 2016

@alitaheri @oliviertassinari Sorry, I've been absolutely slammed.If you both are satisfied, feel free to merge. Seems like there might be some topics to revisit but if the code quality is solid, I'm happy 😄

I'll review the changes either way tonight

Edit: Looked very quickly, this seems like it's pretty low risk. I'm good! Thanks @apercu!

@balthazar
Copy link
Contributor Author

I updated the commit to match the review of @alitaheri.

For the point raised by @mbrookes I totally agree, but do you think we will remember to change this in the next breaking version?

oliviertassinari added a commit that referenced this pull request Jan 18, 2016
[DatePicker] Add firstDayOfWeek and days abbreviations
@oliviertassinari oliviertassinari merged commit aa059c7 into mui:master Jan 18, 2016
@oliviertassinari oliviertassinari mentioned this pull request Jan 18, 2016
8 tasks
@oliviertassinari
Copy link
Member

@apercu Thanks 🎉 !

but do you think we will remember to change this in the next breaking version

I have added it here: #2109.

@balthazar
Copy link
Contributor Author

@oliviertassinari @alitaheri @mbrookes @newoga Thanks for the positive feedbacks and your work! Happy to contribute 🎉

(Should be the last ping from me (on this PR!) 😄)

@alitaheri
Copy link
Member

Thanks a lot, this was surely an important feature to have! 👍 🎉 🎉

@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.

6 participants