(function () {
'use strict';
// Time from military
angular
.module('mohistory')
.filter('timeFromMilitary', timeFromMilitary);
timeFromMilitary.$inject = [];
/**
* Convert from military time to AM / PM times.
* Modified from:
* https://stackoverflow.com/questions/41390084/converting-specific-military-time-with-angular-and-javascript-filter#answer-41392703
* @memberof mohistory
* @name timeFromMilitary
* @ngdoc filter
*/
function timeFromMilitary() {
return function (input) {
var timeParts = input.split(":");
// Convert hours into ints so we can safely do math with it
var hours = +timeParts[0];
var minutes = timeParts[1];
// The `or` allows us to take advantage of the
// falseness of `0`, `0 % 12 = 0` and `12 % 12 = 0`
// in both cases we want the hour to be 0.
return (hours % 12 || 12) + ':' + minutes + (hours < 11 ? 'am' : 'pm');
}
}
})();