"use strict"; /** * Created by mkumar1 on 02-11-2017. */ (function () { 'use strict'; angular.module('myitsmApp') .directive('timeTicker', ['$timeout', 'configurationModel', '$filter', function ($timeout, configurationModel, $filter) { return { scope: { time: '=', refreshInterval: '=' }, link: function (scope, element, attrs) { var timeoutId, time = scope.time, intervalLength = scope.refreshInterval, timeFormat = (configurationModel.dateTimeStyleProperty) ? configurationModel.dateTimeStyleProperty : 'relative'; function updateTime() { if (time) { element.text(moment(Number(time)).fromNow()); } } function updateLater() { if (timeoutId) { $timeout.cancel(timeoutId); } timeoutId = $timeout(function () { updateTime(); updateLater(); }, intervalLength); } scope.$watch('time', function (newTime) { time = newTime; if (timeFormat === 'relative') { updateTime(); updateLater(); } else { element.text($filter('datePreConfigTimezone')(time, 'mediumDate') + ' ' + $filter('datePreConfigTimezone')(time, 'shortTime')); } }); } }; }]); }());