Skip to content

Commit 0711c00

Browse files
committed
Merge pull request siddii#54 from itslenny/master
added simple variable for S for plural/singular units
2 parents 9a67d66 + 2d4843e commit 0711c00

File tree

5 files changed

+55
-11
lines changed

5 files changed

+55
-11
lines changed

app/js/timer.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,10 +95,15 @@ angular.module('timer', [])
9595
});
9696

9797
function calculateTimeUnits() {
98+
9899
$scope.seconds = Math.floor(($scope.millis / 1000) % 60);
100+
$scope.secondsS = $scope.seconds==1 ? '' : 's';
99101
$scope.minutes = Math.floor((($scope.millis / (60000)) % 60));
102+
$scope.minutesS = $scope.minutes==1 ? '' : 's';
100103
$scope.hours = Math.floor((($scope.millis / (3600000)) % 24));
104+
$scope.hoursS = $scope.hours==1 ? '' : 's';
101105
$scope.days = Math.floor((($scope.millis / (3600000)) / 24));
106+
$scope.daysS = $scope.days==1 ? '' : 's';
102107

103108
//add leading zero if number is smaller than 10
104109
$scope.sseconds = $scope.seconds < 10 ? '0' + $scope.seconds : $scope.seconds;

dist/angular-timer.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,17 +102,24 @@ angular.module('timer', [])
102102
});
103103

104104
function calculateTimeUnits() {
105+
105106
$scope.seconds = Math.floor(($scope.millis / 1000) % 60);
107+
$scope.secondsS = $scope.seconds==1 ? '' : 's';
106108
$scope.minutes = Math.floor((($scope.millis / (60000)) % 60));
109+
$scope.minutesS = $scope.minutes==1 ? '' : 's';
107110
$scope.hours = Math.floor((($scope.millis / (3600000)) % 24));
111+
$scope.hoursS = $scope.hours==1 ? '' : 's';
108112
$scope.days = Math.floor((($scope.millis / (3600000)) / 24));
113+
$scope.daysS = $scope.days==1 ? '' : 's';
114+
109115

110116
//add leading zero if number is smaller than 10
111117
$scope.sseconds = $scope.seconds < 10 ? '0' + $scope.seconds : $scope.seconds;
112118
$scope.mminutes = $scope.minutes < 10 ? '0' + $scope.minutes : $scope.minutes;
113119
$scope.hhours = $scope.hours < 10 ? '0' + $scope.hours : $scope.hours;
114120
$scope.ddays = $scope.days < 10 ? '0' + $scope.days : $scope.days;
115121

122+
116123
}
117124
//determine initial values of time units and add AddSeconds functionality
118125
if ($scope.countdownattr) {

dist/angular-timer.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

index.html

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,26 @@ <h3>
161161
<button class="btn" onclick="stopResumeTimer('auto-start-false-timer', this)" type="button">Start</button>
162162
</div>
163163
</section>
164+
165+
<section id="plural-unit-timer">
166+
<h3>Plural / Singular units</h3>
167+
168+
<div class="bs-docs-example">
169+
<p>
170+
Two stopped countdown timers to illustrate how to handle pluralization of time units.
171+
<code ng-non-bindable="">
172+
&lt;timer autostart="false" countdown="90061"&gt;{{days}} day{{daysS}}, {{hours}} hour{{hoursS}}, {{minutes}} minute{{minutesS}}, {{seconds}} second{{secondsS}}.&lt;/timer&gt;
173+
</code>
174+
175+
<h3 class="singular-counter">
176+
<timer autostart="false" countdown="90061">{{days}} day{{daysS}}, {{hours}} hour{{hoursS}}, {{minutes}} minute{{minutesS}}, {{seconds}} second{{secondsS}}.</timer>
177+
</h3>
178+
<h3 class="plural-counter">
179+
<timer autostart="false" countdown="190061">{{days}} day{{daysS}}, {{hours}} hour{{hoursS}}, {{minutes}} minute{{minutesS}}, {{seconds}} second{{secondsS}}.</timer>
180+
</h3>
181+
</div>
182+
</section>
183+
164184
<section id="markup">
165185
<h3>
166186
Markup</h3>

test/e2e/scenarios.js

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -86,16 +86,28 @@ describe('Angular Timer E2E Tests', function () {
8686
var afterTime = element('#timer-with-end-time timer span').html();
8787
expect(beforeTime).toHaveMoreSecondsThan(afterTime);
8888
});
89+
90+
it('Plural / Singular Units - Should properly pluralize units', function () {
91+
expect(element('#plural-unit-timer .singular-counter timer').html()).toMatch(/1 day,/);
92+
expect(element('#plural-unit-timer .singular-counter timer').html()).toMatch(/1 hour,/);
93+
expect(element('#plural-unit-timer .singular-counter timer').html()).toMatch(/1 minute,/);
94+
expect(element('#plural-unit-timer .singular-counter timer').html()).toMatch(/1 second/);
8995

90-
it('Leading zero timer - should add a leading zero if number is smaller than 10', function() {
91-
sleep(1);
92-
expect(element('#clock-timer-leading-zero timer').html()).toMatch(/00 hours,/);
93-
expect(element('#clock-timer-leading-zero timer').html()).toMatch(/00 minutes,/);
94-
expect(element('#clock-timer-leading-zero timer').html()).toMatch(/01 seconds./);
95-
sleep(10);
96-
expect(element('#clock-timer-leading-zero timer').html()).toMatch(/00 hours,/);
97-
expect(element('#clock-timer-leading-zero timer').html()).toMatch(/00 minutes,/);
98-
expect(element('#clock-timer-leading-zero timer').html()).toMatch(/11 seconds./);
99-
});
96+
expect(element('#plural-unit-timer .plural-counter timer').html()).toMatch(/days,/);
97+
expect(element('#plural-unit-timer .plural-counter timer').html()).toMatch(/hours,/);
98+
expect(element('#plural-unit-timer .plural-counter timer').html()).toMatch(/minutes,/);
99+
expect(element('#plural-unit-timer .plural-counter timer').html()).toMatch(/seconds/);
100+
});
101+
102+
it('Leading zero timer - should add a leading zero if number is smaller than 10', function() {
103+
sleep(1);
104+
expect(element('#clock-timer-leading-zero timer').html()).toMatch(/00 hours,/);
105+
expect(element('#clock-timer-leading-zero timer').html()).toMatch(/00 minutes,/);
106+
expect(element('#clock-timer-leading-zero timer').html()).toMatch(/01 seconds./);
107+
sleep(10);
108+
expect(element('#clock-timer-leading-zero timer').html()).toMatch(/00 hours,/);
109+
expect(element('#clock-timer-leading-zero timer').html()).toMatch(/00 minutes,/);
110+
expect(element('#clock-timer-leading-zero timer').html()).toMatch(/11 seconds./);
111+
});
100112

101113
});

0 commit comments

Comments
 (0)