Moment.js - Beginn der Woche am Montag mit isoWeekday ()

Ich erstelle einen Kalender, in dem ich Wochen tabellarisch ausdrucken kann. Eine Voraussetzung ist, dass ich die Wochen entweder am Montag oder am Sonntag starten kann, je nach Benutzeroption. Momente zu nutzen fällt mir schwerisoWeekday Methode.

// Start of some date range. Can be any day of the week.
var startOfPeriod = moment("2013-06-23T00:00:00"),

    // We begin on the start of the first week.
    // Mon Tues Wed Thur Fri Sat Sun
    // 20  21   22  23   24  25  26
    begin = moment(startOfPeriod).isoWeekday(1); // will pull from user setting

console.log(begin.isoWeekday()); // 1 - all good

// Let's get the beginning of this first week, respecting the isoWeekday
begin.startOf('week');

console.log(begin.isoWeekday()); // 7 - what happened ???

// Get column headers
for (var i=0; i<7; i++) {
    console.log(begin.format('ddd')); // I want Monday first!
    begin.add('d', 1);
}

jsFiddle

BEARBEITEN Ich habe was falsch verstandenisoWeekday tat eigentlich. Ich dachte, es wird die Variable "Welcher Wochentag ist der erste Wochentag" gesetzt (die es nicht gibt). Eigentlich ändert es einfach den Wochentag, genau wiemoment.weekday(), verwendet aber einen 1-7-Bereich anstelle von 0-6.

Antworten auf die Frage(6)

Ihre Antwort auf die Frage