Skip to content

Commit

Permalink
user format utilized in endTime computation, some whitespace adjustments
Browse files Browse the repository at this point in the history
  • Loading branch information
mattneary committed Dec 2, 2013
1 parent 654c7fe commit ef86b69
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
2 changes: 1 addition & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
$(".digits").countdown({
image: "img/digits.png",
format: "dd:hh:mm:ss",
endTime: new Date(2013, 12, 25)
endTime: new Date(2013, 12, 2)
});
});
</script>
Expand Down
15 changes: 8 additions & 7 deletions js/jquery.countdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,11 +133,11 @@ var moveDigit = function(elem, options) {
// ... precision is the same as the format.
var parseRelativeDate = function(form, options) {
// give the date the values of now by default
var now = new Date();
var d = now.getDate();
var m = now.getMonth() + 1;
var y = now.getFullYear();
var h = now.getHours(), mm, s;
var now = new Date();
var d = now.getDate();
var m = now.getMonth() + 1;
var y = now.getFullYear();
var h = now.getHours(), mm, s;

// read in components and render based on format
var format = options.format;
Expand Down Expand Up @@ -201,15 +201,16 @@ jQuery.fn.countdown = function(userOptions) {
image: "digits.png",
continuous: false
};
$.extend(options, userOptions);

// if an endTime is provided...
if( userOptions.endTime ) {
// calculate the difference between endTime and present time
var endDate = userOptions.endTime instanceof Date ? userOptions.endTime : parseRelativeDate(userOptions.endTime, options);
var diff = endDate.getTime() - (new Date()).getTime();
var diff = endDate.getTime() - (new Date()).getTime();
// and set that as the startTime
userOptions.startTime = formatCompute(new Date(diff), options);
delete userOptions.endTime;
delete userOptions.endTime;
}
$.extend(options, userOptions);
createDigits(this, options);
Expand Down

0 comments on commit ef86b69

Please sign in to comment.