Skip to content

Commit 9a67d66

Browse files
committed
Merge pull request siddii#56 from WanjaStier/master
Added e2e test for leading zero
2 parents a4fbd4d + d227f8e commit 9a67d66

File tree

5 files changed

+56
-16
lines changed

5 files changed

+56
-16
lines changed

app/js/timer.js

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
angular.module('timer', [])
22
.directive('timer', ['$compile', function ($compile) {
33
return {
4-
restrict: 'E',
4+
restrict: 'EAC',
55
replace: false,
66
scope: {
77
interval: '=interval',
@@ -95,12 +95,18 @@ angular.module('timer', [])
9595
});
9696

9797
function calculateTimeUnits() {
98-
$scope.seconds = Math.floor(($scope.millis / 1000) % 60);
99-
$scope.minutes = Math.floor((($scope.millis / (60000)) % 60));
100-
$scope.hours = Math.floor((($scope.millis / (3600000)) % 24));
101-
$scope.days = Math.floor((($scope.millis / (3600000)) / 24));
102-
}
98+
$scope.seconds = Math.floor(($scope.millis / 1000) % 60);
99+
$scope.minutes = Math.floor((($scope.millis / (60000)) % 60));
100+
$scope.hours = Math.floor((($scope.millis / (3600000)) % 24));
101+
$scope.days = Math.floor((($scope.millis / (3600000)) / 24));
102+
103+
//add leading zero if number is smaller than 10
104+
$scope.sseconds = $scope.seconds < 10 ? '0' + $scope.seconds : $scope.seconds;
105+
$scope.mminutes = $scope.minutes < 10 ? '0' + $scope.minutes : $scope.minutes;
106+
$scope.hhours = $scope.hours < 10 ? '0' + $scope.hours : $scope.hours;
107+
$scope.ddays = $scope.days < 10 ? '0' + $scope.days : $scope.days;
103108

109+
}
104110
//determine initial values of time units and add AddSeconds functionality
105111
if ($scope.countdownattr) {
106112
$scope.millis = $scope.countdownattr * 1000;

dist/angular-timer.js

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* angular-timer - v1.0.12 - 2014-02-10 9:05 AM
2+
* angular-timer - v1.0.12 - 2014-03-18 4:02 PM
33
* https://github.com/siddii/angular-timer
44
*
55
* Copyright (c) 2014 Siddique Hameed
@@ -8,7 +8,7 @@
88
angular.module('timer', [])
99
.directive('timer', ['$compile', function ($compile) {
1010
return {
11-
restrict: 'E',
11+
restrict: 'EAC',
1212
replace: false,
1313
scope: {
1414
interval: '=interval',
@@ -102,12 +102,18 @@ angular.module('timer', [])
102102
});
103103

104104
function calculateTimeUnits() {
105-
$scope.seconds = Math.floor(($scope.millis / 1000) % 60);
106-
$scope.minutes = Math.floor((($scope.millis / (60000)) % 60));
107-
$scope.hours = Math.floor((($scope.millis / (3600000)) % 24));
108-
$scope.days = Math.floor((($scope.millis / (3600000)) / 24));
109-
}
105+
$scope.seconds = Math.floor(($scope.millis / 1000) % 60);
106+
$scope.minutes = Math.floor((($scope.millis / (60000)) % 60));
107+
$scope.hours = Math.floor((($scope.millis / (3600000)) % 24));
108+
$scope.days = Math.floor((($scope.millis / (3600000)) / 24));
109+
110+
//add leading zero if number is smaller than 10
111+
$scope.sseconds = $scope.seconds < 10 ? '0' + $scope.seconds : $scope.seconds;
112+
$scope.mminutes = $scope.minutes < 10 ? '0' + $scope.minutes : $scope.minutes;
113+
$scope.hhours = $scope.hours < 10 ? '0' + $scope.hours : $scope.hours;
114+
$scope.ddays = $scope.days < 10 ? '0' + $scope.days : $scope.days;
110115

116+
}
111117
//determine initial values of time units and add AddSeconds functionality
112118
if ($scope.countdownattr) {
113119
$scope.millis = $scope.countdownattr * 1000;

dist/angular-timer.min.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

index.html

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
<script src="bower_components/jquery/jquery.min.js"></script>
1212
<script src="bower_components/angular/angular.min.js"></script>
1313
<script src="bower_components/bootstrap/docs/assets/js/bootstrap.min.js"></script>
14-
<script src="dist/angular-timer.min.js"></script>
14+
<script src="app/js/timer.js"></script>
1515
<script src="docs/docs.js"></script>
1616
</head>
1717
<body ng-app="timer-demo" ng-controller="TimerDemoController">
@@ -64,6 +64,21 @@ <h3>
6464
<button class="btn" onclick="stopResumeTimer('clock-timer', this)" type="button">Stop</button>
6565
</div>
6666
</section>
67+
<section id="clock-timer-leading-zero">
68+
<h3>
69+
Timer with leading zero</h3>
70+
71+
<div class="bs-docs-example">
72+
<p>
73+
This markup <code ng-non-bindable="">&lt;timer interval=&quot;1000&quot;&gt;{{hhours}} hours, {{mminutes}}
74+
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>
75+
76+
<h3>
77+
<timer interval="1000">{{hhours}} hours, {{mminutes}} minutes, {{sseconds}} seconds.</timer>
78+
</h3>
79+
<button class="btn" onclick="stopResumeTimer('clock-timer', this)" type="button">Stop</button>
80+
</div>
81+
</section>
6782
<section id="timer-with-start-time">
6883
<h3>
6984
Timer initialised with some predefined start time.</h3>

test/e2e/scenarios.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ describe('Angular Timer E2E Tests', function () {
3232
}
3333
});
3434

35+
3536
it("Simple Timer - Should stop ticking when user clicks 'Stop' button", function () {
3637
sleep(1);
3738
element('#basic-timer button:last-child').click();
@@ -85,4 +86,16 @@ describe('Angular Timer E2E Tests', function () {
8586
var afterTime = element('#timer-with-end-time timer span').html();
8687
expect(beforeTime).toHaveMoreSecondsThan(afterTime);
8788
});
89+
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+
});
100+
88101
});

0 commit comments

Comments
 (0)