From 4f6000b9b52fd178b41436ba5f7e88250198119f Mon Sep 17 00:00:00 2001 From: bartaakos Date: Sat, 1 Feb 2014 23:51:15 +0100 Subject: [PATCH 1/6] ignore phpstorm project files --- .gitignore | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.gitignore b/.gitignore index 1566a90..08d2468 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,5 @@ +.idea + lib-cov *.seed *.log From 7ab49df86576d1671bada572996c3d4bbbd53cc6 Mon Sep 17 00:00:00 2001 From: bartaakos Date: Sat, 1 Feb 2014 23:53:47 +0100 Subject: [PATCH 2/6] added support for Y-m-d (dashed) date format --- dist/jquery.countdown.js | 2 +- dist/jquery.countdown.min.js | 2 +- src/countdown.js | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/dist/jquery.countdown.js b/dist/jquery.countdown.js index 64c6591..853ba5a 100644 --- a/dist/jquery.countdown.js +++ b/dist/jquery.countdown.js @@ -31,7 +31,7 @@ var instances = [], matchers = []; matchers.push(/^[0-9]*$/.source); matchers.push(/([0-9]{1,2}\/){2}[0-9]{4}( [0-9]{1,2}(:[0-9]{2}){2})?/.source); - matchers.push(/[0-9]{4}(\/[0-9]{1,2}){2}( [0-9]{1,2}(:[0-9]{2}){2})?/.source); + matchers.push(/[0-9]{4}([\/\-][0-9]{1,2}){2}( [0-9]{1,2}(:[0-9]{2}){2})?/.source); matchers = new RegExp(matchers.join("|")); function parseDateString(dateString) { if (dateString instanceof Date) { diff --git a/dist/jquery.countdown.min.js b/dist/jquery.countdown.min.js index 2cf989a..95a782b 100644 --- a/dist/jquery.countdown.min.js +++ b/dist/jquery.countdown.min.js @@ -19,4 +19,4 @@ * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -!function(a){"function"==typeof define&&define.amd?define(["jquery"],a):a(jQuery)}(function(a){"use strict";function b(a){if(a instanceof Date)return a;if(String(a).match(g))return String(a).match(/^[0-9]*$/)&&(a=Number(a)),new Date(a);throw new Error("Couldn't cast `"+a+"` to a date object.")}function c(a){return function(b){var c=b.match(/%(-|!)?[A-Z]{1}(:[^;]+;)?/gi);if(c)for(var e=0,f=c.length;f>e;++e){var g=c[e].match(/%(-|!)?([a-zA-Z]{1})(:[^;]+;)?/),i=new RegExp(g[0]),j=g[1]||"",k=g[3]||"",l=null;g=g[2],h.hasOwnProperty(g)&&(l=h[g],l=Number(a[l])),null!==l&&("!"===j&&(l=d(k,l)),""===j&&10>l&&(l="0"+l.toString()),b=b.replace(i,l.toString()))}return b=b.replace(/%%/,"%")}}function d(a,b){var c="s",d="";return a&&(a=a.replace(/(:|;|\s)/gi,"").split(/\,/),1===a.length?c=a[0]:(d=a[0],c=a[1])),1===Math.abs(b)?d:c}var e=100,f=[],g=[];g.push(/^[0-9]*$/.source),g.push(/([0-9]{1,2}\/){2}[0-9]{4}( [0-9]{1,2}(:[0-9]{2}){2})?/.source),g.push(/[0-9]{4}(\/[0-9]{1,2}){2}( [0-9]{1,2}(:[0-9]{2}){2})?/.source),g=new RegExp(g.join("|"));var h={Y:"years",m:"months",w:"weeks",d:"days",D:"totalDays",H:"hours",M:"minutes",S:"seconds"},i=function(b,c,d){this.el=b,this.$el=a(b),this.interval=null,this.offset={},this.setFinalDate(c),this.instanceNumber=f.length,f.push(this),this.$el.data("countdown-instance",this.instanceNumber),d&&(this.$el.on("update.countdown",d),this.$el.on("stoped.countdown",d),this.$el.on("finish.countdown",d)),this.start()};a.extend(i.prototype,{start:function(){if(null!==this.interval)throw new Error("Countdown is already running!");var a=this;this.update(),this.interval=setInterval(function(){a.update.call(a)},e)},stop:function(){clearInterval(this.interval),this.interval=null,this.dispatchEvent("stoped")},pause:function(){this.stop.call(this)},resume:function(){this.start.call(this)},remove:function(){this.stop(),delete f[this.instanceNumber],delete this.$el.data().countdownInstance},setFinalDate:function(a){this.finalDate=b(a)},update:function(){return 0===this.$el.closest("html").length?(this.remove(),void 0):(this.totalSecsLeft=this.finalDate.valueOf()-(new Date).valueOf(),this.totalSecsLeft=Math.ceil(this.totalSecsLeft/1e3),this.totalSecsLeft=this.totalSecsLeft<0?0:this.totalSecsLeft,this.offset={seconds:this.totalSecsLeft%60,minutes:Math.floor(this.totalSecsLeft/60)%60,hours:Math.floor(this.totalSecsLeft/60/60)%24,days:Math.floor(this.totalSecsLeft/60/60/24)%7,totalDays:Math.floor(this.totalSecsLeft/60/60/24),weeks:Math.floor(this.totalSecsLeft/60/60/24/7),months:Math.floor(this.totalSecsLeft/60/60/24/30),years:Math.floor(this.totalSecsLeft/60/60/24/365)},0===this.totalSecsLeft?(this.stop(),this.dispatchEvent("finish")):this.dispatchEvent("update"),void 0)},dispatchEvent:function(b){var d=a.Event(b+".countdown");d.finalDate=this.finalDate,d.offset=a.extend({},this.offset),d.strftime=c(this.offset),this.$el.trigger(d)}}),a.fn.countdown=function(){var b=Array.prototype.slice.call(arguments,0);return this.each(function(){var c=a(this).data("countdown-instance");if(void 0!==c){var d=f[c],e=b[0];i.prototype.hasOwnProperty(e)?d[e].apply(d,b.slice(1)):null===String(e).match(/^[$A-Z_][0-9A-Z_$]*$/i)?d.setFinalDate.call(d,e):a.error("Method %s does not exist on jQuery.countdown".replace(/\%s/gi,e))}else new i(this,b[0],b[1])})}}); \ No newline at end of file +!function(a){"function"==typeof define&&define.amd?define(["jquery"],a):a(jQuery)}(function(a){"use strict";function b(a){if(a instanceof Date)return a;if(String(a).match(g))return String(a).match(/^[0-9]*$/)&&(a=Number(a)),new Date(a);throw new Error("Couldn't cast `"+a+"` to a date object.")}function c(a){return function(b){var c=b.match(/%(-|!)?[A-Z]{1}(:[^;]+;)?/gi);if(c)for(var e=0,f=c.length;f>e;++e){var g=c[e].match(/%(-|!)?([a-zA-Z]{1})(:[^;]+;)?/),i=new RegExp(g[0]),j=g[1]||"",k=g[3]||"",l=null;g=g[2],h.hasOwnProperty(g)&&(l=h[g],l=Number(a[l])),null!==l&&("!"===j&&(l=d(k,l)),""===j&&10>l&&(l="0"+l.toString()),b=b.replace(i,l.toString()))}return b=b.replace(/%%/,"%")}}function d(a,b){var c="s",d="";return a&&(a=a.replace(/(:|;|\s)/gi,"").split(/\,/),1===a.length?c=a[0]:(d=a[0],c=a[1])),1===Math.abs(b)?d:c}var e=100,f=[],g=[];g.push(/^[0-9]*$/.source),g.push(/([0-9]{1,2}\/){2}[0-9]{4}( [0-9]{1,2}(:[0-9]{2}){2})?/.source),g.push(/[0-9]{4}([\/\-][0-9]{1,2}){2}( [0-9]{1,2}(:[0-9]{2}){2})?/.source),g=new RegExp(g.join("|"));var h={Y:"years",m:"months",w:"weeks",d:"days",D:"totalDays",H:"hours",M:"minutes",S:"seconds"},i=function(b,c,d){this.el=b,this.$el=a(b),this.interval=null,this.offset={},this.setFinalDate(c),this.instanceNumber=f.length,f.push(this),this.$el.data("countdown-instance",this.instanceNumber),d&&(this.$el.on("update.countdown",d),this.$el.on("stoped.countdown",d),this.$el.on("finish.countdown",d)),this.start()};a.extend(i.prototype,{start:function(){if(null!==this.interval)throw new Error("Countdown is already running!");var a=this;this.update(),this.interval=setInterval(function(){a.update.call(a)},e)},stop:function(){clearInterval(this.interval),this.interval=null,this.dispatchEvent("stoped")},pause:function(){this.stop.call(this)},resume:function(){this.start.call(this)},remove:function(){this.stop(),delete f[this.instanceNumber],delete this.$el.data().countdownInstance},setFinalDate:function(a){this.finalDate=b(a)},update:function(){return 0===this.$el.closest("html").length?(this.remove(),void 0):(this.totalSecsLeft=this.finalDate.valueOf()-(new Date).valueOf(),this.totalSecsLeft=Math.ceil(this.totalSecsLeft/1e3),this.totalSecsLeft=this.totalSecsLeft<0?0:this.totalSecsLeft,this.offset={seconds:this.totalSecsLeft%60,minutes:Math.floor(this.totalSecsLeft/60)%60,hours:Math.floor(this.totalSecsLeft/60/60)%24,days:Math.floor(this.totalSecsLeft/60/60/24)%7,totalDays:Math.floor(this.totalSecsLeft/60/60/24),weeks:Math.floor(this.totalSecsLeft/60/60/24/7),months:Math.floor(this.totalSecsLeft/60/60/24/30),years:Math.floor(this.totalSecsLeft/60/60/24/365)},0===this.totalSecsLeft?(this.stop(),this.dispatchEvent("finish")):this.dispatchEvent("update"),void 0)},dispatchEvent:function(b){var d=a.Event(b+".countdown");d.finalDate=this.finalDate,d.offset=a.extend({},this.offset),d.strftime=c(this.offset),this.$el.trigger(d)}}),a.fn.countdown=function(){var b=Array.prototype.slice.call(arguments,0);return this.each(function(){var c=a(this).data("countdown-instance");if(void 0!==c){var d=f[c],e=b[0];i.prototype.hasOwnProperty(e)?d[e].apply(d,b.slice(1)):null===String(e).match(/^[$A-Z_][0-9A-Z_$]*$/i)?d.setFinalDate.call(d,e):a.error("Method %s does not exist on jQuery.countdown".replace(/\%s/gi,e))}else new i(this,b[0],b[1])})}}); \ No newline at end of file diff --git a/src/countdown.js b/src/countdown.js index 9603d9a..527f05e 100644 --- a/src/countdown.js +++ b/src/countdown.js @@ -15,8 +15,8 @@ matchers.push(/^[0-9]*$/.source); // Month/Day/Year [hours:minutes:seconds] matchers.push(/([0-9]{1,2}\/){2}[0-9]{4}( [0-9]{1,2}(:[0-9]{2}){2})?/.source); - // Year/Day/Month [hours:minutes:seconds] - matchers.push(/[0-9]{4}(\/[0-9]{1,2}){2}( [0-9]{1,2}(:[0-9]{2}){2})?/.source); + // Year/Day/Month [hours:minutes:seconds] and Year-Day-Month [hours:minutes:seconds] + matchers.push(/[0-9]{4}([\/\-][0-9]{1,2}){2}( [0-9]{1,2}(:[0-9]{2}){2})?/.source); // Cast the matchers to a regular expression object matchers = new RegExp(matchers.join("|")); // Parse a Date formatted has String to a native object From da8f85128eed84393744bbeed385ccfd53afc0bf Mon Sep 17 00:00:00 2001 From: Barta Akos Date: Mon, 3 Feb 2014 12:51:29 +0100 Subject: [PATCH 3/6] mysql format test --- test/countdown_test.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/test/countdown_test.js b/test/countdown_test.js index 16697fe..207fbd6 100644 --- a/test/countdown_test.js +++ b/test/countdown_test.js @@ -241,6 +241,13 @@ asyncTest('cast YYYY/MM/DD hh:mm:ss', 1, function() { }); }); +asyncTest('cast YYYY-MM-DD hh:mm:ss', 1, function() { + $dom.countdown('2020-10-20 12:34:56').on('update.countdown', function(event) { + ok(event.finalDate.toString().match(/Oct 20 2020 12:34:56/)); + start(); + }); +}); + asyncTest('cast YYYY/MM/DD', 1, function() { $dom.countdown('2020/10/20').on('update.countdown', function(event) { ok(event.finalDate.toString().match(/Oct 20 2020 00:00:00/)); From 6779a3dda66e5a4f7d4815afa3607663f52f91e9 Mon Sep 17 00:00:00 2001 From: bartaakos Date: Sun, 23 Feb 2014 20:10:57 +0100 Subject: [PATCH 4/6] Y-m-d dash workaround --- dist/jquery.countdown.js | 3 +++ src/countdown.js | 4 ++++ 2 files changed, 7 insertions(+) diff --git a/dist/jquery.countdown.js b/dist/jquery.countdown.js index 853ba5a..88d42c6 100644 --- a/dist/jquery.countdown.js +++ b/dist/jquery.countdown.js @@ -41,6 +41,9 @@ if (String(dateString).match(/^[0-9]*$/)) { dateString = Number(dateString); } + if(String(dateString).match(/^[0-9]*$/)) { + dateString = dateString.replace(/\-/g, '/'); + } return new Date(dateString); } else { throw new Error("Couldn't cast `" + dateString + "` to a date object."); diff --git a/src/countdown.js b/src/countdown.js index 527f05e..b854a38 100644 --- a/src/countdown.js +++ b/src/countdown.js @@ -32,6 +32,10 @@ if(String(dateString).match(/^[0-9]*$/)) { dateString = Number(dateString); } + // Replace dashes to slashes + if(String(dateString).match(/^[0-9]*$/)) { + dateString = dateString.replace(/\-/g, '/'); + } return new Date(dateString); } else { throw new Error("Couldn't cast `" + dateString + From 120e31b76f65f592d6fc17ef5e82e4dd2ee9afad Mon Sep 17 00:00:00 2001 From: bartaakos Date: Sun, 23 Feb 2014 20:21:57 +0100 Subject: [PATCH 5/6] Y-m-d dash workaround - String() --- dist/jquery.countdown.js | 2 +- src/countdown.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/dist/jquery.countdown.js b/dist/jquery.countdown.js index 88d42c6..46a0c2b 100644 --- a/dist/jquery.countdown.js +++ b/dist/jquery.countdown.js @@ -42,7 +42,7 @@ dateString = Number(dateString); } if(String(dateString).match(/^[0-9]*$/)) { - dateString = dateString.replace(/\-/g, '/'); + dateString = String(dateString).replace(/\-/g, '/'); } return new Date(dateString); } else { diff --git a/src/countdown.js b/src/countdown.js index b854a38..bd09730 100644 --- a/src/countdown.js +++ b/src/countdown.js @@ -34,7 +34,7 @@ } // Replace dashes to slashes if(String(dateString).match(/^[0-9]*$/)) { - dateString = dateString.replace(/\-/g, '/'); + dateString = String(dateString).replace(/\-/g, '/'); } return new Date(dateString); } else { From 924455cb40df3591594384f59f9625ba8aa8cadd Mon Sep 17 00:00:00 2001 From: bartaakos Date: Sun, 23 Feb 2014 20:29:50 +0100 Subject: [PATCH 6/6] Y-m-d dash workaround - match fix --- dist/jquery.countdown.js | 2 +- src/countdown.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/dist/jquery.countdown.js b/dist/jquery.countdown.js index 46a0c2b..1d13ebe 100644 --- a/dist/jquery.countdown.js +++ b/dist/jquery.countdown.js @@ -41,7 +41,7 @@ if (String(dateString).match(/^[0-9]*$/)) { dateString = Number(dateString); } - if(String(dateString).match(/^[0-9]*$/)) { + if(String(dateString).match(/\-/)) { dateString = String(dateString).replace(/\-/g, '/'); } return new Date(dateString); diff --git a/src/countdown.js b/src/countdown.js index bd09730..7dfae59 100644 --- a/src/countdown.js +++ b/src/countdown.js @@ -33,7 +33,7 @@ dateString = Number(dateString); } // Replace dashes to slashes - if(String(dateString).match(/^[0-9]*$/)) { + if(String(dateString).match(/\-/)) { dateString = String(dateString).replace(/\-/g, '/'); } return new Date(dateString);