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

Comments

2 participants
@emwee

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

This comment has been minimized.

Show comment
Hide comment
@gpbl

gpbl Sep 9, 2016

Owner

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.

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 gpbl added the docs label Sep 9, 2016

@gpbl

This comment has been minimized.

Show comment
Hide comment
@gpbl

gpbl Sep 9, 2016

Owner

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

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 from firstDayOfWeek does not seem to be respected? to Week names should respect the first day of week Sep 9, 2016

@gpbl gpbl changed the title from Week names should respect the first day of week to Weekday names should respect the first day of week Sep 9, 2016

@gpbl gpbl added this to the Next milestone Sep 9, 2016

@gpbl

This comment has been minimized.

Show comment
Hide comment
@gpbl

gpbl Sep 9, 2016

Owner

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

Owner

gpbl commented Sep 9, 2016

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

@emwee

This comment has been minimized.

Show comment
Hide comment
@emwee

emwee 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 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 Sep 9, 2016

@gpbl gpbl reopened this Sep 9, 2016

@gpbl

This comment has been minimized.

Show comment
Hide comment
@gpbl

gpbl Sep 9, 2016

Owner

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

Owner

gpbl commented Sep 9, 2016

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

@emwee

This comment has been minimized.

Show comment
Hide comment
@emwee

emwee commented Sep 9, 2016

👍

@gpbl

This comment has been minimized.

Show comment
Hide comment
@gpbl

gpbl Oct 11, 2016

Owner

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

Owner

gpbl commented Oct 11, 2016

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

@gpbl gpbl closed this Oct 11, 2016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment