1
0
mirror of https://github.com/moparisthebest/mail synced 2024-11-25 18:32:20 -05:00

Merge pull request #209 from whiteout-io/dev/WO-776

Show time of day instead of date for today in mail-list
This commit is contained in:
Tankred Hase 2014-12-01 10:09:49 +01:00
commit 9bee0f3def
3 changed files with 31 additions and 2 deletions

View File

@ -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
//

View File

@ -61,7 +61,7 @@
<div class="mail-list-entry__attachment">
<svg><use xlink:href="#icon-attachment" /><title>Attachments</title></svg>
</div>
<time class="mail-list-entry__time">{{email.sentDate | date:'mediumDate'}}</time>
<time class="mail-list-entry__time">{{ formatDate(email.sentDate) }}</time>
<div class="mail-list-entry__excerpt">{{email.body ? email.body.substr(0, 200) : ''}}</div>
<div class="mail-list-entry__encrypted">
<svg ng-show="email.encrypted"><use xlink:href="#icon-encrypted" /><title>Encrypted</title></svg>

View File

@ -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);
}));
});
});