From 06ccab6b88601d50940241b496cd674cbe7b8cef Mon Sep 17 00:00:00 2001 From: Robbie Mackay Date: Wed, 2 Nov 2016 16:52:55 +1300 Subject: [PATCH] Format value for post datetime fields nicely --- app/main/posts/detail/post-value.directive.js | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/app/main/posts/detail/post-value.directive.js b/app/main/posts/detail/post-value.directive.js index 7bdb875317..9e81a61596 100644 --- a/app/main/posts/detail/post-value.directive.js +++ b/app/main/posts/detail/post-value.directive.js @@ -1,4 +1,4 @@ -module.exports = ['PostEndpoint', function (PostEndpoint) { +module.exports = ['PostEndpoint', 'moment', function (PostEndpoint, moment) { return { restrict: 'E', replace: true, @@ -18,6 +18,21 @@ module.exports = ['PostEndpoint', function (PostEndpoint) { return PostEndpoint.get({ id : entry }); }); } + if ($scope.attribute.type === 'datetime' && $scope.attribute.input === 'date') { + $scope.value = $scope.value.map(function (entry) { + return moment(entry).format('LL'); + }); + } + if ($scope.attribute.type === 'datetime' && $scope.attribute.input === 'datetime') { + $scope.value = $scope.value.map(function (entry) { + return moment(entry).format('LLL'); + }); + } + if ($scope.attribute.type === 'datetime' && $scope.attribute.input === 'time') { + $scope.value = $scope.value.map(function (entry) { + return moment(entry).format('LT'); + }); + } } }; }];