jquery-countdown
jquery-countdown copied to clipboard
format: "hh:mm:ss" is not working with startTime: _date
Time formating is not working if startTime is taken from date object.
This will not format to "dd:hh:mm", it will stay "dd:hh:mm:ss"
var _date = new Date();
_date.setMonth(10);
_date.setDate(20);
_date.setHours(0);
_date.setMinutes(0);
_date.setSeconds(0);
$('#counter').countdown({
format: "dd:hh:mm",
startTime: _date,
image: 'img/digits.png'
});
Same problem. any solution?
The reason for this is that:
- The user supplied date format is in the UserOptions and these are not applied before the code applies to when a date object is provided.
- The code that handles date object effectively overrides the format provided by splitting the computed date into dd:hh:mm:ss I have created a patch to show how this could be addressed. This checks for various formats that may have been provided for when dealing with dates. However what would be neater is if the input format is 'applied' when creating the date string as opposed to only supporting some options as with the patch. So it coud support say mm:ss, or dd:hh etc Patch
diff --git a/js/jquery.countdown.js b/js/jquery.countdown.js
index 26df4ef..066b180 100644
--- a/js/jquery.countdown.js
+++ b/js/jquery.countdown.js
@@ -23,6 +23,8 @@
image: "digits.png"
};
var digits = [], interval;
+
+ $.extend(true, options, userOptions);
// Draw digits in given container
var createDigits = function(where) {
@@ -50,7 +52,20 @@
var hours = Math.floor((datediff % 86400) / 3600);
var minutes = Math.floor(((datediff % 86400) % 3600) / 60);
var seconds = ((datediff % 86400) % 3600) % 60;
- options.startTime = days + ":" + hours + ":" + minutes + ":" + seconds;
+ switch (options.format) {
+ case "dd:hh:mm:ss":
+ options.startTime = days + ":" + hours + ":" + minutes + ":" + seconds;
+ break;
+ case "hh:mm:ss":
+ options.startTime = hours + ":" + minutes + ":" + seconds;
+ break;
+ case "hh:mm":
+ options.startTime = hours + ":" + minutes;
+ break;
+ default:
+ options.startTime = days + ":" + hours + ":" + minutes + ":" + seconds;
+ }
+
}
_startTime = options.startTime.split("");
@@ -238,7 +253,7 @@
"pause": pause
});
- $.extend(options, userOptions);
+
this.css({height: options.digitHeight, overflow: 'hidden'});
createDigits(this);
if (options.autoStart) {