Fix bug 794477 - jsDate setter can't handle a wrapped JS::Value. r=mmecca
--HG-- extra : rebase_source : 201b1d9d88c56a060e97d503913a820175cc0f56
This commit is contained in:
Родитель
7933762021
Коммит
93d597c3f0
|
@ -886,7 +886,7 @@ function setupContextItemType(event, items) {
|
|||
*/
|
||||
function minimonthPick(aNewDate) {
|
||||
if (cal.isSunbird() || gCurrentMode == "calendar" || gCurrentMode == "task") {
|
||||
let cdt = jsDateToDateTime(aNewDate, currentView().timezone);
|
||||
let cdt = cal.jsDateToDateTime(aNewDate, currentView().timezone);
|
||||
cdt.isDate = true;
|
||||
currentView().goToDay(cdt);
|
||||
|
||||
|
|
|
@ -340,8 +340,8 @@ function updateStartTime() {
|
|||
// jsDate is always in OS timezone, thus we create a calIDateTime
|
||||
// object from the jsDate representation and simply set the new
|
||||
// timezone instead of converting.
|
||||
var start = jsDateToDateTime(startWidget.value,
|
||||
gDisplayTimezone ? gStartTimezone : calendarDefaultTimezone());
|
||||
var start = cal.jsDateToDateTime(startWidget.value,
|
||||
gDisplayTimezone ? gStartTimezone : calendarDefaultTimezone());
|
||||
gStartDate = start.clone();
|
||||
start.addDuration(gDuration);
|
||||
gEndDate = start.getInTimezone(gEndTimezone);
|
||||
|
@ -374,7 +374,7 @@ function updateEndTime() {
|
|||
var saveEndTime = gEndDate;
|
||||
var kDefaultTimezone = calendarDefaultTimezone();
|
||||
|
||||
gStartDate = jsDateToDateTime(startWidget.value,
|
||||
gStartDate = cal.jsDateToDateTime(startWidget.value,
|
||||
gDisplayTimezone ? gStartTimezone : calendarDefaultTimezone());
|
||||
|
||||
var timezone = gEndTimezone;
|
||||
|
@ -383,8 +383,8 @@ function updateEndTime() {
|
|||
!compareObjects(gStartTimezone, gEndTimezone)) {
|
||||
timezone = gStartTimezone;
|
||||
}
|
||||
gEndDate = jsDateToDateTime(endWidget.value,
|
||||
gDisplayTimezone ? timezone : kDefaultTimezone);
|
||||
gEndDate = cal.jsDateToDateTime(endWidget.value,
|
||||
gDisplayTimezone ? timezone : kDefaultTimezone);
|
||||
|
||||
var allDayElement = document.getElementById("all-day");
|
||||
var allDay = allDayElement.getAttribute("checked") == "true";
|
||||
|
|
|
@ -693,7 +693,7 @@
|
|||
"@mozilla.org/calendar/datetime-formatter;1"]
|
||||
.getService(
|
||||
Components.interfaces.calIDateTimeFormatter);
|
||||
let date = jsDateToDateTime(new Date());
|
||||
let date = cal.jsDateToDateTime(new Date());
|
||||
date.hour = this.mStartHour;
|
||||
date.minute = 0;
|
||||
let height = this.parentNode.parentNode.boxObject.height - 1;
|
||||
|
|
|
@ -336,7 +336,7 @@ function onSave(item) {
|
|||
recRule.count = Math.max(1, getElementValue("repeat-ntimes-count"));
|
||||
break;
|
||||
case "until":
|
||||
let untilDate = jsDateToDateTime(getElementValue("repeat-until-date"), gStartTime.timezone);
|
||||
let untilDate = cal.jsDateToDateTime(getElementValue("repeat-until-date"), gStartTime.timezone);
|
||||
untilDate.isDate = gStartTime.isDate; // enforce same value type as DTSTART
|
||||
if (!gStartTime.isDate) {
|
||||
// correct UNTIL to exactly match start date's hour, minute, second:
|
||||
|
@ -594,7 +594,7 @@ function updatePreview() {
|
|||
* dialog when the user enters a wrong until date.
|
||||
*/
|
||||
function checkUntilDate() {
|
||||
let untilDate = jsDateToDateTime(getElementValue("repeat-until-date"), gStartTime.timezone);
|
||||
let untilDate = cal.jsDateToDateTime(getElementValue("repeat-until-date"), gStartTime.timezone);
|
||||
let startDate = gStartTime.clone();
|
||||
startDate.isDate = true;
|
||||
if (untilDate.compare(startDate) < 0) {
|
||||
|
|
|
@ -328,8 +328,8 @@ function updateReminder(event) {
|
|||
reminder.related = Components.interfaces.calIAlarm.ALARM_RELATED_ABSOLUTE;
|
||||
|
||||
if (absDate.value) {
|
||||
reminder.alarmDate = jsDateToDateTime(absDate.value,
|
||||
window.arguments[0].timezone);
|
||||
reminder.alarmDate = cal.jsDateToDateTime(absDate.value,
|
||||
window.arguments[0].timezone);
|
||||
} else {
|
||||
reminder.alarmDate = null;
|
||||
}
|
||||
|
|
|
@ -575,8 +575,8 @@ function dateTimeControls2State(aStartDatepicker) {
|
|||
// jsDate is always in OS timezone, thus we create a calIDateTime
|
||||
// object from the jsDate representation then we convert the timezone
|
||||
// in order to keep gStartTime in default timezone.
|
||||
gStartTime = jsDateToDateTime(getElementValue(startWidgetId),
|
||||
(timezonesEnabled || allDay) ? gStartTimezone : kDefaultTimezone);
|
||||
gStartTime = cal.jsDateToDateTime(getElementValue(startWidgetId),
|
||||
(timezonesEnabled || allDay) ? gStartTimezone : kDefaultTimezone);
|
||||
if (timezonesEnabled || allDay) {
|
||||
gStartTime = gStartTime.getInTimezone(kDefaultTimezone);
|
||||
}
|
||||
|
@ -596,8 +596,8 @@ function dateTimeControls2State(aStartDatepicker) {
|
|||
timezone = gStartTimezone;
|
||||
}
|
||||
}
|
||||
gEndTime = jsDateToDateTime(getElementValue(endWidgetId),
|
||||
(timezonesEnabled || allDay) ? timezone : kDefaultTimezone);
|
||||
gEndTime = cal.jsDateToDateTime(getElementValue(endWidgetId),
|
||||
(timezonesEnabled || allDay) ? timezone : kDefaultTimezone);
|
||||
if (timezonesEnabled || allDay) {
|
||||
gEndTime = gEndTime.getInTimezone(kDefaultTimezone);
|
||||
}
|
||||
|
@ -706,23 +706,23 @@ function updateDateCheckboxes(aDatePickerId, aCheckboxId, aDateTime) {
|
|||
setElementValue(aDatePickerId, getElementValue(aDatePickerId));
|
||||
|
||||
// first of all disable the datetime picker if we don't have a date
|
||||
var hasDate = getElementValue(aCheckboxId, "checked");
|
||||
let hasDate = getElementValue(aCheckboxId, "checked");
|
||||
setElementValue(aDatePickerId, !hasDate, "disabled");
|
||||
|
||||
// create a new datetime object if date is now checked for the first time
|
||||
if (hasDate && !aDateTime.isValid()) {
|
||||
var date = jsDateToDateTime(getElementValue(aDatePickerId), calendarDefaultTimezone());
|
||||
aDateTime.setDateTime(date);
|
||||
let dt = cal.jsDateToDateTime(getElementValue(aDatePickerId), cal.calendarDefaultTimezone());
|
||||
aDateTime.setDateTime(dt);
|
||||
} else if (!hasDate && aDateTime.isValid()) {
|
||||
aDateTime.setDateTime(null);
|
||||
}
|
||||
|
||||
// calculate the duration if possible
|
||||
var hasEntryDate = getElementValue("todo-has-entrydate", "checked");
|
||||
var hasDueDate = getElementValue("todo-has-duedate", "checked");
|
||||
let hasEntryDate = getElementValue("todo-has-entrydate", "checked");
|
||||
let hasDueDate = getElementValue("todo-has-duedate", "checked");
|
||||
if (hasEntryDate && hasDueDate) {
|
||||
var start = jsDateToDateTime(getElementValue("todo-entrydate"));
|
||||
var end = jsDateToDateTime(getElementValue("todo-duedate"));
|
||||
let start = cal.jsDateToDateTime(getElementValue("todo-entrydate"));
|
||||
let end = cal.jsDateToDateTime(getElementValue("todo-duedate"));
|
||||
gItemDuration = end.subtractDate(start);
|
||||
} else {
|
||||
gItemDuration = null;
|
||||
|
@ -942,7 +942,7 @@ function saveDialog(item) {
|
|||
|
||||
if (item.status == "COMPLETED" && isToDo(item)) {
|
||||
var elementValue = getElementValue("completed-date-picker");
|
||||
item.completedDate = jsDateToDateTime(elementValue);
|
||||
item.completedDate = cal.jsDateToDateTime(elementValue);
|
||||
}
|
||||
|
||||
saveReminder(item);
|
||||
|
@ -1069,8 +1069,8 @@ function updateAccept() {
|
|||
var startDate;
|
||||
var endDate;
|
||||
if (isEvent(window.calendarItem)) {
|
||||
startDate = jsDateToDateTime(getElementValue("event-starttime"));
|
||||
endDate = jsDateToDateTime(getElementValue("event-endtime"));
|
||||
startDate = cal.jsDateToDateTime(getElementValue("event-starttime"));
|
||||
endDate = cal.jsDateToDateTime(getElementValue("event-endtime"));
|
||||
|
||||
var menuItem = document.getElementById('options-timezone-menuitem');
|
||||
if (menuItem.getAttribute('checked') == 'true') {
|
||||
|
@ -1110,9 +1110,9 @@ function updateAccept() {
|
|||
}
|
||||
} else {
|
||||
startDate = getElementValue("todo-has-entrydate", "checked") ?
|
||||
jsDateToDateTime(getElementValue("todo-entrydate")) : null;
|
||||
cal.jsDateToDateTime(getElementValue("todo-entrydate")) : null;
|
||||
endDate = getElementValue("todo-has-duedate", "checked") ?
|
||||
jsDateToDateTime(getElementValue("todo-duedate")) : null;
|
||||
cal.jsDateToDateTime(getElementValue("todo-duedate")) : null;
|
||||
}
|
||||
|
||||
if (endDate && startDate && endDate.compare(startDate) == -1) {
|
||||
|
@ -3142,8 +3142,8 @@ function updateRepeatDetails() {
|
|||
|
||||
let startDate = getElementValue(event ? "event-starttime" : "todo-entrydate");
|
||||
let endDate = getElementValue(event ? "event-endtime" : "todo-duedate");
|
||||
startDate = jsDateToDateTime(startDate, kDefaultTimezone);
|
||||
endDate = jsDateToDateTime(endDate, kDefaultTimezone);
|
||||
startDate = cal.jsDateToDateTime(startDate, kDefaultTimezone);
|
||||
endDate = cal.jsDateToDateTime(endDate, kDefaultTimezone);
|
||||
|
||||
let allDay = getElementValue("event-all-day", "checked");
|
||||
let detailsString = recurrenceRule2String(recurrenceInfo, startDate,
|
||||
|
|
|
@ -113,10 +113,10 @@ function getPrintSettings(receiverFunc) {
|
|||
// We return the time from the timepickers using the selected
|
||||
// timezone, as not doing so in timezones with a positive offset
|
||||
// from UTC may cause the printout to include the wrong days.
|
||||
var currentTimezone = calendarDefaultTimezone();
|
||||
settings.start = jsDateToDateTime(document.getElementById("start-date-picker").value);
|
||||
let currentTimezone = cal.calendarDefaultTimezone();
|
||||
settings.start = cal.jsDateToDateTime(document.getElementById("start-date-picker").value);
|
||||
settings.start = settings.start.getInTimezone(currentTimezone);
|
||||
settings.end = jsDateToDateTime(document.getElementById("end-date-picker").value);
|
||||
settings.end = cal.jsDateToDateTime(document.getElementById("end-date-picker").value);
|
||||
settings.end = settings.end.getInTimezone(currentTimezone);
|
||||
settings.end = settings.end.clone();
|
||||
settings.end.day += 1;
|
||||
|
|
|
@ -388,8 +388,8 @@
|
|||
<property name="firstDate" readonly="true">
|
||||
<getter><![CDATA[
|
||||
let calbox = document.getAnonymousElementByAttribute(this, "anonid", "minimonth-calendar");
|
||||
let date = calbox.childNodes[1].firstChild.date;
|
||||
return jsDateToDateTime(date);
|
||||
let dt = calbox.childNodes[1].firstChild.date;
|
||||
return cal.jsDateToDateTime(dt);
|
||||
]]></getter>
|
||||
</property>
|
||||
|
||||
|
@ -398,7 +398,7 @@
|
|||
<getter><![CDATA[
|
||||
var calbox = document.getAnonymousElementByAttribute(this, "anonid", "minimonth-calendar");
|
||||
var date = calbox.lastChild.lastChild.date;
|
||||
var lastDateTime = jsDateToDateTime(date);
|
||||
var lastDateTime = cal.jsDateToDateTime(date);
|
||||
lastDateTime.day = lastDateTime.day + 1;
|
||||
return lastDateTime;
|
||||
]]></getter>
|
||||
|
|
|
@ -396,6 +396,34 @@ let cal = {
|
|||
return calDateTime.nativeTime;
|
||||
},
|
||||
|
||||
/**
|
||||
* Returns a calIDateTime corresponding to a javascript Date.
|
||||
*
|
||||
* @param aDate a javascript date
|
||||
* @param aTimezone (optional) a timezone that should be enforced
|
||||
* @returns a calIDateTime
|
||||
*
|
||||
* @warning Use of this function is strongly discouraged. calIDateTime should
|
||||
* be used directly whenever possible.
|
||||
* If you pass a timezone, then the passed jsDate's timezone will be ignored,
|
||||
* but only its local time portions are be taken.
|
||||
*/
|
||||
jsDateToDateTime: function jsDateToDateTime(aDate, aTimezone) {
|
||||
let newDate = cal.createDateTime();
|
||||
if (aTimezone) {
|
||||
newDate.resetTo(aDate.getFullYear(),
|
||||
aDate.getMonth(),
|
||||
aDate.getDate(),
|
||||
aDate.getHours(),
|
||||
aDate.getMinutes(),
|
||||
aDate.getSeconds(),
|
||||
aTimezone);
|
||||
} else {
|
||||
newDate.jsDate = aDate;
|
||||
}
|
||||
return newDate;
|
||||
},
|
||||
|
||||
userWeekStart: function userWeekStart(dt) {
|
||||
let wkst = cal.getPrefSafe("calendar.week.start", 0);
|
||||
let wkstDate = dt.clone();
|
||||
|
|
|
@ -10,7 +10,7 @@ Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
|
|||
const kHoursBetweenUpdates = 6;
|
||||
|
||||
function nowUTC() {
|
||||
return jsDateToDateTime(new Date()).getInTimezone(UTC());
|
||||
return cal.jsDateToDateTime(new Date()).getInTimezone(cal.UTC());
|
||||
}
|
||||
|
||||
function newTimerWithCallback(aCallback, aDelay, aRepeating) {
|
||||
|
|
|
@ -13,6 +13,7 @@
|
|||
|
||||
#include "jsapi.h"
|
||||
#include "jsfriendapi.h"
|
||||
#include "jswrapper.h"
|
||||
#include "prprf.h"
|
||||
|
||||
extern "C" {
|
||||
|
@ -629,13 +630,15 @@ calDateTime::SetJsDate(JSContext* aCx, const JS::Value& aDate)
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
JSObject& dobj = aDate.toObject();
|
||||
if (!js_DateIsValid(aCx, &dobj)) {
|
||||
JSObject* dobj = js::UnwrapObjectChecked(aCx, JSVAL_TO_OBJECT(aDate));
|
||||
JSAutoCompartment ac(aCx, dobj);
|
||||
|
||||
if (!JS_ObjectIsDate(aCx, dobj) || !js_DateIsValid(aCx, dobj)) {
|
||||
mIsValid = false;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
PRTime utcTime = PRTime(js_DateGetMsecSinceEpoch(aCx, &dobj)) * 1000;
|
||||
PRTime utcTime = PRTime(js_DateGetMsecSinceEpoch(aCx, dobj)) * 1000;
|
||||
mIsValid = NS_SUCCEEDED(SetNativeTime(utcTime));
|
||||
return NS_OK;
|
||||
}
|
||||
|
|
|
@ -46,7 +46,7 @@ calItemBase.prototype = {
|
|||
this.wrappedJSObject = this;
|
||||
this.mProperties = new calPropertyBag();
|
||||
this.mPropertyParams = {};
|
||||
this.mProperties.setProperty("CREATED", jsDateToDateTime(new Date()));
|
||||
this.mProperties.setProperty("CREATED", cal.jsDateToDateTime(new Date()));
|
||||
},
|
||||
|
||||
/**
|
||||
|
@ -176,7 +176,7 @@ calItemBase.prototype = {
|
|||
*/
|
||||
ensureNotDirty: function cIB_ensureNotDirty() {
|
||||
if (this.mDirty) {
|
||||
let now = jsDateToDateTime(new Date());
|
||||
let now = cal.jsDateToDateTime(new Date());
|
||||
this.setProperty("LAST-MODIFIED", now);
|
||||
this.setProperty("DTSTAMP", now);
|
||||
this.mDirty = false;
|
||||
|
|
|
@ -88,7 +88,7 @@ calTodo.prototype = {
|
|||
set isCompleted(v) {
|
||||
if (v) {
|
||||
if (!this.completedDate)
|
||||
this.completedDate = jsDateToDateTime(new Date());
|
||||
this.completedDate = cal.jsDateToDateTime(new Date());
|
||||
this.status = "COMPLETED";
|
||||
this.percentComplete = 100;
|
||||
} else {
|
||||
|
|
|
@ -375,34 +375,6 @@ function now() {
|
|||
return d.getInTimezone(calendarDefaultTimezone());
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a calIDateTime corresponding to a javascript Date.
|
||||
*
|
||||
* @param aDate a javascript date
|
||||
* @param aTimezone (optional) a timezone that should be enforced
|
||||
* @returns a calIDateTime
|
||||
*
|
||||
* @warning Use of this function is strongly discouraged. calIDateTime should
|
||||
* be used directly whenever possible.
|
||||
* If you pass a timezone, then the passed jsDate's timezone will be ignored,
|
||||
* but only its local time portions are be taken.
|
||||
*/
|
||||
function jsDateToDateTime(aDate, aTimezone) {
|
||||
var newDate = createDateTime();
|
||||
if (aTimezone) {
|
||||
newDate.resetTo(aDate.getFullYear(),
|
||||
aDate.getMonth(),
|
||||
aDate.getDate(),
|
||||
aDate.getHours(),
|
||||
aDate.getMinutes(),
|
||||
aDate.getSeconds(),
|
||||
aTimezone);
|
||||
} else {
|
||||
newDate.jsDate = aDate;
|
||||
}
|
||||
return newDate;
|
||||
}
|
||||
|
||||
/**
|
||||
* Selects an item with id aItemId in the radio group with id aRadioGroupId
|
||||
*
|
||||
|
|
|
@ -351,7 +351,7 @@ calGoogleRequest.prototype = {
|
|||
getCorrectedDate.mClockSkew = curDate.getTime() - serverDate.getTime();
|
||||
|
||||
// Remember when this request happened
|
||||
this.requestDate = jsDateToDateTime(serverDate);
|
||||
this.requestDate = cal.jsDateToDateTime(serverDate);
|
||||
|
||||
// Handle all (documented) error codes
|
||||
switch (httpChannel.responseStatus) {
|
||||
|
|
|
@ -48,7 +48,7 @@ function handleCommandLine(aComLine) {
|
|||
|
||||
switch (flag) {
|
||||
case "showdate":
|
||||
currentView().goToDay(jsDateToDateTime(new Date(param)));
|
||||
currentView().goToDay(cal.jsDateToDateTime(new Date(param)));
|
||||
break;
|
||||
case "subscribe":
|
||||
case "url":
|
||||
|
@ -184,7 +184,7 @@ function changeNumberOfWeeks(menuitem) {
|
|||
function pickAndGoToDate() {
|
||||
var initialDate = currentView().selectedDay.getInTimezone(floating()).jsDate;
|
||||
var callback = function receiveAndGoToDate(pickedDate) {
|
||||
currentView().goToDay(jsDateToDateTime(pickedDate));
|
||||
currentView().goToDay(cal.jsDateToDateTime(pickedDate));
|
||||
getMinimonth().value = pickedDate;
|
||||
};
|
||||
openDialog("chrome://sunbird/content/calendar-gotodate-dialog.xul",
|
||||
|
|
|
@ -83,4 +83,10 @@ function run_test() {
|
|||
do_check_eq(utc.timezone.tzid, "UTC");
|
||||
do_check_eq(utc.clone().timezone.tzid, "UTC");
|
||||
do_check_eq(utc.timezoneOffset, 0);
|
||||
|
||||
// Bug 794477 - setting jsdate across compartments needs to work
|
||||
let someDate = new Date();
|
||||
let createdDate = cal.jsDateToDateTime(someDate).getInTimezone(cal.calendarDefaultTimezone());
|
||||
do_check_eq(Math.floor(someDate.getTime() / 1000),
|
||||
Math.floor(createdDate.jsDate.getTime() / 1000));
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче