Introduction Using the js Date() object in a json event source offers substantial performance improvements over XML event source or json using iso8601 strings for the dates. {'start': new Date(1216,2,15),
'end': new Date(1216,2,18)
}Notes - Using Date() objects obviates the need for an explicit 'dateTimeFormat': 'iso8601', declaration at the top of the file.
- The JSON standard does not allow object declarations. So your event data set will no longer be valid JSON. But it will work fine with Timeline.
- The Date object will use the timezone of the browser. To use a specific GMT time, use new Date(Date.UTC(2008,0,17,20,00,00,0))
- the js Date() object takes seven arguments, first three are required:
- Date(year, month, day, hours, minutes, seconds, milliseconds)
- Date and Date.UTC use zero-indexed months: 0 => Jan, 1 => Feb, ..., 11 => Dec
|
To me it only worked without the 'dateTimeFormat': 'iso8601' declaration!
I've added a new dateTimeFormat called 'javascriptnative' so I can send Date() objects in valid JSON.
I create new parser in timeline_ajax/scripts/date-time.js;
SimileAjax.DateTime.parseNativeDate = function (string) { try { var date = eval('new ' + string); // string should be 'Date(yy,mm,dd)' or another valid Date constructor if (date == undefined) return null; return date; } catch (e) { return null; } };Then in timeline_ajax/scripts/units.js define the parser function which just calls eval('new ' + string) to construct a new Date object;
SimileAjax.NativeDateUnit.getParser = function(format) { if (typeof format == "string") { format = format.toLowerCase(); } if (format == "javascriptnative") { return SimileAjax.DateTime.parseNativeDate; } return (format == "iso8601" || format == "iso 8601") ? SimileAjax.DateTime.parseIso8601DateTime : SimileAjax.DateTime.parseGregorianDateTime; };I'm writing a django app and using django.utils.simplejson encoder like this in my view;
from django.utils.simplejson import JSONEncoder def list_items(request): e_dict = {} e_dict['dateTimeFormat'] = 'javascriptnative' e_list = list() e_dict['events'] = events e1 = {} e1['start'] = 'Date(%s)' % datetime.now().strftime('%Y,%m-1,%d,%H,%M,%S') e1['title'] = 'Hey now!' e_list.append(e1) return HttpResponse(JSONEncoder().encode(e_dict), mimetype='application/javascript')Note that the javascript Date() constructor expects the month to be zero-indexed, so I subtract 1 from the python datetime '%m' argument.
Regardless of how you enter the dates, the display in the popups will always be converted to display in GMT.
not work for me, using 'dateTimeFormat': 'iso8601' -> 'start': new Date(1216,2,15) error => v1 is null, n1=v1.getTime();
The timeline doesn't work on my website using precise dates strings or Date() objects. Only years are accepted, probably because i'm using MooTools?. Timeline is using jQuery, then I won't use it anymore... too bad, I loved it !