Skip to content

Commit

Permalink
Merged singular / plural change with master.
Browse files Browse the repository at this point in the history
  • Loading branch information
itslenny committed Mar 18, 2014
2 parents 2cce636 + 9a67d66 commit 2d4843e
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 25 deletions.
27 changes: 17 additions & 10 deletions app/js/timer.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
angular.module('timer', [])
.directive('timer', ['$compile', function ($compile) {
return {
restrict: 'E',
restrict: 'EAC',
replace: false,
scope: {
interval: '=interval',
Expand Down Expand Up @@ -95,16 +95,23 @@ angular.module('timer', [])
});

function calculateTimeUnits() {
$scope.seconds = Math.floor(($scope.millis / 1000) % 60);
$scope.secondsS = $scope.seconds==1 ? '' : 's';
$scope.minutes = Math.floor((($scope.millis / (60000)) % 60));
$scope.minutesS = $scope.minutes==1 ? '' : 's';
$scope.hours = Math.floor((($scope.millis / (3600000)) % 24));
$scope.hoursS = $scope.hours==1 ? '' : 's';
$scope.days = Math.floor((($scope.millis / (3600000)) / 24));
$scope.daysS = $scope.days==1 ? '' : 's';
}

$scope.seconds = Math.floor(($scope.millis / 1000) % 60);
$scope.secondsS = $scope.seconds==1 ? '' : 's';
$scope.minutes = Math.floor((($scope.millis / (60000)) % 60));
$scope.minutesS = $scope.minutes==1 ? '' : 's';
$scope.hours = Math.floor((($scope.millis / (3600000)) % 24));
$scope.hoursS = $scope.hours==1 ? '' : 's';
$scope.days = Math.floor((($scope.millis / (3600000)) / 24));
$scope.daysS = $scope.days==1 ? '' : 's';

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

}
//determine initial values of time units and add AddSeconds functionality
if ($scope.countdownattr) {
$scope.millis = $scope.countdownattr * 1000;
Expand Down
31 changes: 20 additions & 11 deletions dist/angular-timer.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* angular-timer - v1.0.12 - 2014-02-10 9:05 AM
* angular-timer - v1.0.12 - 2014-03-18 4:02 PM
* https://github.com/siddii/angular-timer
*
* Copyright (c) 2014 Siddique Hameed
Expand All @@ -8,7 +8,7 @@
angular.module('timer', [])
.directive('timer', ['$compile', function ($compile) {
return {
restrict: 'E',
restrict: 'EAC',
replace: false,
scope: {
interval: '=interval',
Expand Down Expand Up @@ -102,16 +102,25 @@ angular.module('timer', [])
});

function calculateTimeUnits() {
$scope.seconds = Math.floor(($scope.millis / 1000) % 60);
$scope.secondsS = $scope.seconds==1 ? '' : 's';
$scope.minutes = Math.floor((($scope.millis / (60000)) % 60));
$scope.minutesS = $scope.minutes==1 ? '' : 's';
$scope.hours = Math.floor((($scope.millis / (3600000)) % 24));
$scope.hoursS = $scope.hours==1 ? '' : 's';
$scope.days = Math.floor((($scope.millis / (3600000)) / 24));
$scope.daysS = $scope.days==1 ? '' : 's';
}

$scope.seconds = Math.floor(($scope.millis / 1000) % 60);
$scope.secondsS = $scope.seconds==1 ? '' : 's';
$scope.minutes = Math.floor((($scope.millis / (60000)) % 60));
$scope.minutesS = $scope.minutes==1 ? '' : 's';
$scope.hours = Math.floor((($scope.millis / (3600000)) % 24));
$scope.hoursS = $scope.hours==1 ? '' : 's';
$scope.days = Math.floor((($scope.millis / (3600000)) / 24));
$scope.daysS = $scope.days==1 ? '' : 's';


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


}
//determine initial values of time units and add AddSeconds functionality
if ($scope.countdownattr) {
$scope.millis = $scope.countdownattr * 1000;
Expand Down
4 changes: 2 additions & 2 deletions dist/angular-timer.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 16 additions & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<script src="bower_components/jquery/jquery.min.js"></script>
<script src="bower_components/angular/angular.min.js"></script>
<script src="bower_components/bootstrap/docs/assets/js/bootstrap.min.js"></script>
<script src="dist/angular-timer.min.js"></script>
<script src="app/js/timer.js"></script>
<script src="docs/docs.js"></script>
</head>
<body ng-app="timer-demo" ng-controller="TimerDemoController">
Expand Down Expand Up @@ -64,6 +64,21 @@ <h3>
<button class="btn" onclick="stopResumeTimer('clock-timer', this)" type="button">Stop</button>
</div>
</section>
<section id="clock-timer-leading-zero">
<h3>
Timer with leading zero</h3>

<div class="bs-docs-example">
<p>
This markup <code ng-non-bindable="">&lt;timer interval=&quot;1000&quot;&gt;{{hhours}} hours, {{mminutes}}
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>

<h3>
<timer interval="1000">{{hhours}} hours, {{mminutes}} minutes, {{sseconds}} seconds.</timer>
</h3>
<button class="btn" onclick="stopResumeTimer('clock-timer', this)" type="button">Stop</button>
</div>
</section>
<section id="timer-with-start-time">
<h3>
Timer initialised with some predefined start time.</h3>
Expand Down
14 changes: 13 additions & 1 deletion test/e2e/scenarios.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ describe('Angular Timer E2E Tests', function () {
}
});


it("Simple Timer - Should stop ticking when user clicks 'Stop' button", function () {
sleep(1);
element('#basic-timer button:last-child').click();
Expand Down Expand Up @@ -85,7 +86,7 @@ describe('Angular Timer E2E Tests', function () {
var afterTime = element('#timer-with-end-time timer span').html();
expect(beforeTime).toHaveMoreSecondsThan(afterTime);
});

it('Plural / Singular Units - Should properly pluralize units', function () {
expect(element('#plural-unit-timer .singular-counter timer').html()).toMatch(/1 day,/);
expect(element('#plural-unit-timer .singular-counter timer').html()).toMatch(/1 hour,/);
Expand All @@ -98,4 +99,15 @@ describe('Angular Timer E2E Tests', function () {
expect(element('#plural-unit-timer .plural-counter timer').html()).toMatch(/seconds/);
});

it('Leading zero timer - should add a leading zero if number is smaller than 10', function() {
sleep(1);
expect(element('#clock-timer-leading-zero timer').html()).toMatch(/00 hours,/);
expect(element('#clock-timer-leading-zero timer').html()).toMatch(/00 minutes,/);
expect(element('#clock-timer-leading-zero timer').html()).toMatch(/01 seconds./);
sleep(10);
expect(element('#clock-timer-leading-zero timer').html()).toMatch(/00 hours,/);
expect(element('#clock-timer-leading-zero timer').html()).toMatch(/00 minutes,/);
expect(element('#clock-timer-leading-zero timer').html()).toMatch(/11 seconds./);
});

});

0 comments on commit 2d4843e

Please sign in to comment.