summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorniko <niko>2012-11-02 00:11:25 (GMT)
committerniko <niko>2012-11-02 00:11:25 (GMT)
commit0b7dceed02fcb12fa7c19a0ac7976b528e76ff93 (patch)
treebd275bbd4f123296da417565b3a4566fdbaf33a1
parentcb3aa2a9e753ae8f500ad0fa162002a0cf654403 (diff)
downloadsynckolab-0b7dceed02fcb12fa7c19a0ac7976b528e76ff93.tar.gz
fixed all day handling #25201
-rw-r--r--src/chrome/content/synckolab/calendarTools.js17
-rw-r--r--src/chrome/content/synckolab/tools/text.js41
-rw-r--r--test/synckolab/tools/textTest.js16
3 files changed, 64 insertions, 10 deletions
diff --git a/src/chrome/content/synckolab/calendarTools.js b/src/chrome/content/synckolab/calendarTools.js
index c18746c..51fd542 100644
--- a/src/chrome/content/synckolab/calendarTools.js
+++ b/src/chrome/content/synckolab/calendarTools.js
@@ -820,7 +820,13 @@ synckolab.calendarTools.json2event = function (jobj, calendar) {
if (jobj.startDate.dateTime.indexOf(":") === -1) {
// entry date and start date can be handled the same way
synckolab.tools.logMessage("setting all day: " + (syncTasks?"entryDate":"startDate"), synckolab.global.LOG_CAL + synckolab.global.LOG_DEBUG);
- this.setKolabItemProperty(event, syncTasks?"entryDate":"startDate", synckolab.tools.text.string2CalDateTime(jobj.startDate));
+ cDate = synckolab.tools.text.string2CalDateTime(jobj.startDate);
+ // this is a date
+ var tmp_date = cDate.jsDate;
+ tmp_date.setTime(tmp_date.getTime() + 12*60*60000);
+ cDate.jsDate = tmp_date;
+ cDate.isDate = true;
+ this.setKolabItemProperty(event, syncTasks?"entryDate":"startDate", cDate);
} else {
// entry date and start date can be handled the same way
synckolab.tools.logMessage("setting: " + (syncTasks?"entryDate":"startDate"), synckolab.global.LOG_CAL + synckolab.global.LOG_DEBUG);
@@ -835,7 +841,8 @@ synckolab.calendarTools.json2event = function (jobj, calendar) {
jobj.endDate.dateTime = jobj.endDate;
}
- if (jobj.endDate.dateTime.indexOf(":") === -1) {
+ if (jobj.endDate.dateTime.indexOf("T") === -1) {
+ synckolab.tools.logMessage("setting endate all day!" , synckolab.global.LOG_CAL + synckolab.global.LOG_DEBUG);
cDate = synckolab.tools.text.string2CalDateTime(jobj.endDate);
// Kolab uses for 1-day-event:
// startdate = day_x, enddate = day_x
@@ -1192,7 +1199,7 @@ synckolab.calendarTools.xml2json = function (xml, syncTasks)
if (!cur.firstChild) {
break;
}
- s = cur.getXmlResult("date-time", "");
+ s = synckolab.tools.text.getLongDateTime(cur.getXmlResult("date-time", ""));
jobj.startDate = {
tz: cur.getXmlResult(["parameters","tzid","text"], null),
allday: s.indexOf("T") === -1,
@@ -1220,7 +1227,7 @@ synckolab.calendarTools.xml2json = function (xml, syncTasks)
if (!cur.firstChild) {
break;
}
- s = cur.getXmlResult("date-time", "");
+ s = synckolab.tools.text.getLongDateTime(cur.getXmlResult("date-time", ""));
jobj.endDate = {
tz: cur.getXmlResult(["parameters","tzid","text"], null),
allday: s.indexOf("T") === -1,
@@ -1592,7 +1599,7 @@ synckolab.calendarTools.xml2json = function (xml, syncTasks)
}
// add exclusion
- jobj.recurrence.exclusion.push(cur.getXmlResult("date", null));
+ jobj.recurrence.exclusion.push(synckolab.tools.text.getLongDateTime(cur.getXmlResult("date", null)));
break;
case "ATTENDEE":
diff --git a/src/chrome/content/synckolab/tools/text.js b/src/chrome/content/synckolab/tools/text.js
index 47e371a..bdf99d5 100644
--- a/src/chrome/content/synckolab/tools/text.js
+++ b/src/chrome/content/synckolab/tools/text.js
@@ -317,6 +317,45 @@ synckolab.tools.text = {
}
},
+ /**
+ * Helper function that converts a compact Date or DateTime to a long version
+ */
+ getLongDateTime: function(val) {
+ if(!val) {
+ return val;
+ }
+ // already a long format
+ if(val.indexOf('-') !== -1) {
+ return val;
+ }
+ var s = val;
+ s = s.replace('T', ' ');
+ var both = s.split(' ');
+ var cdate = both[0];
+ // kolab3: YYYYMMDD
+ cdate = [];
+ cdate[0] = both[0].substr(0,4);
+ if(both[0].length > 7) {
+ cdate[1] = both[0].substr(4,2);
+ cdate[2] = both[0].substr(6,2);
+ } else {
+ cdate[1] = 1;
+ cdate[2] = 1;
+ }
+
+
+ s = cdate[0] + "-" + cdate[1] + "-" + cdate[2];
+
+ if(val.indexOf('T') !== -1) {
+ var ctime = [];
+ // kolab3: HHmmSS
+ ctime[0] = both[1].substr(0,2);
+ ctime[1] = both[1].substr(2,2);
+ s += "T" + ctime[0] + ":" + ctime[1] + ":" + both[1].substring(4);
+ }
+ return s;
+ },
+
// takes: 2005-03-30T15:28:52Z or 2005-03-30 15:28:52
string2CalDateTime : function (val, useUTC) {
// in case its a date without time fall back to string2CalDate()
@@ -424,7 +463,7 @@ synckolab.tools.text = {
// make sure not to use UTC for all-day events
var resultstring = this.date2String(val, true, compact);
- if (!allday) {
+ if (!onlyDate) {
resultstring += 'T';
resultstring += this.time2String(val, compact);
resultstring += 'Z';
diff --git a/test/synckolab/tools/textTest.js b/test/synckolab/tools/textTest.js
index 23c6034..a7b7547 100644
--- a/test/synckolab/tools/textTest.js
+++ b/test/synckolab/tools/textTest.js
@@ -40,8 +40,8 @@ test("synckolab.tools.text.utf8.decode", function() {
test("synckolab.tools.text.string2DateTime", function() {
// 2005-03-30T15:28:52Z or 2005-03-30 15:28:52 or: 20050303T152852Z
- equal(synckolab.tools.text.string2DateTime("2005-03-30T15:28:52Z", true).getTime(), 1112196532000, "datetime with - and T/Z (kolab2)");
- equal(synckolab.tools.text.string2DateTime("20050330T152852Z", true).getTime(), 1112196532000, "datetime with T/Z (kolab3)");
+ equal(synckolab.tools.text.string2DateTime("2005-03-30T15:28:52Z", false, true).getTime(), 1112189332000, "datetime with - and T/Z (kolab2)");
+ equal(synckolab.tools.text.string2DateTime("20050330T152852Z", false, true).getTime(), 1112189332000, "datetime with T/Z (kolab3)");
equal(synckolab.tools.text.string2DateTime("2005-03-30T").getTime(), 1112133600000, "date with - (kolab2)");
equal(synckolab.tools.text.string2DateTime("20050330T").getTime(), 1112133600000, "date (kolab3)");
@@ -56,7 +56,15 @@ test("synckolab.tools.text.string2DateTime", function() {
test("synckolab.tools.text.calDateTime2String", function() {
// 2005-03-30T15:28:52Z or 2005-03-30 15:28:52 or: 20050303T152852Z
var cdate = new Date(1112196532000);
- equal(synckolab.tools.text.calDateTime2String(cdate, false), "2005-03-30T15:28:52Z", "datetime with - and T/Z (kolab2)");
- equal(synckolab.tools.text.calDateTime2String(cdate, true), "20050330T152852Z", "datetime with T/Z (kolab3)");
+ equal(synckolab.tools.text.calDateTime2String(cdate, false, false), "2005-03-30T15:28:52Z", "datetime with - and T/Z (kolab2)");
+ equal(synckolab.tools.text.calDateTime2String(cdate, false, true), "20050330T152852Z", "datetime with T/Z (kolab3)");
+ equal(synckolab.tools.text.calDateTime2String(cdate, true, false), "2005-03-30", "date with - and T/Z (kolab2)");
+ equal(synckolab.tools.text.calDateTime2String(cdate, true, true), "20050330", "date with T/Z (kolab3)");
});
+test("synckolab.tools.text.getLongDateTime", function(){
+ equal(synckolab.tools.text.getLongDateTime("20050330T152852Z"), "2005-03-30T15:28:52Z", "normalize datetime");
+ equal(synckolab.tools.text.getLongDateTime("20050330"), "2005-03-30", "normalize date");
+ equal(synckolab.tools.text.getLongDateTime("2005-03-30"), "2005-03-30", "normalize date");
+ equal(synckolab.tools.text.getLongDateTime("20050330T152852ZEurope/Vienna"), "2005-03-30T15:28:52ZEurope/Vienna", "normalize datetime");
+}); \ No newline at end of file