Skip to content
This repository has been archived by the owner on Nov 3, 2021. It is now read-only.

Commit

Permalink
Merge pull request #9808 from KevinGrandon/calendar_event_view_format…
Browse files Browse the repository at this point in the history
…ting

Bug 872922 - Localize dates/times on event view page r=lightsofapollo
  • Loading branch information
lightsofapollo committed May 16, 2013
2 parents 7c87f0b + ad50bf7 commit 8a49e2d
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 19 deletions.
8 changes: 4 additions & 4 deletions apps/calendar/js/views/modify_event.js
Expand Up @@ -615,18 +615,18 @@ Calendar.ns('Views').ModifyEvent = (function() {
*/
_updateDateTimeLocale: function(type, date, target, value) {
var _ = navigator.mozL10n.get;
var dateTimeFormatter = new navigator.mozL10n.DateTimeFormat();
var localeFormat = Calendar.App.dateFormat.localeFormat;

var _formats = {
date: _('dateTimeFormat_%x'),
time: _('dateTimeFormat_%X')
time: _('shortTimeFormat')
};

var targetElement = document.getElementById(target);
if (!targetElement)
return;

targetElement.textContent = dateTimeFormatter.localeFormat(
targetElement.textContent = localeFormat(
value, _formats[type]);

this.getEl(date).addEventListener('input', function(e) {
Expand All @@ -646,7 +646,7 @@ Calendar.ns('Views').ModifyEvent = (function() {
newDate.setSeconds(0);
}

targetElement.textContent = dateTimeFormatter.localeFormat(
targetElement.textContent = localeFormat(
newDate, _formats[type]);
});
},
Expand Down
31 changes: 23 additions & 8 deletions apps/calendar/js/views/view_event.js
Expand Up @@ -68,6 +68,23 @@ Calendar.ns('Views').ViewEvent = (function() {
}
},

formatDate: function(date) {
return Calendar.App.dateFormat.localeFormat(
date,
navigator.mozL10n.get('dateTimeFormat_%x')
);
},

formatTime: function(time) {
if (!time)
return '';

return Calendar.App.dateFormat.localeFormat(
time,
navigator.mozL10n.get('shortTimeFormat')
);
},

/**
* Updates the UI to use values from the current model.
*/
Expand All @@ -92,8 +109,8 @@ Calendar.ns('Views').ViewEvent = (function() {

var startDate = dateSrc.startDate;
var endDate = dateSrc.endDate;
var startTime = InputParser.exportTime(startDate);
var endTime = InputParser.exportTime(endDate);
var startTime = startDate;
var endTime = endDate;

// update the allday status of the view
if (model.isAllDay) {
Expand All @@ -105,15 +122,13 @@ Calendar.ns('Views').ViewEvent = (function() {
endTime = null;
}

this.setContent('start-date',
InputParser.exportDate(startDate));
this.setContent('start-date', this.formatDate(startDate));

this.setContent('end-date',
InputParser.exportDate(endDate));
this.setContent('end-date', this.formatDate(endDate));

this.setContent('start-time', startTime);
this.setContent('start-time', this.formatTime(startTime));

this.setContent('end-time', endTime);
this.setContent('end-time', this.formatTime(endTime));

// Handle alarm display
var alarmContent = '';
Expand Down
4 changes: 2 additions & 2 deletions apps/calendar/test/unit/views/modify_event_test.js
Expand Up @@ -392,10 +392,10 @@ suiteGroup('Views.ModifyEvent', function() {
assert.equal(endDateLocale.textContent, '12/31/2012');

var startTimeLocale = document.getElementById('start-time-locale');
assert.equal(startTimeLocale.textContent, '1:02:00 AM');
assert.equal(startTimeLocale.textContent, '1:02 AM');

var endTimeLocale = document.getElementById('end-time-locale');
assert.equal(endTimeLocale.textContent, '1:04:00 PM');
assert.equal(endTimeLocale.textContent, '1:04 PM');
});
});
});
Expand Down
17 changes: 12 additions & 5 deletions apps/calendar/test/unit/views/view_event_test.js
Expand Up @@ -202,10 +202,10 @@ suiteGroup('Views.ViewEvent', function() {
var expected = {
title: remote.title,
location: remote.location,
startDate: InputParser.exportDate(remote.startDate),
startTime: InputParser.exportTime(remote.startDate),
endDate: InputParser.exportDate(remote.endDate),
endTime: InputParser.exportTime(remote.endDate),
startDate: subject.formatDate(remote.startDate),
startTime: subject.formatTime(remote.startDate),
endDate: subject.formatDate(remote.endDate),
endTime: subject.formatTime(remote.endDate),
currentCalendar: calendar.remote.name,
description: remote.description
};
Expand Down Expand Up @@ -288,7 +288,7 @@ suiteGroup('Views.ViewEvent', function() {
remote.endDate = new Date(2012, 0, 2);

updatesValues(
{ endDate: '2012-01-01' },
{ endDate: '01/01/2012' },
true,
done
);
Expand Down Expand Up @@ -325,6 +325,13 @@ suiteGroup('Views.ViewEvent', function() {
});
});

suite('#formatTime', function() {
test('returns empty if invalid', function() {
var result = subject.formatTime();
assert.equal('', result);
});
});

suite('navigation', function() {
test('cancel button step back', function(done) {

Expand Down

0 comments on commit 8a49e2d

Please sign in to comment.