From c0bb6253c09ed1bc5f313afbdf54bff750674626 Mon Sep 17 00:00:00 2001 From: Kersten Burkhardt Date: Wed, 4 Sep 2013 09:57:38 +0200 Subject: [PATCH 1/3] Added attributes for displaying full seconds / minutes / hours This change will help me to show a timer like 235:59 (minutes:seconds) if I don't want to show hours or days. --- app/js/timer.js | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/app/js/timer.js b/app/js/timer.js index 5b4b4f8..7403f84 100644 --- a/app/js/timer.js +++ b/app/js/timer.js @@ -6,7 +6,10 @@ angular.module('timer', []) scope: { interval: '=interval', startTimeAttr: '=startTime', - countdownattr: '=countdown' + countdownattr: '=countdown', + fullSeconds: '=fullSeconds', + fullMinutes: '=fullMinutes', + fullHours: '=fullHours' }, controller: function ($scope, $element, $attrs) { //angular 1.2 doesn't support attributes ending in "-start", so we're @@ -69,7 +72,7 @@ angular.module('timer', []) $scope.$emit('timer-stopped', {millis: $scope.millis, seconds: $scope.seconds, minutes: $scope.minutes, hours: $scope.hours, days: $scope.days}); $scope.timeoutId = null; }; - + $scope.end = $element[0].end = function () { resetTimeout(); $scope.startTime = null; @@ -89,9 +92,24 @@ angular.module('timer', []) }); function calculateTimeUnits() { - $scope.seconds = Math.floor(($scope.millis / 1000) % 60); - $scope.minutes = Math.floor((($scope.millis / (60000)) % 60)); - $scope.hours = Math.floor((($scope.millis / (3600000)) % 24)); + if ($scope.fullSeconds) { + $scope.seconds = Math.floor($scope.millis / 1000); + } else { + $scope.seconds = Math.floor(($scope.millis / 1000) % 60); + } + + if ($scope.fullMinutes === true) { + $scope.minutes = Math.floor($scope.millis / 60000); + } else { + $scope.minutes = Math.floor((($scope.millis / (60000)) % 60)); + } + + if ($scope.fullHours === true) { + $scope.hours = Math.floor($scope.millis / 3600000); + } else { + $scope.hours = Math.floor((($scope.millis / (3600000)) % 24)); + } + $scope.days = Math.floor((($scope.millis / (3600000)) / 24)); } From 78f180308d0bb33f98c1ca1bce0c569797e55e9a Mon Sep 17 00:00:00 2001 From: Kersten Burkhardt Date: Wed, 4 Sep 2013 09:58:37 +0200 Subject: [PATCH 2/3] Update timer.js added true to fullSeconds --- app/js/timer.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/js/timer.js b/app/js/timer.js index 7403f84..c4912f1 100644 --- a/app/js/timer.js +++ b/app/js/timer.js @@ -92,7 +92,7 @@ angular.module('timer', []) }); function calculateTimeUnits() { - if ($scope.fullSeconds) { + if ($scope.fullSeconds === true) { $scope.seconds = Math.floor($scope.millis / 1000); } else { $scope.seconds = Math.floor(($scope.millis / 1000) % 60); From 71fef68930cd588b9faf5cf19898817629f86342 Mon Sep 17 00:00:00 2001 From: Kersten Burkhardt Date: Wed, 4 Sep 2013 11:15:07 +0200 Subject: [PATCH 3/3] Update timer.js Updated usage without API --- app/js/timer.js | 29 ++++++++--------------------- 1 file changed, 8 insertions(+), 21 deletions(-) diff --git a/app/js/timer.js b/app/js/timer.js index c4912f1..03020de 100644 --- a/app/js/timer.js +++ b/app/js/timer.js @@ -6,10 +6,7 @@ angular.module('timer', []) scope: { interval: '=interval', startTimeAttr: '=startTime', - countdownattr: '=countdown', - fullSeconds: '=fullSeconds', - fullMinutes: '=fullMinutes', - fullHours: '=fullHours' + countdownattr: '=countdown' }, controller: function ($scope, $element, $attrs) { //angular 1.2 doesn't support attributes ending in "-start", so we're @@ -92,25 +89,15 @@ angular.module('timer', []) }); function calculateTimeUnits() { - if ($scope.fullSeconds === true) { - $scope.seconds = Math.floor($scope.millis / 1000); - } else { - $scope.seconds = Math.floor(($scope.millis / 1000) % 60); - } - - if ($scope.fullMinutes === true) { - $scope.minutes = Math.floor($scope.millis / 60000); - } else { - $scope.minutes = Math.floor((($scope.millis / (60000)) % 60)); - } + $scope.seconds = Math.floor(($scope.millis / 1000) % 60); + $scope.minutes = Math.floor(($scope.millis / 60000) % 60); + $scope.hours = Math.floor(($scope.millis / 3600000) % 24); - if ($scope.fullHours === true) { - $scope.hours = Math.floor($scope.millis / 3600000); - } else { - $scope.hours = Math.floor((($scope.millis / (3600000)) % 24)); - } + $scope.fullSeconds = Math.floor($scope.millis / 1000); + $scope.fullMinutes = Math.floor($scope.millis / 60000); + $scope.fullHours = Math.floor($scope.millis / 3600000); - $scope.days = Math.floor((($scope.millis / (3600000)) / 24)); + $scope.days = Math.floor(($scope.millis / 3600000) / 24); } //determine initial values of time units