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:
Stefan Sitter 2012-10-08 19:49:53 +02:00
Родитель 8776b5f5e8
Коммит da32c49e39
3 изменённых файлов: 55 добавлений и 59 удалений

Просмотреть файл

@ -424,20 +424,6 @@ let cal = {
return newDate; 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) { sortEntry: function cal_sortEntry(aItem) {
let key = cal.getItemSortKey(aItem, this.mSortKey, this.mSortStartedDate); let key = cal.getItemSortKey(aItem, this.mSortKey, this.mSortStartedDate);
return { mSortKey : key, mItem: aItem }; return { mSortKey : key, mItem: aItem };

Просмотреть файл

@ -38,38 +38,15 @@ calMonthPrinter.prototype = {
// Make sure to create tables from start to end, if passed // Make sure to create tables from start to end, if passed
if (aStart && aEnd) { if (aStart && aEnd) {
// Make sure the start date is really a date. let startDate = this.normalizeStartDate(aStart);
let startDate = aStart.clone(); let endDate = this.normalizeEndDate(aEnd);
startDate.isDate = true; let weekInfoService = cal.getWeekInfoService();
// 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;
}
// Now set up all the months we need to // 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); this.setupMonth(document, current, dayTable);
} }
} }
@ -124,7 +101,44 @@ calMonthPrinter.prototype = {
convStream.writeString(html); 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 monthTemplate = document.getElementById("month-template");
let monthContainer = document.getElementById("month-container"); let monthContainer = document.getElementById("month-container");
@ -147,8 +161,9 @@ calMonthPrinter.prototype = {
} }
// Set up each week // Set up each week
let endOfMonthView = cal.userWeekEnd(startOfMonth.endOfMonth); let weekInfoService = cal.getWeekInfoService();
let startOfMonthView = cal.userWeekStart(startOfMonth); let endOfMonthView = weekInfoService.getEndOfWeek(startOfMonth.endOfMonth);
let startOfMonthView = weekInfoService.getStartOfWeek(startOfMonth);
let mainMonth = startOfMonth.month; let mainMonth = startOfMonth.month;
let weekContainer = currentMonth.querySelector(".week-container"); let weekContainer = currentMonth.querySelector(".week-container");
@ -166,7 +181,7 @@ calMonthPrinter.prototype = {
cal.binaryInsertNode(monthContainer, currentMonth, currentMonth.item, compareDates); 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"]; const weekdayMap = ["sunday", "monday", "tuesday", "wednesday", "thursday", "friday", "saturday"];
let weekTemplate = document.getElementById("week-template"); let weekTemplate = document.getElementById("week-template");

Просмотреть файл

@ -28,7 +28,6 @@ calWeekPrinter.prototype = {
get name() cal.calGetString("calendar", "weekPrinterName"), get name() cal.calGetString("calendar", "weekPrinterName"),
formatToHtml: function weekPrint_format(aStream, aStart, aEnd, aCount, aItems, aTitle) { 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"); let document = cal.xml.parseFile("chrome://calendar/skin/printing/calWeekPrinter.html");
// Set page title // 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 // Table that maps YYYY-MM-DD to the DOM node container where items are to be added
let dayTable = {}; let dayTable = {};
let weekInfoService = cal.getWeekInfoService();
// Make sure to create tables from start to end, if passed // Make sure to create tables from start to end, if passed
if (aStart && aEnd) { if (aStart && aEnd) {
let startDate = aStart.clone(); for (let current = weekInfoService.getStartOfWeek(aStart); current.compare(aEnd) < 0; current.day += 7) {
startDate.isDate = true;
for (let current = cal.userWeekStart(startDate); current.compare(aEnd) < 0; current.day += 7) {
this.setupWeek(document, current, dayTable); this.setupWeek(document, current, dayTable);
} }
} }
@ -71,7 +68,7 @@ calWeekPrinter.prototype = {
if (!(boxDateKey in dayTable)) { if (!(boxDateKey in dayTable)) {
// Doesn't exist, we need to create a new table for it // 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); this.setupWeek(document, startOfWeek, dayTable);
} }
@ -91,7 +88,7 @@ calWeekPrinter.prototype = {
convStream.writeString(html); 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"]; const weekdayMap = ["sunday", "monday", "tuesday", "wednesday", "thursday", "friday", "saturday"];
let weekTemplate = document.getElementById("week-template"); 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 // Clone the template week and make sure it doesn't have an id
let currentPage = weekTemplate.cloneNode(true); let currentPage = weekTemplate.cloneNode(true);
let startOfWeekKey = cal.print.getDateKey(startOfWeek);
currentPage.removeAttribute("id"); currentPage.removeAttribute("id");
currentPage.item = startOfWeek.clone(); currentPage.item = startOfWeek.clone();
@ -111,10 +107,9 @@ calWeekPrinter.prototype = {
let weekTitle = cal.calGetString("calendar", 'WeekTitle', [weekno]); let weekTitle = cal.calGetString("calendar", 'WeekTitle', [weekno]);
currentPage.querySelector(".week-number").textContent = weekTitle; currentPage.querySelector(".week-number").textContent = weekTitle;
// Set up the day boxes // Set up the day boxes
let endOfWeek = cal.userWeekEnd(startOfWeek); let endOfWeek = weekInfo.getEndOfWeek(startOfWeek);
for (let currentDate = startOfWeek; currentDate.compare(endOfWeek) <= 0; currentDate.day++) { for (let currentDate = startOfWeek.clone(); currentDate.compare(endOfWeek) <= 0; currentDate.day++) {
let weekday = currentDate.weekday; let weekday = currentDate.weekday;
let weekdayName = weekdayMap[weekday]; let weekdayName = weekdayMap[weekday];
let dayOffPrefName = "calendar.week.d" + weekday + weekdayName + "soff"; let dayOffPrefName = "calendar.week.d" + weekday + weekdayName + "soff";