Baremetrics / calendar

Date range picker for Baremetrics
MIT License
679 stars 78 forks source link

Locale/option based first day of the week #32

Closed enekochan closed 8 years ago

enekochan commented 8 years ago

Right now the first day of the week is set to Sunday as it is used in en_US. But lots of languages, spanish for example, use other day, usually Monday, as first day of the week. We already have text and dates translations/localization which is great but this new feature I think should be a must.

I've tried myself coding this feature but failed. The only thing I've managed to change is the order of the days array (S, M, T, ...) based on moment().localeData().firstDayOfWeek() replacing this code in Calendar.prototype.calendarHTML:

$.each(this.days_array || moment.weekdaysMin(), function(i, elem) {
  ul_days_of_the_week.append('<li class="dr-day-of-week">' + elem + '</li>'); 
});

With this code:

var days = this.days_array || moment.weekdaysMin();
days = days.splice(moment().localeData().firstDayOfWeek()).concat(days.splice(0, moment().localeData().firstDayOfWeek()));
$.each(days, function(i, elem) {
  ul_days_of_the_week.append('<li class="dr-day-of-week">' + elem + '</li>'); 
});
cissav commented 8 years ago

Any news on this one?

kalepail commented 8 years ago

No not yet as we don't currently need this for Baremetrics. I also haven't heard much from other people needing this feature. I don't think it'd be super hard to do but it'd take some time to think through the best way. You'd definitely want it to be an option, though maybe a function option that doesn't automatically do anything until you explicitly tell it which day of the week it should start the week on.

kalepail commented 8 years ago

Added in https://github.com/Baremetrics/calendar/releases/tag/v1.0.6