|
1 | 1 | /** |
2 | | - * angular-timer - v1.1.6 - 2014-07-01 7:37 AM |
| 2 | + * angular-timer - v1.1.8 - 2014-10-24 3:55 PM |
3 | 3 | * https://github.com/siddii/angular-timer |
4 | 4 | * |
5 | 5 | * Copyright (c) 2014 Siddique Hameed |
@@ -113,7 +113,9 @@ var timerModule = angular.module('timer', []) |
113 | 113 | }); |
114 | 114 |
|
115 | 115 | function calculateTimeUnits() { |
116 | | - |
| 116 | + if ($attrs.startTime !== undefined){ |
| 117 | + $scope.millis = new Date() - new Date($scope.startTimeAttr); |
| 118 | + } |
117 | 119 | // compute time values based on maxTimeUnit specification |
118 | 120 | if (!$scope.maxTimeUnit || $scope.maxTimeUnit === 'day') { |
119 | 121 | $scope.seconds = Math.floor(($scope.millis / 1000) % 60); |
@@ -158,14 +160,13 @@ var timerModule = angular.module('timer', []) |
158 | 160 | $scope.months = Math.floor((($scope.millis / (3600000)) / 24 / 30) % 12); |
159 | 161 | $scope.years = Math.floor(($scope.millis / (3600000)) / 24 / 365); |
160 | 162 | } |
161 | | - |
162 | 163 | // plural - singular unit decision |
163 | | - $scope.secondsS = $scope.seconds == 1 ? '' : 's'; |
164 | | - $scope.minutesS = $scope.minutes == 1 ? '' : 's'; |
165 | | - $scope.hoursS = $scope.hours == 1 ? '' : 's'; |
166 | | - $scope.daysS = $scope.days == 1 ? '' : 's'; |
167 | | - $scope.monthsS = $scope.months == 1 ? '' : 's'; |
168 | | - $scope.yearsS = $scope.years == 1 ? '' : 's'; |
| 164 | + $scope.secondsS = ($scope.seconds === 1 || $scope.seconds === 0) ? '' : 's'; |
| 165 | + $scope.minutesS = ($scope.minutes === 1 || $scope.minutes === 0) ? '' : 's'; |
| 166 | + $scope.hoursS = ($scope.hours === 1 || $scope.hours === 0) ? '' : 's'; |
| 167 | + $scope.daysS = ($scope.days === 1 || $scope.days === 0)? '' : 's'; |
| 168 | + $scope.monthsS = ($scope.months === 1 || $scope.months === 0)? '' : 's'; |
| 169 | + $scope.yearsS = ($scope.years === 1 || $scope.years === 0)? '' : 's'; |
169 | 170 | //add leading zero if number is smaller than 10 |
170 | 171 | $scope.sseconds = $scope.seconds < 10 ? '0' + $scope.seconds : $scope.seconds; |
171 | 172 | $scope.mminutes = $scope.minutes < 10 ? '0' + $scope.minutes : $scope.minutes; |
|
0 commit comments