diff --git a/src/js/controller/app/mail-list.js b/src/js/controller/app/mail-list.js index 3e142eb..562ee38 100644 --- a/src/js/controller/app/mail-list.js +++ b/src/js/controller/app/mail-list.js @@ -11,7 +11,7 @@ var INIT_DISPLAY_LEN = 20, FOLDER_TYPE_INBOX = 'Inbox', NOTIFICATION_INBOX_TIMEOUT = 5000; -var MailListCtrl = function($scope, $timeout, $routeParams, statusDisplay, notification, email, keychain, dialog, search, dummy) { +var MailListCtrl = function($scope, $timeout, $routeParams, $filter, statusDisplay, notification, email, keychain, dialog, search, dummy) { // // Init @@ -98,6 +98,20 @@ var MailListCtrl = function($scope, $timeout, $routeParams, statusDisplay, notif } }; + /** + * Date formatting + */ + $scope.formatDate = function(date) { + var now = new Date(); + + // return time if mail is from today + if(now.getDay() === date.getDay() && now.getMonth() === date.getMonth() && now.getFullYear() === date.getFullYear()) { + return $filter('date')(date, 'shortTime'); + } + + return $filter('date')(date, 'mediumDate'); + }; + // // watch tasks // diff --git a/src/tpl/mail-list.html b/src/tpl/mail-list.html index e8df234..0fb3bd0 100644 --- a/src/tpl/mail-list.html +++ b/src/tpl/mail-list.html @@ -61,7 +61,7 @@
Attachments
- +
{{email.body ? email.body.substr(0, 200) : ''}}
Encrypted diff --git a/test/unit/controller/app/mail-list-ctrl-test.js b/test/unit/controller/app/mail-list-ctrl-test.js index bb113bb..bc62d43 100644 --- a/test/unit/controller/app/mail-list-ctrl-test.js +++ b/test/unit/controller/app/mail-list-ctrl-test.js @@ -324,4 +324,19 @@ describe('Mail List controller unit test', function() { expect(scope.state.mailList.selected).to.equal(mail); }); }); + + describe('formatDate', function() { + it('should output short time if date is today', angular.mock.inject(function($filter) { + var now = new Date(); + var expected = $filter('date')(now, 'shortTime'); + expect(scope.formatDate(now)).to.equal(expected); + })); + it('should output date only if date is not today', angular.mock.inject(function($filter) { + var yesterday = new Date(); + yesterday.setTime(yesterday.getTime() - 24*60*60*1000); + + var expected = $filter('date')(yesterday, 'mediumDate'); + expect(scope.formatDate(yesterday)).to.equal(expected); + })); + }); }); \ No newline at end of file