Skip to content

Commit c0bb625

Browse files
committed
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.
1 parent 783e322 commit c0bb625

File tree

1 file changed

+23
-5
lines changed

1 file changed

+23
-5
lines changed

app/js/timer.js

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,10 @@ angular.module('timer', [])
66
scope: {
77
interval: '=interval',
88
startTimeAttr: '=startTime',
9-
countdownattr: '=countdown'
9+
countdownattr: '=countdown',
10+
fullSeconds: '=fullSeconds',
11+
fullMinutes: '=fullMinutes',
12+
fullHours: '=fullHours'
1013
},
1114
controller: function ($scope, $element, $attrs) {
1215
//angular 1.2 doesn't support attributes ending in "-start", so we're
@@ -69,7 +72,7 @@ angular.module('timer', [])
6972
$scope.$emit('timer-stopped', {millis: $scope.millis, seconds: $scope.seconds, minutes: $scope.minutes, hours: $scope.hours, days: $scope.days});
7073
$scope.timeoutId = null;
7174
};
72-
75+
7376
$scope.end = $element[0].end = function () {
7477
resetTimeout();
7578
$scope.startTime = null;
@@ -89,9 +92,24 @@ angular.module('timer', [])
8992
});
9093

9194
function calculateTimeUnits() {
92-
$scope.seconds = Math.floor(($scope.millis / 1000) % 60);
93-
$scope.minutes = Math.floor((($scope.millis / (60000)) % 60));
94-
$scope.hours = Math.floor((($scope.millis / (3600000)) % 24));
95+
if ($scope.fullSeconds) {
96+
$scope.seconds = Math.floor($scope.millis / 1000);
97+
} else {
98+
$scope.seconds = Math.floor(($scope.millis / 1000) % 60);
99+
}
100+
101+
if ($scope.fullMinutes === true) {
102+
$scope.minutes = Math.floor($scope.millis / 60000);
103+
} else {
104+
$scope.minutes = Math.floor((($scope.millis / (60000)) % 60));
105+
}
106+
107+
if ($scope.fullHours === true) {
108+
$scope.hours = Math.floor($scope.millis / 3600000);
109+
} else {
110+
$scope.hours = Math.floor((($scope.millis / (3600000)) % 24));
111+
}
112+
95113
$scope.days = Math.floor((($scope.millis / (3600000)) / 24));
96114
}
97115

0 commit comments

Comments
 (0)