-
-
Notifications
You must be signed in to change notification settings - Fork 32.2k
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
Conversation
* Used to change the first day of week | ||
* Defaults to 0 (Sunday) | ||
*/ | ||
firstDayOfWeek: React.PropTypes.number, |
There was a problem hiding this comment.
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 Thanks, I will update my PR and ping again |
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? |
@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 |
😁
Awesome!
Yeah, I think that it's the most difficult point. |
Ah sorry, I thought rebasing would be better. Any idea why the build cannot seems to find the |
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/. |
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 |
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. |
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? |
@oliviertassinari I updated the changes to handle the build issue and use a fallback when 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 |
If we don't have better option, yes, and in this case, It would be great to update the |
return new Date(now.setDate(now.getDate() - now.getDay())); | ||
}, | ||
|
||
getWeekArray(d, firstDayOfWeek = 0) { |
There was a problem hiding this comment.
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.
@oliviertassinari I changed the things you pointed out ;) |
Wait I need to change something |
@oliviertassinari All good 👌 I didn't worked when you didn't provided a Sorry for all the pings 😕 |
@@ -59,6 +60,7 @@ const Calendar = React.createClass({ | |||
selectedDate: this.props.initialDate, | |||
transitionDirection: 'left', | |||
transitionEnter: true, | |||
daysArray: [...Array(7)], |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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({
...
Could you add Regarding
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, |
There was a problem hiding this comment.
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.
@oliviertassinari I changed the docs, comments and the Nice catch for ecma the issue, really interesting |
@apercu Really nice PR 👍 |
Please could you note the use of the |
* 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, |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 😁
There was a problem hiding this comment.
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! 😄
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry 💫 !
There was a problem hiding this comment.
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
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 👍 👍 |
@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. |
I agree, but we have to wait for the next breaking changes release. |
@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. |
Yeah, don't want to stand in the way of this PR. Great work BTW @apercu! |
@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! |
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? |
[DatePicker] Add firstDayOfWeek and days abbreviations
@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!) 😄) |
…d abbreviations When it's available
Thanks a lot, this was surely an important feature to have! 👍 🎉 🎉 |
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.