Skip to content

Instantly share code, notes, and snippets.

@jthmiranda
Created October 29, 2015 17:38
Show Gist options
  • Save jthmiranda/f4c1fff94627ca349e84 to your computer and use it in GitHub Desktop.
Save jthmiranda/f4c1fff94627ca349e84 to your computer and use it in GitHub Desktop.
filter interval of time angularJS 1
<div ng-app="APP" ng-controller="MainController">
<select>
<option ng-repeat="h_m in [] | time:8:20:15">{{h_m}}</option>
</select>
</div>
var app = angular.module('APP', ['APP.filters']);
app.controller('MainController', ['$scope', function($scope) {
}]);
angular.module('APP.filters', []).filter('time', function() {
return function(input, from, to, interval) {
from = parseInt(from, 10);
to = parseInt(to, 10);
interval = parseInt(interval, 10);
for(var i=from, y=0; i<=to; ++i, y+=interval) {
for(var y=0; y<60; y+=interval) {
input.push(((i % 12) || 12)+ ":" + (y===0?'00':y) +" " + (i>12?'pm':'am'));
}
}
return input;
};
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment