Skip to content

Commit

Permalink
Add UTC support
Browse files Browse the repository at this point in the history
  • Loading branch information
VincentLoy committed Aug 29, 2015
1 parent 86a68b4 commit 0e5c682
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 11 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ $ npm install simplycountdown.js
inline: false, //set to true to get an inline basic countdown like : 24 days, 4 hours, 2 minutes, 5 seconds
inlineClass: 'simply-countdown-inline', //inline css span class in case of inline = true
// in case of inline set to false
enableUtc: true, //Use UTC as default
sectionClass: 'simply-section', //section css class
amountClass: 'simply-amount', // amount css class
wordClass: 'simply-word' // word css class
Expand Down Expand Up @@ -110,6 +111,11 @@ You can easly customize the countdown using the css theme starter file or create

### Changelog

##### 1.2.0
- Resolve #4 - Add UTC support adding enableUtc parameter
```javascript
enableUtc: true //true is default
```
##### 1.1.1
- Resolve #3 - Remove ID Only compatibility

Expand Down
4 changes: 2 additions & 2 deletions bower.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "simplycountdown.js",
"version": "1.1.1",
"version": "1.2.0",
"homepage": "https://github.com/VincentLoy/simplyCountdown.js",
"authors": [
"VincentLoy <[email protected]>"
Expand All @@ -26,7 +26,7 @@
"*.md"
],
"dependencies": {
"jquery": "~1.11.3"
"jquery": ">=1.11.3"
},
"devDependencies": {
"lesshat": "~3.0.0",
Expand Down
27 changes: 22 additions & 5 deletions dev/simplyCountdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* File : simplyCountdown
* Date : 27/06/2015
* License : MIT
* Version : 1.1.1
* Version : 1.2.0
* Author : Vincent Loy <[email protected]>
*/
/*global window, document*/
Expand Down Expand Up @@ -56,21 +56,24 @@
},
plural: true,
inline: false,
enableUtc: true,
inlineClass: 'simply-countdown-inline',
sectionClass: 'simply-section',
amountClass: 'simply-amount',
wordClass: 'simply-word'
}, args),
targetDate,
currentDate,
targetTmpDate,
now,
nowUtc,
secondsLeft,
days,
hours,
minutes,
seconds,
cd = document.querySelectorAll(elt);

targetDate = new Date(
targetTmpDate = new Date(
parameters.year,
parameters.month - 1,
parameters.day,
Expand All @@ -79,6 +82,13 @@
parameters.seconds
);

if (parameters.enableUtc) {
targetDate = new Date(targetTmpDate.getUTCFullYear(), targetTmpDate.getUTCMonth(), targetTmpDate.getUTCDate(), targetTmpDate.getUTCHours(),
targetTmpDate.getUTCMinutes(), targetTmpDate.getUTCSeconds());
} else {
targetDate = targetTmpDate;
}

Array.prototype.forEach.call(cd, function (countdown) {

window.setInterval(function () {
Expand All @@ -93,8 +103,15 @@
fullCountDown,
secondWord;

currentDate = new Date().getTime();
secondsLeft = (targetDate - currentDate) / 1000;
now = new Date();
if (parameters.enableUtc) {
nowUtc = new Date(now.getFullYear(), now.getMonth(), now.getDate(), now.getHours(),
now.getMinutes(), now.getSeconds());
secondsLeft = (targetDate - nowUtc.getTime()) / 1000;

} else {
secondsLeft = (targetDate - now.getTime()) / 1000;
}

if (secondsLeft > 0) {
days = parseInt(secondsLeft / 86400, 10);
Expand Down
Loading

0 comments on commit 0e5c682

Please sign in to comment.