Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handling timezones regardless of server TZ setting. #24

Open
wants to merge 57 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
57 commits
Select commit Hold shift + click to select a range
0b62d04
Use node-time to set timezone at parse-time rather than setting .tz o…
Aug 7, 2013
eaee1b5
Try using the setTimezone with true param.
Aug 7, 2013
2a4ce32
I simply cannot get this to work properly. Trying to print out what …
Aug 7, 2013
3feaff6
Trying to understand this date parsing.
Aug 7, 2013
6f1dc5e
Maybe I was just not setting tz in the right spot.
Aug 7, 2013
5687776
Consolidate setTimezone call into addTZ method.
Aug 7, 2013
b113dd6
Forgot true
Aug 7, 2013
fb61a8b
Use node-time as a drop-in replacement for Date and use the setTimezo…
Aug 7, 2013
3648492
Use node-time as a drop-in replacement for Date and use the setTimezo…
Aug 7, 2013
16f8c49
If there is no time on the date, then I'm going to set a bAllDay bool…
Aug 8, 2013
23b1cbc
Adding some logging.
Aug 12, 2013
c5b0cb6
Adding some logging.
Aug 12, 2013
2663f76
Ignore webstore stuff.
Aug 12, 2013
4994946
Adding more logging.
Aug 12, 2013
b305520
Only call addTZ when the datetime value doesn't have a Z.
Aug 12, 2013
cb95cce
That should do it.
Aug 12, 2013
f4004fb
That should do it.
Aug 12, 2013
90cbadf
Don't alter the timestamp if the date/time string is already in zulu …
Aug 12, 2013
3e5902f
Something is dying along the way... Added skip param to tell node-tim…
Aug 12, 2013
dc427cc
Putting rrule inside handler because using a singleton means that eve…
Aug 28, 2013
bfad0e3
That didn't work. I am going to try and tell it to not cache.
Aug 28, 2013
be18d97
Passing empty hash in first param.
Aug 28, 2013
2a77fe4
Trying creating instance variable with caching off.
Aug 28, 2013
bbdac89
Try creating instance var.
Aug 28, 2013
582a2de
set _cache = false.
Aug 28, 2013
3764211
set _cache = false after instantiating it properly.
Aug 28, 2013
2fab6c9
Leave caching on but empty _cache.all on each pass.
Aug 28, 2013
286c889
Leave caching on but empty _cache.all on each pass.
Aug 28, 2013
053e774
Removing log line.
Aug 28, 2013
f9dc8bb
I forked rrule in order to allow noCache param to be passed in with t…
Aug 28, 2013
54c560c
That didn't work, so just going to pull in what RRule is doing and br…
Aug 28, 2013
8a6adea
Reverting package.json
Aug 28, 2013
d25a26e
Idiotic syntax errors.
Aug 28, 2013
b030aa9
Idiotic syntax errors.
Aug 28, 2013
a7526a1
I simply don't know what's going on here.
Aug 28, 2013
7548aaa
I'm going to stick the all() output to the rrule property on ical's o…
Aug 28, 2013
c535af4
That didn't work. Creating an instance per uid is my next thing.
Aug 28, 2013
d2fd912
That didn't work. Creating an instance per uid is my next thing.
Aug 28, 2013
d201cdc
Trying to create a unique RRule instance for each event in the data s…
Aug 28, 2013
811b7f2
Moving to moment-timezone.
Jun 24, 2014
2b3706a
Moving to moment-timezone.
Jun 24, 2014
c43e972
Moving to moment-timezone.
Jun 24, 2014
b44aa19
Don't convert to utc. Just parse using moment and see how it comes out.
Jun 24, 2014
8b252a8
Don't convert to utc. Just parse using moment and see how it comes out.
Jun 24, 2014
41c90f2
Handling non-ISO formatted dates.
Jun 24, 2014
2b4499a
Handling non-ISO formatted dates.
Jun 24, 2014
afc6944
Handling non-ISO formatted dates.
Jun 24, 2014
c1561b1
Handling non-ISO formatted dates.
Jun 24, 2014
6100b27
Handling non-ISO formatted dates.
Jun 24, 2014
99dc9f5
Handling non-ISO formatted dates.
Jun 24, 2014
65e9b67
Handling non-ISO formatted dates.
Jun 24, 2014
bd6b5d9
Handling non-ISO formatted dates.
Jun 24, 2014
11473d8
Handling non-ISO formatted dates.
Jun 24, 2014
b5d78f6
Just using a moment object instead of js Date.
Jun 24, 2014
a7aa567
Using js Date. Grr.
Jun 24, 2014
6c75229
Using js Date. Grr.
Jun 24, 2014
ec84701
Using js Date. Grr.
Jun 24, 2014
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,19 @@
node_modules

.idea/workspace.xml

.idea/vcs.xml

.idea/scopes/scope_settings.xml

.idea/modules.xml

.idea/misc.xml

.idea/jsLibraryMappings.xml

.idea/ical.js.iml

.idea/encodings.xml

.idea/.name
69 changes: 12 additions & 57 deletions ical.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*
* <[email protected]>
* **************/

var moment = require('moment-timezone');

// Unescape Text re RFC 4.3.11
var text = function(t){
Expand Down Expand Up @@ -42,66 +42,23 @@ var storeParam = function(name){
}
}

var addTZ = function(dt, name, params){
var p = parseParams(params);

if (params && p){
dt[name].tz = p.TZID
}

return dt
}


var dateParam = function(name){
return function(val, params, curr){

// Store as string - worst case scenario
storeParam(name)(val, undefined, curr)

if (params && params[0] === "VALUE=DATE") {
// Just Date
return function(val, params, curr) {
// Store as string - worst case scenario
storeParam(name)(val, undefined, curr)

var comps = /^(\d{4})(\d{2})(\d{2})$/.exec(val);
if (comps !== null) {
// No TZ info - assume same timezone as this computer
curr[name] = new Date(
comps[1],
parseInt(comps[2], 10)-1,
comps[3]
);

return addTZ(curr, name, params);
}
}


//typical RFC date-time format
var comps = /^(\d{4})(\d{2})(\d{2})T(\d{2})(\d{2})(\d{2})(Z)?$/.exec(val);
if (comps !== null) {
if (comps[7] == 'Z'){ // GMT
curr[name] = new Date(Date.UTC(
parseInt(comps[1], 10),
parseInt(comps[2], 10)-1,
parseInt(comps[3], 10),
parseInt(comps[4], 10),
parseInt(comps[5], 10),
parseInt(comps[6], 10 )
));
// TODO add tz
} else {
curr[name] = new Date(
parseInt(comps[1], 10),
parseInt(comps[2], 10)-1,
parseInt(comps[3], 10),
parseInt(comps[4], 10),
parseInt(comps[5], 10),
parseInt(comps[6], 10)
);
if (comps) {
curr[name] = moment(val,'YYYYMMDD');
curr[name].bAllDay = true;
} else if (val) {
curr[name] = moment(val,'YYYYMMDDTHHmmss');
}
}
if (curr[name])
curr[name] = curr[name].toDate();

return addTZ(curr, name, params)
return curr[name];
}
}

Expand All @@ -115,8 +72,6 @@ var geoParam = function(name){
}
}



exports.objectHandlers = {
'BEGIN' : function(component, params, curr){
if (component === 'VCALENDAR')
Expand Down
14 changes: 12 additions & 2 deletions node-ical.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,19 @@ exports.parseFile = function(filename){
}


var rrule = require('rrule').RRule
var RRule = require('rrule').RRule;
var hInstances = {};

ical.objectHandlers['RRULE'] = function(val, params, curr, par, line){
curr['rrule'] = rrule.fromString(line.replace("RRULE:", ""));
if (par) {
var id;
for (var sID in par) {
id = sID;
}
if (id) {
hInstances[id] = new RRule(RRule.parseString(line.replace("RRULE:", "")));
curr['rrule'] = hInstances[id].all();
}
}
return curr
}
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
"url": "git://github.com/peterbraden/ical.js.git"
},
"dependencies": {
"request": "",
"request": "*",
"moment-timezone":"*",
"rrule": "2.0.0"
},
"devDependencies": {
Expand Down