fixing event dialog to use use timezone-corrected times when displaying start/end times. adding some code to try to guess what your system timezone is

This commit is contained in:
pavlov%pavlov.net 2005-04-22 22:57:08 +00:00
Родитель 25677ada84
Коммит cfffe0617c
3 изменённых файлов: 49 добавлений и 15 удалений

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

@ -36,12 +36,10 @@
* ***** END LICENSE BLOCK ***** */
/* this needs to be a pref/system thing/something.. wtf! */
var TIMEZONE = "/mozilla.org/20050126_1/America/Los_Angeles"
/* all params are optional */
function createEventWithDialog(calendar, startDate, endDate, summary)
{
const kDefaultTimezone = calendarDefaultTimezone();
var event = createEvent();
if (!startDate) {
@ -49,9 +47,13 @@ function createEventWithDialog(calendar, startDate, endDate, summary)
startDate.second = 0;
startDate.normalize();
} else if (startDate.isDate) {
startDate = startDate.clone();
startDate.isDate = false;
event.startDate.isDate = false;
/* set the hour/minute of startDate to "right now"
if the day is the same */
var now = jsDateToDateTime(new Date()).getInTimezone(TIMEZONE).clone();
var now = jsDateToDateTime(new Date()).getInTimezone(kDefaultTimezone).clone();
var nowDate = now.clone();
nowDate.isDate = true;
nowDate.normalize();
@ -61,12 +63,12 @@ function createEventWithDialog(calendar, startDate, endDate, summary)
normalize and change startDate to be now. */
now.second = 0;
now.normalize();
startDate = now;
}
}
event.startDate = startDate.clone();
event.startDate.isDate = false;
if (!endDate) {
endDate = startDate.clone();

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

@ -1,3 +1,4 @@
/* -*- Mode: javascript; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
@ -133,10 +134,35 @@ function calendarDefaultTimezone() {
try {
gDefaultTimezone = prefobj.getCharPref("timezone.local");
} catch (e) {
gDefaultTimezone = null;
gDefaultTimezone = guessSystemTimezone();
dump("gDefaultTimezone: " + gDefaultTimezone);
}
}
return gDefaultTimezone;
}
// XXX this should probably live somewhere else
// XXX this table needs a _lot_ more stuff in it.
const tzTable = {
"GMT-0700 Pacific Daylight Time" : "/mozilla.org/20050126_1/America/Los_Angeles",
"GMT-0800 Pacific Standard Time" : "/mozilla.org/20050126_1/America/Los_Angeles"
};
// returns a ICS timezone string
function guessSystemTimezone()
{
var m = (new Date()).toString().match(/[^(]* ([^ ]*) \(([^)]+)\)/);
var offset = m[1];
var timezone = m[2];
dump("Guessing system timezone:\n");
dump("offset : " + offset + "\ntimezone: " + timezone + "\n");
try {
return tzTable[offset + " " + timezone];
} catch(ex) {
return null;
}
}

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

@ -96,6 +96,8 @@ const DEFAULT_ALARM_LENGTH = 15; //default number of time units, an alarm goes o
*/
function loadCalendarEventDialog()
{
const kDefaultTimezone = calendarDefaultTimezone();
// Get arguments, see description at top of file
var args = window.arguments[0];
@ -120,12 +122,16 @@ function loadCalendarEventDialog()
// fill in fields from the event
switch(componentType) {
case "event":
var startDate = event.startDate.jsDate;
var startDate = event.startDate.getInTimezone(kDefaultTimezone).jsDate;
setElementValue("start-datetime", startDate);
dump(startDate + "\n");
// only events have end dates. todos have due dates
var endDate = event.endDate.jsDate;
var endDate = event.endDate.getInTimezone(kDefaultTimezone).jsDate;
var displayEndDate = new Date(endDate);
dump(displayEndDate + "\n");
/*
if (event.isAllDay) {
//displayEndDate == icalEndDate - 1, in the case of allday events
@ -424,13 +430,13 @@ function loadCalendarEventDialog()
var calendarField = document.getElementById('server-field');
var calendars = getCalendarManager().getCalendars({});
for (i in calendars) {
var menuitem = calendarField.appendItem(calendars[i].name,
calendars[i].uri);
menuitem.calendar = calendars[i];
// compare cal.uri because there may be multiple instances of
// calICalendar or uri for the same spec, and those instances are
// not ==.
try {
var menuitem = calendarField.appendItem(calendars[i].name,
calendars[i].uri);
menuitem.calendar = calendars[i];
// compare cal.uri because there may be multiple instances of
// calICalendar or uri for the same spec, and those instances are
// not ==.
if (eventCalendar && eventCalendar.uri.equals(calendars[i].uri))
calendarField.selectedIndex = i;
} catch(ex) {