Skip to content

Commit 21f1d51

Browse files
author
sanderaido
committed
Update angular-timer.js
Removed zero-unit pluralization and added new unit functions with custom string support.
1 parent 0e313e6 commit 21f1d51

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

dist/angular-timer.js

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -160,13 +160,20 @@ var timerModule = angular.module('timer', [])
160160
$scope.months = Math.floor((($scope.millis / (3600000)) / 24 / 30) % 12);
161161
$scope.years = Math.floor(($scope.millis / (3600000)) / 24 / 365);
162162
}
163-
// plural - singular unit decision
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';
163+
// plural - singular unit decision (old syntax, for backwards compatibility and English only)
164+
$scope.secondsS = ($scope.seconds === 1) ? '' : 's';
165+
$scope.minutesS = ($scope.minutes === 1) ? '' : 's';
166+
$scope.hoursS = ($scope.hours === 1) ? '' : 's';
167+
$scope.daysS = ($scope.days === 1)? '' : 's';
168+
$scope.monthsS = ($scope.months === 1)? '' : 's';
169+
$scope.yearsS = ($scope.years === 1)? '' : 's';
170+
// new plural-singular unit decision functions (for custom units and multilingual support)
171+
$scope.secondUnit = function(singleSecond, pluralSecond){if($scope.seconds === 1){return singleSecond} return pluralSecond};
172+
$scope.minuteUnit = function(singleMinute, pluralMinute){if($scope.minutes === 1){return singleMinute} return pluralMinute};
173+
$scope.hourUnit = function(singleHour, pluralHour){if($scope.hours === 1){return singleHour} return pluralHour};
174+
$scope.dayUnit = function(singleDay, pluralDay){if($scope.days === 1){return singleDay} return pluralDay};
175+
$scope.monthUnit = function(singleMonth, pluralMonth){if($scope.months === 1){return singleMonth} return pluralMonth};
176+
$scope.yearUnit = function(singleYear, pluralYear){if($scope.years === 1){return singleYear} return pluralYear};
170177
//add leading zero if number is smaller than 10
171178
$scope.sseconds = $scope.seconds < 10 ? '0' + $scope.seconds : $scope.seconds;
172179
$scope.mminutes = $scope.minutes < 10 ? '0' + $scope.minutes : $scope.minutes;

0 commit comments

Comments
 (0)