Skip to content

Commit a5b1006

Browse files
Start time and autostart working togheter now
1 parent 1e52ca5 commit a5b1006

File tree

4 files changed

+33
-2
lines changed

4 files changed

+33
-2
lines changed

app/js/timer.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,9 @@ var timerModule = angular.module('timer', [])
106106
});
107107

108108
function calculateTimeUnits() {
109-
109+
if ($attrs.startTime !== undefined){
110+
$scope.millis = new Date() - new Date($scope.startTimeAttr);
111+
}
110112
// compute time values based on maxTimeUnit specification
111113
if (!$scope.maxTimeUnit || $scope.maxTimeUnit === 'day') {
112114
$scope.seconds = Math.floor(($scope.millis / 1000) % 60);
@@ -151,7 +153,6 @@ var timerModule = angular.module('timer', [])
151153
$scope.months = Math.floor((($scope.millis / (3600000)) / 24 / 30) % 12);
152154
$scope.years = Math.floor(($scope.millis / (3600000)) / 24 / 365);
153155
}
154-
155156
// plural - singular unit decision
156157
$scope.secondsS = $scope.seconds == 1 ? '' : 's';
157158
$scope.minutesS = $scope.minutes == 1 ? '' : 's';
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<title>Start Time and Auto Start set - Timer Example</title>
5+
<script src="../bower_components/angular/angular.min.js"></script>
6+
<script src="../app/js/timer.js"></script>
7+
</head>
8+
<body ng-app="timer">
9+
<div id="start-time-and-auto-start-set">
10+
<h2>Start Time and Auto Start set - Timer Example</h2>
11+
<h3><timer start-time="1410914940000" autostart="false"></timer></h3>
12+
</div>
13+
<br/>
14+
</body>
15+
</html>

index.html

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,17 @@ <h3>
4949
<button class="btn" onclick="stopTimer('basic-timer')" type="button">Stop</button>
5050
</div>
5151
</section>
52+
<section id="start-time-and-auto-start-set">
53+
<h3>Timer with start time and auto start set</h3>
54+
55+
<div class="bs-docs-example">
56+
<p>This will start a timer with 1410914940000 milliseconds and stopped</p>
57+
58+
<h3>
59+
<timer start-time="1410914940000" autostart="false"></timer>
60+
</h3>
61+
</div>
62+
</section>
5263
<section id="clock-timer">
5364
<h3>
5465
Timer with hours, minutes &amp; seconds</h3>

test/e2e/scenarios.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,10 @@ describe('Angular Timer E2E Tests', function () {
155155

156156
});
157157

158+
it('Start time with auto start', function() {
159+
expect(element('#start-time-and-auto-start-set timer span').html()).toBeGreaterThan(1000);
160+
});
161+
158162
it('Countdown timer with maxTimeUnit- should display time value from lower to specified maxTimeUnit', function() {
159163
var timer1Val = element('#max-time-unit-countdown-timer .WithMaxTimeUnitAsMinute timer').text();
160164

0 commit comments

Comments
 (0)