Last active
January 5, 2018 10:52
-
-
Save lkatney/fb0d73122b3cbc950131b1a3415aff5a to your computer and use it in GitHub Desktop.
custom asynchronous filter to format date into appropriate format
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function() { | |
'use strict'; | |
angular | |
.module('app.directives') | |
/** | |
* @ngdoc filter | |
* @name filter:formattedDate | |
* @description | |
* filter to return in formatted time format | |
* @function | |
* @requires $translate | |
* @requires dateFilter | |
*/ | |
.filter('formattedDate', function(dateFilter, $translate) { | |
var format = null, translated = false; | |
function returnFilter(inputDate) { | |
if(format){ | |
return dateFilter(inputDate, format); | |
}else{ | |
return '-'; | |
} | |
} | |
function formattedDateFilter(inputDate){ | |
if( format === null ) { | |
if( !translated ){ | |
translated = true; | |
// it is GENERAL.TIME_FORMAT is coming from one of translations | |
// It can have format as dd/MM/yyyy HH:mm for english | |
//or any other format for any other language | |
$translate('GENERAL.TIME_FORMAT').then(function (result) { | |
format = result; | |
},function (translationId) { | |
format = translationId; | |
}); | |
} | |
} | |
else return returnFilter(inputDate); | |
} | |
formattedDateFilter.$stateful = true; | |
return formattedDateFilter; | |
}); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment