From 782d9ca1becba89759b51b055621b0a57a875343 Mon Sep 17 00:00:00 2001 From: Vijay Date: Wed, 21 Aug 2013 09:14:45 +0100 Subject: [PATCH 1/4] Added fix to date parsing issue in IE setUTCFullYear() and setUTCHours() is needed for IE<9 versions in order to assign new Date. --- oocharts.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/oocharts.js b/oocharts.js index 045278a..65ebb1e 100644 --- a/oocharts.js +++ b/oocharts.js @@ -251,7 +251,11 @@ var oo = (function(document){ * @returns {Date} parsed Date */ var _parseDate = function(val){ - return new Date(val.substring(0, 4), parseInt(val.substring(5, 7)) - 1, val.substring(8, 10)); + val = val.split('-'); + var newDate = new Date(); + newDate.setUTCFullYear(val[0], val[1]-1, val[2]); + newDate.setUTCHours(0,0,0,0); + return newDate; }; /*------------------------------------------------------------ From d7eec801c4565c4c7ef7be99378a5548ea313d04 Mon Sep 17 00:00:00 2001 From: Vijay Date: Wed, 21 Aug 2013 09:37:58 +0100 Subject: [PATCH 2/4] Full compressed with http://www.jsmini.com/ --- oocharts.min.js | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/oocharts.min.js b/oocharts.min.js index 772f3be..41d7ba8 100644 --- a/oocharts.min.js +++ b/oocharts.min.js @@ -1 +1,13 @@ -var oo=function(a){var b="https://api.oocharts.com/v1/dynamic.jsonp",c=void 0,d={},e={},f={},g={},h=function(){for(var b=function(b){for(var c=[],d=a.getElementsByTagName("*"),e=0;e0&&google.load("visualization","1",{packages:b,callback:a})}},e=a;b(function(){d(function(){e&&e(),h()})})},k=function(a){c=a},l=function(a){d=a},m=function(a){e=a},n=function(a){f=a},o=function(a){var b=a.getFullYear().toString(),c=(a.getMonth()+1).toString(),a=a.getDate().toString();return 1===c.length&&(c="0"+c),1===a.length&&(a="0"+a),b+"-"+c+"-"+a},p=function(a){return new Date(a.substring(0,4),parseInt(a.substring(5,7))-1,a.substring(8,10))},q=function(a,b,c){if(this.metrics=[],this.dimensions=[],!a)throw new Error("Profile argument required");this.profile=a,b=b||new Date,c=c||new Date,b instanceof Date&&(b=o(b)),c instanceof Date&&(c=o(c));var d=function(a){return/^[0-9]+(m|d|w|y)$/.test(a)},e=function(a){return/^([0-9]{4}-[0-9]{2}-[0-9]{2})$|^[0-9]+(m|d|w|y)$/.test(a)};if(!d(b)&&!e(b))throw new Error("startDate parameter invalid");if(!d(c)&&!e(c))throw new Error("endDate parameter invalid");if(d(b)&&d(c))throw new Error("startDate and endDate cannot both be relative dates");this.startDate=b,this.endDate=c};q.prototype.clearMetrics=function(){this.metrics=[]},q.prototype.clearDimensions=function(){this.dimensions=[]},q.prototype.addMetric=function(a){this.metrics.push(a)},q.prototype.addDimension=function(a){this.dimensions.push(a)},q.prototype.setFilter=function(a){this.filters=a},q.prototype.setSort=function(a){this.sort=a},q.prototype.setSegment=function(a){this.segment=a},q.prototype.setIndex=function(a){this.index=a},q.prototype.setMaxResults=function(a){this.maxResults=a},q.prototype.execute=function(a){var d={};if(d.key=c,d.profile=this.profile,0===this.metrics.length)throw new Error("At least one metric is required");d.metrics=this.metrics.toString(),d.start=this.startDate,d.end=this.endDate,this.dimensions.length>0&&(d.dimensions=this.dimensions.toString()),this.filters&&(d.filters=this.filters),this.sort&&(d.sort=this.sort),this.index&&(d.index=this.index),this.segment&&(d.segment=this.segment),this.maxResults&&(d.maxResults=this.maxResults),JSONP.get(b,d,function(b){0===b.rows.length&&(b.rows=[[]]),a(b)})};var r=function(a,b,c){this.query=new q(a,b,c)};r.prototype.setMetric=function(a){this.query.clearMetrics(),this.query.addMetric(a)},r.prototype.draw=function(b,c){this.query.execute(function(d){var e;e="string"==typeof b?a.getElementById(b):b,e.innerHTML="undefined"!=typeof d.rows[0][0]?d.rows[0][0].toString():"0","undefined"!=typeof c&&c()})};var s=function(a,b,c){this.query=new q(a,b,c),this.query.addDimension("ga:date"),this.labels=[],this.options=d};s.prototype.setOptions=function(a){this.options=a},s.prototype.addMetric=function(a,b){this.labels.push(b),this.query.addMetric(a)},s.prototype.draw=function(b,c){var d=this;this.query.execute(function(e){for(var f=e.rows,g=0;g Date: Thu, 22 Aug 2013 08:51:49 +0100 Subject: [PATCH 3/4] Replaced with timezone specific date and time parsing function --- oocharts.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/oocharts.js b/oocharts.js index 65ebb1e..d8b30bc 100644 --- a/oocharts.js +++ b/oocharts.js @@ -253,8 +253,8 @@ var oo = (function(document){ var _parseDate = function(val){ val = val.split('-'); var newDate = new Date(); - newDate.setUTCFullYear(val[0], val[1]-1, val[2]); - newDate.setUTCHours(0,0,0,0); + newDate.setFullYear(val[0], val[1]-1, val[2]); + newDate.setHours(0,0,0,0); return newDate; }; From fd68a8feb22625d4493c83b466dcaea88e7c8d50 Mon Sep 17 00:00:00 2001 From: Vijay Date: Thu, 22 Aug 2013 08:53:45 +0100 Subject: [PATCH 4/4] Replaced with timezone specific date and time parsing function --- oocharts.min.js | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/oocharts.min.js b/oocharts.min.js index 41d7ba8..611fb4a 100644 --- a/oocharts.min.js +++ b/oocharts.min.js @@ -1,13 +1,12 @@ (function(m){function q(a,b,c){this.a=new h(a,b,c);this.e=[];this.k=[];this.options=w}function p(a,b,c){this.a=new h(a,b,c);this.options=x}function l(a,b,c){this.a=new h(a,b,c);this.e=[];this.options=z}function n(a,b,c){this.a=new h(a,b,c);this.a.h("ga:date");this.labels=[];this.options=y}function r(a,b,c){this.a=new h(a,b,c)}function h(a,b,c){function g(a){return/^([0-9]{4}-[0-9]{2}-[0-9]{2})$|^[0-9]+(m|d|w|y)$/.test(a)}function d(a){return/^[0-9]+(m|d|w|y)$/.test(a)}this.i=[];this.f=[];if(!a)throw Error("Profile argument required"); -this.profile=a;b=b||new Date;c=c||new Date;b instanceof Date&&(b=u(b));c instanceof Date&&(c=u(c));if(!d(b)&&!g(b))throw Error("startDate parameter invalid");if(!d(c)&&!g(c))throw Error("endDate parameter invalid");if(d(b)&&d(c))throw Error("startDate and endDate cannot both be relative dates");this.B=b;this.v=c}function s(a){a=a.split("-");var b=new Date;b.setUTCFullYear(a[0],a[1]-1,a[2]);b.setUTCHours(0,0,0,0);return b}function u(a){var b=a.getFullYear().toString(),c=(a.getMonth()+1).toString(); -a=a.getDate().toString();1===c.length&&(c="0"+c);1===a.length&&(a="0"+a);return b+"-"+c+"-"+a}function v(a){var b=m.createElement("script");b.type="text/javascript";b.src="https://www.google.com/jsapi";b.async=!1;b.onreadystatechange=b.onload=function(){var c=b.readyState;a.u||c&&!/loaded|complete/.test(c)||(a.u=!0,a())};var c=m.getElementsByTagName("script")[0];c.parentNode.insertBefore(b,c)}var t=void 0,y={},x={},w={},z={};h.prototype.q=function(){this.i=[]};h.prototype.p=function(){this.f=[]}; -h.prototype.c=function(a){this.i.push(a)};h.prototype.h=function(a){this.f.push(a)};h.prototype.execute=function(a){var b={};b.key=t;b.profile=this.profile;if(0===this.i.length)throw Error("At least one metric is required");b.i=this.i.toString();b.start=this.B;b.end=this.v;0