Skip to content

Commit 29d34d3

Browse files
committed
Merge branch 'meedi-master'
2 parents 6d59153 + f67f667 commit 29d34d3

File tree

5 files changed

+70
-8
lines changed

5 files changed

+70
-8
lines changed

app/js/timer.js

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,38 +107,64 @@ angular.module('timer', [])
107107
function calculateTimeUnits() {
108108

109109
// compute time values based on maxTimeUnit specification
110-
if(!$scope.maxTimeUnit) {
110+
if(!$scope.maxTimeUnit || $scope.maxTimeUnit === 'day') {
111111
$scope.seconds = Math.floor(($scope.millis / 1000) % 60);
112112
$scope.minutes = Math.floor((($scope.millis / (60000)) % 60));
113113
$scope.hours = Math.floor((($scope.millis / (3600000)) % 24));
114-
$scope.days = Math.floor((($scope.millis / (3600000)) / 24));
114+
$scope.days = Math.floor((($scope.millis / (3600000)) / 24));
115+
$scope.months = 0;
116+
$scope.years = 0;
115117
} else if($scope.maxTimeUnit === 'second') {
116118
$scope.seconds = Math.floor($scope.millis / 1000);
117119
$scope.minutes = 0;
118120
$scope.hours = 0;
119121
$scope.days = 0;
122+
$scope.months = 0;
123+
$scope.years = 0;
120124
} else if($scope.maxTimeUnit === 'minute') {
121125
$scope.seconds = Math.floor(($scope.millis / 1000) % 60);
122126
$scope.minutes = Math.floor($scope.millis / 60000);
123127
$scope.hours = 0;
124128
$scope.days = 0;
129+
$scope.months = 0;
130+
$scope.years = 0;
125131
} else if($scope.maxTimeUnit === 'hour') {
126132
$scope.seconds = Math.floor(($scope.millis / 1000) % 60);
127133
$scope.minutes = Math.floor((($scope.millis / (60000)) % 60));
128134
$scope.hours = Math.floor($scope.millis / 3600000);
129135
$scope.days = 0;
136+
$scope.months = 0;
137+
$scope.years = 0;
138+
} else if($scope.maxTimeUnit === 'month') {
139+
$scope.seconds = Math.floor(($scope.millis / 1000) % 60);
140+
$scope.minutes = Math.floor((($scope.millis / (60000)) % 60));
141+
$scope.hours = Math.floor((($scope.millis / (3600000)) % 24));
142+
$scope.days = Math.floor((($scope.millis / (3600000)) / 24) % 30);
143+
$scope.months = Math.floor((($scope.millis / (3600000)) / 24) / 30);
144+
$scope.years = 0;
145+
} else if($scope.maxTimeUnit === 'year') {
146+
$scope.seconds = Math.floor(($scope.millis / 1000) % 60);
147+
$scope.minutes = Math.floor((($scope.millis / (60000)) % 60));
148+
$scope.hours = Math.floor((($scope.millis / (3600000)) % 24));
149+
$scope.days = Math.floor((($scope.millis / (3600000)) / 24) % 30);
150+
$scope.months = Math.floor((($scope.millis / (3600000)) / 24 / 30) % 12);
151+
$scope.years = Math.floor(($scope.millis / (3600000)) / 24 / 365);
130152
}
131153

132154
// plural - singular unit decision
133155
$scope.secondsS = $scope.seconds==1 ? '' : 's';
134156
$scope.minutesS = $scope.minutes==1 ? '' : 's';
135157
$scope.hoursS = $scope.hours==1 ? '' : 's';
136158
$scope.daysS = $scope.days==1 ? '' : 's';
159+
$scope.monthsS = $scope.months==1 ? '' : 's';
160+
$scope.yearsS = $scope.years==1 ? '' : 's';
137161
//add leading zero if number is smaller than 10
138162
$scope.sseconds = $scope.seconds < 10 ? '0' + $scope.seconds : $scope.seconds;
139163
$scope.mminutes = $scope.minutes < 10 ? '0' + $scope.minutes : $scope.minutes;
140164
$scope.hhours = $scope.hours < 10 ? '0' + $scope.hours : $scope.hours;
141165
$scope.ddays = $scope.days < 10 ? '0' + $scope.days : $scope.days;
166+
$scope.mmonths = $scope.months < 10 ? '0' + $scope.months : $scope.months;
167+
$scope.yyears = $scope.years < 10 ? '0' + $scope.years : $scope.years;
142168

143169
}
144170
//determine initial values of time units and add AddSeconds functionality

dist/angular-timer.js

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* angular-timer - v1.1.1 - 2014-05-16 7:26 PM
2+
* angular-timer - v1.1.1 - 2014-05-17 3:54 AM
33
* https://github.com/siddii/angular-timer
44
*
55
* Copyright (c) 2014 Siddique Hameed
@@ -114,38 +114,64 @@ angular.module('timer', [])
114114
function calculateTimeUnits() {
115115

116116
// compute time values based on maxTimeUnit specification
117-
if(!$scope.maxTimeUnit) {
117+
if(!$scope.maxTimeUnit || $scope.maxTimeUnit === 'day') {
118118
$scope.seconds = Math.floor(($scope.millis / 1000) % 60);
119119
$scope.minutes = Math.floor((($scope.millis / (60000)) % 60));
120120
$scope.hours = Math.floor((($scope.millis / (3600000)) % 24));
121-
$scope.days = Math.floor((($scope.millis / (3600000)) / 24));
121+
$scope.days = Math.floor((($scope.millis / (3600000)) / 24));
122+
$scope.months = 0;
123+
$scope.years = 0;
122124
} else if($scope.maxTimeUnit === 'second') {
123125
$scope.seconds = Math.floor($scope.millis / 1000);
124126
$scope.minutes = 0;
125127
$scope.hours = 0;
126128
$scope.days = 0;
129+
$scope.months = 0;
130+
$scope.years = 0;
127131
} else if($scope.maxTimeUnit === 'minute') {
128132
$scope.seconds = Math.floor(($scope.millis / 1000) % 60);
129133
$scope.minutes = Math.floor($scope.millis / 60000);
130134
$scope.hours = 0;
131135
$scope.days = 0;
136+
$scope.months = 0;
137+
$scope.years = 0;
132138
} else if($scope.maxTimeUnit === 'hour') {
133139
$scope.seconds = Math.floor(($scope.millis / 1000) % 60);
134140
$scope.minutes = Math.floor((($scope.millis / (60000)) % 60));
135141
$scope.hours = Math.floor($scope.millis / 3600000);
136142
$scope.days = 0;
143+
$scope.months = 0;
144+
$scope.years = 0;
145+
} else if($scope.maxTimeUnit === 'month') {
146+
$scope.seconds = Math.floor(($scope.millis / 1000) % 60);
147+
$scope.minutes = Math.floor((($scope.millis / (60000)) % 60));
148+
$scope.hours = Math.floor((($scope.millis / (3600000)) % 24));
149+
$scope.days = Math.floor((($scope.millis / (3600000)) / 24) % 30);
150+
$scope.months = Math.floor((($scope.millis / (3600000)) / 24) / 30);
151+
$scope.years = 0;
152+
} else if($scope.maxTimeUnit === 'year') {
153+
$scope.seconds = Math.floor(($scope.millis / 1000) % 60);
154+
$scope.minutes = Math.floor((($scope.millis / (60000)) % 60));
155+
$scope.hours = Math.floor((($scope.millis / (3600000)) % 24));
156+
$scope.days = Math.floor((($scope.millis / (3600000)) / 24) % 30);
157+
$scope.months = Math.floor((($scope.millis / (3600000)) / 24 / 30) % 12);
158+
$scope.years = Math.floor(($scope.millis / (3600000)) / 24 / 365);
137159
}
138160

139161
// plural - singular unit decision
140162
$scope.secondsS = $scope.seconds==1 ? '' : 's';
141163
$scope.minutesS = $scope.minutes==1 ? '' : 's';
142164
$scope.hoursS = $scope.hours==1 ? '' : 's';
143165
$scope.daysS = $scope.days==1 ? '' : 's';
166+
$scope.monthsS = $scope.months==1 ? '' : 's';
167+
$scope.yearsS = $scope.years==1 ? '' : 's';
144168
//add leading zero if number is smaller than 10
145169
$scope.sseconds = $scope.seconds < 10 ? '0' + $scope.seconds : $scope.seconds;
146170
$scope.mminutes = $scope.minutes < 10 ? '0' + $scope.minutes : $scope.minutes;
147171
$scope.hhours = $scope.hours < 10 ? '0' + $scope.hours : $scope.hours;
148172
$scope.ddays = $scope.days < 10 ? '0' + $scope.days : $scope.days;
173+
$scope.mmonths = $scope.months < 10 ? '0' + $scope.months : $scope.months;
174+
$scope.yyears = $scope.years < 10 ? '0' + $scope.years : $scope.years;
149175

150176
}
151177
//determine initial values of time units and add AddSeconds functionality

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: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,10 @@ <h3>countdown Time Display according to specified max Time Unit</h3>
193193
&lt;timer countdown="10041" max-time-unit="'minute'" interval="1000"&gt;{{mminutes}} minute{{minutesS}}, {{sseconds}} second{{secondsS}}&lt;/timer&gt;
194194
</code>
195195
</p>
196-
196+
<p class="muted">countdown Time with max time unit option - year</p>
197+
<h3 class="WithMaxTimeUnitAsYear">
198+
<timer countdown="100410000" max-time-unit="'year'" interval="1000">{{yyears}} year{{yearsS}}, {{mmonths}} month{{monthsS}}, {{ddays}} day{{daysS}}, {{hhours}} hour{{hoursS}}, {{mminutes}} minute{{minutesS}}, {{sseconds}} second{{secondsS}}</timer>
199+
</h3>
197200
<p class="muted">countdown Time with max time unit option - minute</p>
198201
<h3 class="WithMaxTimeUnitAsMinute">
199202
<timer countdown="10041" max-time-unit="'minute'" interval="1000"> {{mminutes}} minute{{minutesS}}, {{sseconds}} second{{secondsS}}</timer>

test/e2e/scenarios.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,13 @@ describe('Angular Timer E2E Tests', function () {
153153
expect({'timerText': timer2Val, 'unit': 'minutes', 'compareTo': 'EqualTo'}).toCompareWith(0);
154154
expect({'timerText': timer2Val, 'unit': 'seconds', 'compareTo': 'GreaterThan'}).toCompareWith(59);
155155

156+
var timer3Val = element('#max-time-unit-countdown-timer .WithMaxTimeUnitAsYear timer').text();
157+
expect({'timerText': timer3Val, 'unit': 'seconds', 'compareTo': 'LessThan'}).toCompareWith(60);
158+
expect({'timerText': timer3Val, 'unit': 'minutes', 'compareTo': 'LessThan'}).toCompareWith(60);
159+
expect({'timerText': timer3Val, 'unit': 'hours', 'compareTo': 'LessThan'}).toCompareWith(24);
160+
expect({'timerText': timer3Val, 'unit': 'days', 'compareTo': 'LessThan'}).toCompareWith(30);
161+
expect({'timerText': timer3Val, 'unit': 'months', 'compareTo': 'LessThan'}).toCompareWith(12);
162+
156163
});
157164

158165
});

0 commit comments

Comments
 (0)