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

Weekday names should respect the first day of week #207

Closed
emwee opened this issue Sep 8, 2016 · 7 comments
Closed

Weekday names should respect the first day of week #207

emwee opened this issue Sep 8, 2016 · 7 comments

Comments

@emwee
Copy link

emwee commented Sep 8, 2016

I want my calendar to let week starts on Monday. The API is pretty much straight-forward, but I can't get it to work.

My code:

const localeUtils = {
    formatDay: (d, locale='en') => formatDate(d, 'LLLL'),
    formatMonthTitle: (d, locale) => moment.months()[d.getMonth()],
    formatWeekdayShort: (i, locale) =>  moment.weekdaysShort()[i],
    formatWeekdayLong: (i, locale) => moment.weekdays()[i],
    getFirstDayOfWeek: (locale) => 0,
}

const Datepicker = props =>
    <DayPicker
        localeUtils={localeUtils}
    />

It doesn't matter if getFirstDayOfWeek returns 0 or 1, the first weekday is always Sunday.

I am using version 2.4.1.

@gpbl gpbl added the question label Sep 9, 2016
@gpbl
Copy link
Owner

gpbl commented Sep 9, 2016

Hi @emwee!
Yeah that's not clear from the examples: if you want to set the first day to Monday, also your weekdays names should start on Monday.

@gpbl
Copy link
Owner

gpbl commented Sep 9, 2016

(Sorry my previous comment included a code sample that didn't work, the trick is making the weeks name array starting from monday)

@gpbl gpbl changed the title firstDayOfWeek does not seem to be respected? Week names should respect the first day of week Sep 9, 2016
@gpbl gpbl changed the title Week names should respect the first day of week Weekday names should respect the first day of week Sep 9, 2016
@gpbl gpbl added bug and removed question labels Sep 9, 2016
@gpbl gpbl added this to the Next milestone Sep 9, 2016
@gpbl
Copy link
Owner

gpbl commented Sep 9, 2016

I'm filing this as bug as I agree it is an unexpected behavior :)

@emwee
Copy link
Author

emwee commented Sep 9, 2016

Alright, fixed it the way you suggested for now. Thanks! :-)


const getWeekdayByIndex = (weekdays, i) =>
    weekdays[(i + 1) < weekdays.length ? i + 1 : 0]

export const localeUtils = {
    formatDay: (d, locale='en') => formatDate(d, 'LLLL'),
    formatMonthTitle: (d, locale) => moment.months()[d.getMonth()],
    formatWeekdayShort: (i, locale) => getWeekdayByIndex(moment.weekdaysShort(), i),
    formatWeekdayLong: (i, locale) => getWeekdayByIndex(moment.weekdays(), i),
    getFirstDayOfWeek: () => 1,
}

@emwee emwee closed this as completed Sep 9, 2016
@gpbl gpbl reopened this Sep 9, 2016
@gpbl
Copy link
Owner

gpbl commented Sep 9, 2016

Nice !! Reopening this as i'd like to fix it in the next major release.

@emwee
Copy link
Author

emwee commented Sep 9, 2016

👍

@gpbl
Copy link
Owner

gpbl commented Oct 11, 2016

This has been fixed in v3 – no need anymore for the workaround above, @emwee !

@gpbl gpbl closed this as completed Oct 11, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants