Bug 794585 - unnecessary additional empty week row printed in monthly layout; Bug 792061 - incorrect dates printed in weekly layout r=philipp
This commit is contained in:
Родитель
8776b5f5e8
Коммит
da32c49e39
|
@ -424,20 +424,6 @@ let cal = {
|
|||
return newDate;
|
||||
},
|
||||
|
||||
userWeekStart: function userWeekStart(dt) {
|
||||
let wkst = cal.getPrefSafe("calendar.week.start", 0);
|
||||
let wkstDate = dt.clone();
|
||||
wkstDate.day -= (wkstDate.weekday - wkst + 7) % 7;
|
||||
return wkstDate;
|
||||
},
|
||||
|
||||
userWeekEnd: function userWeekEnd(dt) {
|
||||
let wkst = cal.getPrefSafe("calendar.week.start", 0);
|
||||
let wkendDate = dt.clone();
|
||||
wkendDate.day += (7 - wkendDate.weekday) + wkst;
|
||||
return wkendDate;
|
||||
},
|
||||
|
||||
sortEntry: function cal_sortEntry(aItem) {
|
||||
let key = cal.getItemSortKey(aItem, this.mSortKey, this.mSortStartedDate);
|
||||
return { mSortKey : key, mItem: aItem };
|
||||
|
|
|
@ -38,38 +38,15 @@ calMonthPrinter.prototype = {
|
|||
|
||||
// Make sure to create tables from start to end, if passed
|
||||
if (aStart && aEnd) {
|
||||
// Make sure the start date is really a date.
|
||||
let startDate = aStart.clone();
|
||||
startDate.isDate = true;
|
||||
|
||||
// Copy end date, which is exclusive. For our calculations, we will
|
||||
// only be handling dates and the below code is much cleaner with
|
||||
// the range being inclusive.
|
||||
let endDate = aEnd.clone();
|
||||
endDate.isDate = true;
|
||||
|
||||
// Find out if the start date is also shown in the first week of the
|
||||
// following month. This means we can spare a month printout.
|
||||
let probeDate = startDate.clone();
|
||||
probeDate.month++;
|
||||
probeDate.day = 1;
|
||||
if (cal.userWeekStart(probeDate).compare(startDate) <= 0) {
|
||||
startDate = probeDate;
|
||||
} else {
|
||||
startDate = startDate.startOfMonth;
|
||||
}
|
||||
|
||||
// Find out if the end date is also shown in the last week of the
|
||||
// previous month. This also means we can spare a month printout.
|
||||
probeDate = endDate.clone();
|
||||
probeDate.month--;
|
||||
probeDate = probeDate.endOfMonth;
|
||||
if (cal.userWeekEnd(probeDate).compare(endDate) >= 0) {
|
||||
endDate = probeDate;
|
||||
}
|
||||
let startDate = this.normalizeStartDate(aStart);
|
||||
let endDate = this.normalizeEndDate(aEnd);
|
||||
let weekInfoService = cal.getWeekInfoService();
|
||||
|
||||
// Now set up all the months we need to
|
||||
for (let current = startDate.clone(); cal.userWeekEnd(current).compare(endDate) <= 0; current.month += 1) {
|
||||
for (let current = startDate.clone();
|
||||
weekInfoService.getEndOfWeek(current.endOfMonth).compare(endDate) < 0;
|
||||
current.month += 1)
|
||||
{
|
||||
this.setupMonth(document, current, dayTable);
|
||||
}
|
||||
}
|
||||
|
@ -124,7 +101,44 @@ calMonthPrinter.prototype = {
|
|||
convStream.writeString(html);
|
||||
},
|
||||
|
||||
setupMonth: function setupMonth(document, startOfMonth, dayTable) {
|
||||
normalizeStartDate: function monthPrint_normalizeStartDate(aStart) {
|
||||
// Make sure the start date is really a date.
|
||||
let startDate = aStart.clone();
|
||||
startDate.isDate = true;
|
||||
|
||||
// Find out if the start date is also shown in the first week of the
|
||||
// following month. This means we can spare a month printout.
|
||||
let firstDayOfNextMonth = startDate.clone();
|
||||
firstDayOfNextMonth.day = 1;
|
||||
firstDayOfNextMonth.month++;
|
||||
if (cal.getWeekInfoService().getStartOfWeek(firstDayOfNextMonth).compare(startDate) <= 0) {
|
||||
startDate = firstDayOfNextMonth;
|
||||
} else {
|
||||
startDate = startDate.startOfMonth;
|
||||
}
|
||||
return startDate;
|
||||
},
|
||||
|
||||
normalizeEndDate: function monthPrint_normalizeEndDate(aEnd) {
|
||||
// Copy end date, which is exclusive. For our calculations, we will
|
||||
// only be handling dates and the formatToHtml() code is much cleaner with
|
||||
// the range being inclusive.
|
||||
let endDate = aEnd.clone();
|
||||
endDate.isDate = true;
|
||||
|
||||
// Find out if the end date is also shown in the last week of the
|
||||
// previous month. This also means we can spare a month printout.
|
||||
lastDayOfPreviousMonth = endDate.clone();
|
||||
lastDayOfPreviousMonth.month--;
|
||||
lastDayOfPreviousMonth = lastDayOfPreviousMonth.endOfMonth;
|
||||
if (cal.getWeekInfoService().getEndOfWeek(lastDayOfPreviousMonth).compare(endDate) >= 0) {
|
||||
endDate = lastDayOfPreviousMonth;
|
||||
}
|
||||
|
||||
return endDate;
|
||||
},
|
||||
|
||||
setupMonth: function monthPrint_setupMonth(document, startOfMonth, dayTable) {
|
||||
let monthTemplate = document.getElementById("month-template");
|
||||
let monthContainer = document.getElementById("month-container");
|
||||
|
||||
|
@ -147,8 +161,9 @@ calMonthPrinter.prototype = {
|
|||
}
|
||||
|
||||
// Set up each week
|
||||
let endOfMonthView = cal.userWeekEnd(startOfMonth.endOfMonth);
|
||||
let startOfMonthView = cal.userWeekStart(startOfMonth);
|
||||
let weekInfoService = cal.getWeekInfoService();
|
||||
let endOfMonthView = weekInfoService.getEndOfWeek(startOfMonth.endOfMonth);
|
||||
let startOfMonthView = weekInfoService.getStartOfWeek(startOfMonth);
|
||||
let mainMonth = startOfMonth.month;
|
||||
let weekContainer = currentMonth.querySelector(".week-container");
|
||||
|
||||
|
@ -166,7 +181,7 @@ calMonthPrinter.prototype = {
|
|||
cal.binaryInsertNode(monthContainer, currentMonth, currentMonth.item, compareDates);
|
||||
},
|
||||
|
||||
setupWeek: function setupWeek(document, weekContainer, startOfWeek, mainMonth, dayTable) {
|
||||
setupWeek: function monthPrint_setupWeek(document, weekContainer, startOfWeek, mainMonth, dayTable) {
|
||||
const weekdayMap = ["sunday", "monday", "tuesday", "wednesday", "thursday", "friday", "saturday"];
|
||||
let weekTemplate = document.getElementById("week-template");
|
||||
|
||||
|
|
|
@ -28,7 +28,6 @@ calWeekPrinter.prototype = {
|
|||
get name() cal.calGetString("calendar", "weekPrinterName"),
|
||||
|
||||
formatToHtml: function weekPrint_format(aStream, aStart, aEnd, aCount, aItems, aTitle) {
|
||||
let dateFormatter = cal.getDateFormatter();
|
||||
let document = cal.xml.parseFile("chrome://calendar/skin/printing/calWeekPrinter.html");
|
||||
|
||||
// Set page title
|
||||
|
@ -36,13 +35,11 @@ calWeekPrinter.prototype = {
|
|||
|
||||
// Table that maps YYYY-MM-DD to the DOM node container where items are to be added
|
||||
let dayTable = {};
|
||||
let weekInfoService = cal.getWeekInfoService();
|
||||
|
||||
// Make sure to create tables from start to end, if passed
|
||||
if (aStart && aEnd) {
|
||||
let startDate = aStart.clone();
|
||||
startDate.isDate = true;
|
||||
|
||||
for (let current = cal.userWeekStart(startDate); current.compare(aEnd) < 0; current.day += 7) {
|
||||
for (let current = weekInfoService.getStartOfWeek(aStart); current.compare(aEnd) < 0; current.day += 7) {
|
||||
this.setupWeek(document, current, dayTable);
|
||||
}
|
||||
}
|
||||
|
@ -71,7 +68,7 @@ calWeekPrinter.prototype = {
|
|||
|
||||
if (!(boxDateKey in dayTable)) {
|
||||
// Doesn't exist, we need to create a new table for it
|
||||
let startOfWeek = boxDate.startOfWeek;
|
||||
let startOfWeek = weekInfoService.getStartOfWeek(boxDate);
|
||||
this.setupWeek(document, startOfWeek, dayTable);
|
||||
}
|
||||
|
||||
|
@ -91,7 +88,7 @@ calWeekPrinter.prototype = {
|
|||
convStream.writeString(html);
|
||||
},
|
||||
|
||||
setupWeek: function setupWeek(document, startOfWeek, dayTable) {
|
||||
setupWeek: function weekPrint_setupWeek(document, startOfWeek, dayTable) {
|
||||
const weekdayMap = ["sunday", "monday", "tuesday", "wednesday", "thursday", "friday", "saturday"];
|
||||
|
||||
let weekTemplate = document.getElementById("week-template");
|
||||
|
@ -100,7 +97,6 @@ calWeekPrinter.prototype = {
|
|||
|
||||
// Clone the template week and make sure it doesn't have an id
|
||||
let currentPage = weekTemplate.cloneNode(true);
|
||||
let startOfWeekKey = cal.print.getDateKey(startOfWeek);
|
||||
currentPage.removeAttribute("id");
|
||||
currentPage.item = startOfWeek.clone();
|
||||
|
||||
|
@ -111,10 +107,9 @@ calWeekPrinter.prototype = {
|
|||
let weekTitle = cal.calGetString("calendar", 'WeekTitle', [weekno]);
|
||||
currentPage.querySelector(".week-number").textContent = weekTitle;
|
||||
|
||||
|
||||
// Set up the day boxes
|
||||
let endOfWeek = cal.userWeekEnd(startOfWeek);
|
||||
for (let currentDate = startOfWeek; currentDate.compare(endOfWeek) <= 0; currentDate.day++) {
|
||||
let endOfWeek = weekInfo.getEndOfWeek(startOfWeek);
|
||||
for (let currentDate = startOfWeek.clone(); currentDate.compare(endOfWeek) <= 0; currentDate.day++) {
|
||||
let weekday = currentDate.weekday;
|
||||
let weekdayName = weekdayMap[weekday];
|
||||
let dayOffPrefName = "calendar.week.d" + weekday + weekdayName + "soff";
|
||||
|
|
Загрузка…
Ссылка в новой задаче