Skip to content

Commit 37f5b63

Browse files
committed
Merge pull request siddii#118 from polomarcus/fix-plurial
plural - singular unit decision now detects 0 and 1 instead of just 1
2 parents e54608f + bf9e5af commit 37f5b63

File tree

3 files changed

+67
-61
lines changed

3 files changed

+67
-61
lines changed

app/js/timer.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -154,12 +154,12 @@ var timerModule = angular.module('timer', [])
154154
$scope.years = Math.floor(($scope.millis / (3600000)) / 24 / 365);
155155
}
156156
// plural - singular unit decision
157-
$scope.secondsS = $scope.seconds == 1 ? '' : 's';
158-
$scope.minutesS = $scope.minutes == 1 ? '' : 's';
159-
$scope.hoursS = $scope.hours == 1 ? '' : 's';
160-
$scope.daysS = $scope.days == 1 ? '' : 's';
161-
$scope.monthsS = $scope.months == 1 ? '' : 's';
162-
$scope.yearsS = $scope.years == 1 ? '' : 's';
157+
$scope.secondsS = ($scope.seconds === 1 || $scope.seconds === 0) ? '' : 's';
158+
$scope.minutesS = ($scope.minutes === 1 || $scope.minutes === 0) ? '' : 's';
159+
$scope.hoursS = ($scope.hours === 1 || $scope.hours === 0) ? '' : 's';
160+
$scope.daysS = ($scope.days === 1 || $scope.days === 0)? '' : 's';
161+
$scope.monthsS = ($scope.months === 1 || $scope.months === 0)? '' : 's';
162+
$scope.yearsS = ($scope.years === 1 || $scope.years === 0)? '' : 's';
163163
//add leading zero if number is smaller than 10
164164
$scope.sseconds = $scope.seconds < 10 ? '0' + $scope.seconds : $scope.seconds;
165165
$scope.mminutes = $scope.minutes < 10 ? '0' + $scope.minutes : $scope.minutes;

index.html

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ <h3>Timer with start time and auto start set</h3>
5454

5555
<div class="bs-docs-example">
5656
<p>This will start a timer with 1410914940000 milliseconds and stopped</p>
57-
57+
5858
<h3>
5959
<timer start-time="1410914940000" autostart="false"></timer>
6060
</h3>
@@ -66,11 +66,11 @@ <h3>
6666

6767
<div class="bs-docs-example">
6868
<p>
69-
This markup <code ng-non-bindable="">&lt;timer interval=&quot;1000&quot;&gt;{{hours}} hours, {{minutes}}
70-
minutes, {{seconds}} seconds.&lt;/timer&gt;</code> will run the clock timer ticking every second</p>
69+
This markup <code ng-non-bindable="">&lt;timer interval=&quot;1000&quot;&gt;{{hours}} hour{{hoursS}}, {{minutes}}
70+
minute{{minutesS}}, {{seconds}} second{{secondsS}}.&lt;/timer&gt;</code> will run the clock timer ticking every second</p>
7171

7272
<h3>
73-
<timer interval="1000">{{hours}} hours, {{minutes}} minutes, {{seconds}} seconds.</timer>
73+
<timer interval="1000">{{hours}} hour{{hoursS}}, {{minutes}} minute{{minutesS}}, {{seconds}} second{{secondsS}}.</timer>
7474
</h3>
7575
<button class="btn" onclick="stopResumeTimer('clock-timer', this)" type="button">Stop</button>
7676
</div>
@@ -81,11 +81,11 @@ <h3>
8181

8282
<div class="bs-docs-example">
8383
<p>
84-
This markup <code ng-non-bindable="">&lt;timer interval=&quot;1000&quot;&gt;{{hhours}} hours, {{mminutes}}
85-
minutes, {{sseconds}} seconds.&lt;/timer&gt;</code> will run the clock timer ticking every second with an additional zero at the beginning if unit is smaller than 10</p>
84+
This markup <code ng-non-bindable="">&lt;timer interval=&quot;1000&quot;&gt;{{hhours}} hour{{hhoursS}}, {{mminutes}}
85+
minute{{minutesS}}, {{sseconds}} second{{secondsS}}.&lt;/timer&gt;</code> will run the clock timer ticking every second with an additional zero at the beginning if unit is smaller than 10</p>
8686

8787
<h3>
88-
<timer interval="1000">{{hhours}} hours, {{mminutes}} minutes, {{sseconds}} seconds.</timer>
88+
<timer interval="1000">{{hhours}} hour{{hoursS}}, {{mminutes}} minute{{minutesS}}, {{sseconds}} second{{secondsS}}</timer>
8989
</h3>
9090
<button class="btn" onclick="stopResumeTimer('clock-timer-leading-zero', this)" type="button">Stop</button>
9191
</div>
@@ -201,7 +201,7 @@ <h3>Countdown time display according to specified <em>max-time-unit</em></h3>
201201
<p>
202202
This markup will display countdown time in minute and seconds only. This attribute can be applied to regular clock timer as well.
203203
<code ng-non-bindable="">
204-
&lt;timer countdown="10041" max-time-unit="'minute'" interval="1000"&gt;{{mminutes}} minute{{minutesS}}, {{sseconds}} second{{secondsS}}&lt;/timer&gt;
204+
&lt;timer countdown="10041" max-time-unit="'minute'" interval="1000"&gt;{{mminutes}} minute{{minutesS}}, {{sseconds}} second{{secondsS}}&lt;/timer&gt;
205205
</code>
206206
</p>
207207
<p class="muted">countdown Time with max time unit option - year</p>
@@ -217,7 +217,7 @@ <h3 class="WithMaxTimeUnitAsMinute">
217217
<h3 class="WithMaxTimeUnitAsSecond">
218218
<timer countdown="10041" max-time-unit="'second'" interval="1000"> {{mminutes}} minute{{minutesS}}, {{sseconds}} second{{secondsS}}</timer>
219219
</h3>
220-
220+
221221
<p class="muted">countdown Time without max time unit option - minute</p>
222222
<h3 class="WithoutMaxTimeUnit">
223223
<timer countdown="10041" interval="1000"> {{ddays}} day{{daysS}}, {{hhours}} hour{{hoursS}}, {{mminutes}} minute{{minutesS}}, {{sseconds}} second{{secondsS}}</timer>
@@ -339,7 +339,7 @@ <h4>
339339
<td>
340340
false
341341
</td>
342-
<td> no default value. But you can give value, 'minute', 'second', or 'hour'.
342+
<td> no default value. But you can give value, 'minute', 'second', or 'hour'.
343343
</td>
344344
</tr>
345345
</tbody>

test/e2e/scenarios.js

Lines changed: 51 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -25,26 +25,26 @@ describe('Angular Timer E2E Tests', function () {
2525

2626
angular.scenario.matcher('toCompareWith', function(future) {
2727
function getUnitValue (text, unitName) {
28-
var arr = text.toLowerCase().match(/\w+/g),
28+
var arr = text.toLowerCase().match(/\w+/g),
2929
returnVal,
3030
numInd= -1;
31-
arr.every(function (item,index,list) {
31+
arr.every(function (item,index,list) {
3232
if(isNaN(item)) {
3333
if(index===0) {
3434
numInd=1;
3535
}
36-
if(item === unitName) {
36+
if(item === unitName) {
3737
returnVal = list[index+numInd];
3838
return false;
3939
}
4040
}
41-
return true;
42-
});
41+
return true;
42+
});
4343
return returnVal;
4444
}
4545

46-
var unitVal = getUnitValue(this.future.timerText.value,this.future.unit),
47-
compareResultFlag=false;
46+
var unitVal = getUnitValue(this.future.timerText.value,this.future.unit),
47+
compareResultFlag=false;
4848
if(this.future.compareTo === 'GreaterThan') {
4949
compareResultFlag = Number(unitVal) > Number(future);
5050
} else if(this.future.compareTo === 'LessThan') {
@@ -90,9 +90,9 @@ describe('Angular Timer E2E Tests', function () {
9090

9191
it('Clock Timer - with hours, minutes & seconds', function () {
9292
sleep(3);
93-
expect(element('#clock-timer timer').html()).toMatch(/0 hours,/);
94-
expect(element('#clock-timer timer').html()).toMatch(/0 minutes,/);
95-
expect(element('#clock-timer timer').html()).not().toMatch(/0 seconds./);
93+
expect(element('#clock-timer timer').text()).toMatch(/0 hour/);
94+
expect(element('#clock-timer timer').text()).toMatch(/0 minute/);
95+
expect(element('#clock-timer timer').text()).toMatch(/3 seconds./); //because of sleep(3);
9696
});
9797

9898
it('Countdown Timer - Starts from 100', function () {
@@ -124,59 +124,65 @@ describe('Angular Timer E2E Tests', function () {
124124
expect(element('#plural-unit-timer .singular-counter timer').html()).toMatch(/1 day,/);
125125
expect(element('#plural-unit-timer .singular-counter timer').html()).toMatch(/1 hour,/);
126126
expect(element('#plural-unit-timer .singular-counter timer').html()).toMatch(/1 minute,/);
127-
expect(element('#plural-unit-timer .singular-counter timer').html()).toMatch(/1 second/);
128-
127+
expect(element('#plural-unit-timer .singular-counter timer').html()).toMatch(/1 second/);
128+
129129
expect(element('#plural-unit-timer .plural-counter timer').html()).toMatch(/days,/);
130130
expect(element('#plural-unit-timer .plural-counter timer').html()).toMatch(/hours,/);
131131
expect(element('#plural-unit-timer .plural-counter timer').html()).toMatch(/minutes,/);
132-
expect(element('#plural-unit-timer .plural-counter timer').html()).toMatch(/seconds/);
133-
});
134-
135-
// Commenting to see if build pass
136-
// it('Leading zero timer - should add a leading zero if number is smaller than 10', function() {
137-
// sleep(1);
138-
// expect(element('#clock-timer-leading-zero timer').html()).toMatch(/00 hours,/);
139-
// expect(element('#clock-timer-leading-zero timer').html()).toMatch(/00 minutes,/);
140-
// expect(element('#clock-timer-leading-zero timer').html()).toMatch(/01 seconds./);
141-
// sleep(10);
142-
// expect(element('#clock-timer-leading-zero timer').html()).toMatch(/00 hours,/);
143-
// expect(element('#clock-timer-leading-zero timer').html()).toMatch(/00 minutes,/);
144-
// expect(element('#clock-timer-leading-zero timer').html()).toMatch(/11 seconds./);
145-
// });
146-
132+
expect(element('#plural-unit-timer .plural-counter timer').html()).toMatch(/seconds/);
133+
});
134+
135+
it('Leading zero timer - should add a leading zero if number is smaller than 10', function() {
136+
sleep(1);
137+
expect(element('#clock-timer-leading-zero timer').text()).toMatch(/00 hour,/);
138+
expect(element('#clock-timer-leading-zero timer').text()).toMatch(/00 minute,/);
139+
expect(element('#clock-timer-leading-zero timer').text()).toMatch(/01 second/);
140+
sleep(10);
141+
expect(element('#clock-timer-leading-zero timer').text()).toMatch(/00 hour,/);
142+
expect(element('#clock-timer-leading-zero timer').text()).toMatch(/00 minute,/);
143+
expect(element('#clock-timer-leading-zero timer').text()).toMatch(/11 seconds/);
144+
});
145+
147146
it('Countdown finish - Should fire callback on completion', function () {
148-
149-
150147
expect(element('#finish-callback-timer .timer-status').html()).toBe('Running');
151148
expect(element('#finish-callback-timer .timer-callbacks').html()).toBe('0');
152-
149+
153150
sleep(5);
154-
expect(element('#finish-callback-timer .timer-status').html()).toBe('COMPLETE!!');
155-
expect(element('#finish-callback-timer .timer-callbacks').html()).toBe('1');
156-
157-
});
151+
expect(element('#finish-callback-timer .timer-status').html()).toBe('COMPLETE!!');
152+
expect(element('#finish-callback-timer .timer-callbacks').html()).toBe('1');
153+
154+
});
158155

159156
it('Start time with auto start', function() {
160157
expect(element('#start-time-and-auto-start-set timer span').html()).toBeGreaterThan(1000);
161158
});
162159

163160
it('Countdown timer with maxTimeUnit- should display time value from lower to specified maxTimeUnit', function() {
164161
var timer1Val = element('#max-time-unit-countdown-timer .WithMaxTimeUnitAsMinute timer').text();
165-
166-
expect({'timerText': timer1Val, 'unit': 'minutes', 'compareTo': 'GreaterThan'}).toCompareWith(59);
167-
expect({'timerText': timer1Val, 'unit': 'seconds', 'compareTo': 'LessThan'}).toCompareWith(60);
162+
expect(timer1Val).toMatch(/minutes/);
163+
expect(timer1Val).toMatch(/167/);
164+
expect(timer1Val).toMatch(/seconds/);
165+
expect(timer1Val).toMatch(/21/);
168166

169167
var timer2Val = element('#max-time-unit-countdown-timer .WithMaxTimeUnitAsSecond timer').text();
170-
expect({'timerText': timer2Val, 'unit': 'minutes', 'compareTo': 'EqualTo'}).toCompareWith(0);
171-
expect({'timerText': timer2Val, 'unit': 'seconds', 'compareTo': 'GreaterThan'}).toCompareWith(59);
168+
expect(timer2Val).toMatch(/minute/);
169+
expect(timer2Val).toMatch(/0/);
170+
expect(timer2Val).toMatch(/seconds/);
171+
expect(timer2Val).toMatch(/10041/);
172172

173173
var timer3Val = element('#max-time-unit-countdown-timer .WithMaxTimeUnitAsYear timer').text();
174-
expect({'timerText': timer3Val, 'unit': 'seconds', 'compareTo': 'LessThan'}).toCompareWith(60);
175-
expect({'timerText': timer3Val, 'unit': 'minutes', 'compareTo': 'LessThan'}).toCompareWith(60);
176-
expect({'timerText': timer3Val, 'unit': 'hours', 'compareTo': 'LessThan'}).toCompareWith(24);
177-
expect({'timerText': timer3Val, 'unit': 'days', 'compareTo': 'LessThan'}).toCompareWith(30);
178-
expect({'timerText': timer3Val, 'unit': 'months', 'compareTo': 'LessThan'}).toCompareWith(12);
179-
174+
expect(timer3Val).toMatch(/years/);
175+
expect(timer3Val).toMatch(/03/);
176+
expect(timer3Val).toMatch(/months/);
177+
expect(timer3Val).toMatch(/02/);
178+
expect(timer3Val).toMatch(/days/);
179+
expect(timer3Val).toMatch(/22/);
180+
expect(timer3Val).toMatch(/hours/);
181+
expect(timer3Val).toMatch(/03/);
182+
expect(timer3Val).toMatch(/minute/);
183+
expect(timer3Val).toMatch(/40/);
184+
expect(timer3Val).toMatch(/second/);
185+
expect(timer3Val).toMatch(/00/);
180186
});
181187

182188
});

0 commit comments

Comments
 (0)