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 #12631 from gitmai/bug-880775-birthday-timezone-error
Browse files Browse the repository at this point in the history
Bug 880775 - Birthday timezone error
  • Loading branch information
jmcanterafonseca committed Oct 3, 2013
2 parents be336dc + 40c250d commit 05686b6
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 12 deletions.
6 changes: 3 additions & 3 deletions apps/communications/contacts/js/fb/fb_contact_utils.js
Expand Up @@ -199,11 +199,11 @@ fb.getBirthDate = function getBirthDate(sbday) {

var syear = sbday.substring(iyear + 1, sbday.length);

out.setDate(parseInt(sday, 10));
out.setMonth(parseInt(smonth, 10) - 1, parseInt(sday, 10));
out.setUTCDate(parseInt(sday, 10));
out.setUTCMonth(parseInt(smonth, 10) - 1, parseInt(sday, 10));

if (syear && syear.length > 0) {
out.setYear(parseInt(syear, 10));
out.setUTCFullYear(parseInt(syear, 10));
}

return out;
Expand Down
4 changes: 3 additions & 1 deletion apps/communications/contacts/js/views/details.js
Expand Up @@ -295,7 +295,9 @@ contacts.Details = (function() {
var birthdayFormat = _('birthdayDateFormat') || '%e %B';
var birthdayString = '';
try {
birthdayString = f.localeFormat(contact.bday, birthdayFormat);
var offset = contact.bday.getTimezoneOffset() * 60 * 1000;
var normalizeBirthdayDate = new Date(contact.bday.getTime() + offset);
birthdayString = f.localeFormat(normalizeBirthdayDate, birthdayFormat);
} catch (err) {
console.error('Error parsing birthday');
return;
Expand Down
4 changes: 2 additions & 2 deletions apps/communications/contacts/test/unit/contact2vcard_test.js
Expand Up @@ -46,7 +46,7 @@ suite('mozContact to vCard', function() {
assert.ok(_contains('org:test org'));
assert.ok(_contains('title:sr. software architect'));
assert.ok(_contains('note:note 1'));
assert.ok(_contains('bday:1995-12-17'));
assert.ok(_contains('bday:1970-01-01'));
assert.ok(_contains('photo:data:image/gif;base64,' + b64));
assert.ok(_contains('email;type=personal:test@test.com'));
assert.ok(_contains(
Expand All @@ -73,7 +73,7 @@ suite('mozContact to vCard', function() {
assert.ok(_contains('org:test org'));
assert.ok(_contains('title:sr. software architect'));
assert.ok(_contains('note:note 1'));
assert.ok(_contains('bday:1995-12-17'));
assert.ok(_contains('bday:1970-01-01'));
assert.ok(_contains('photo:data:image/gif;base64,' + b64));
assert.ok(_contains('email;type=personal:test@test.com'));
assert.ok(_contains(
Expand Down
8 changes: 7 additions & 1 deletion apps/communications/contacts/test/unit/views/details_test.js
Expand Up @@ -187,7 +187,13 @@ suite('Render contact', function() {
suite('Render bday', function() {
test('with bday', function() {
subject.render(null, TAG_OPTIONS);
assert.include(container.innerHTML, mockContact.bday);
var bdayBlock = container.querySelector('#birthday-template-1');
assert.isNotNull(bdayBlock);
// Ensuring timezone correctly treated (Bug 880775)
var offset = mockContact.bday.getTimezoneOffset() * 60 * 1000;
var targetDate = new Date(mockContact.bday.getTime() + offset);
assert.equal(bdayBlock.querySelector('strong').textContent,
targetDate.toString());
});
test('without bday', function() {
var contactWoBday = new MockContactAllFields();
Expand Down
2 changes: 1 addition & 1 deletion apps/communications/gmail/js/gmail_connector.js
Expand Up @@ -267,7 +267,7 @@ var GmailConnector = (function GmailConnector() {

var bday = googleContact.querySelector('birthday');
if (bday) {
output.bday = new Date(bday.getAttribute('when'));
output.bday = new Date(Date.parse(bday.getAttribute('when')));
}

var content = googleContact.querySelector('content');
Expand Down
6 changes: 3 additions & 3 deletions apps/communications/live/js/live_connector.js
Expand Up @@ -109,10 +109,10 @@ if (!window.LiveConnector) {
var bday = liveContact.birth_day;
if (bmonth && bday) {
var birthdate = out.bday = new Date();
birthdate.setDate(bday);
birthdate.setMonth(bmonth, bday);
birthdate.setUTCDate(bday);
birthdate.setUTCMonth(bmonth, bday);
if (byear) {
birthdate.setYear(byear);
birthdate.setUTCFullYear(byear);
}
}

Expand Down
2 changes: 1 addition & 1 deletion shared/test/unit/mocks/mock_contact_all_fields.js
Expand Up @@ -16,7 +16,7 @@ function MockContactAllFields() {
'streetAddress': 'Gotthardstrasse 22'
}
],
'bday': new Date('December 17, 1995 13:24:00'),
'bday': new Date(0),
'email': [
{
'type': ['personal'],
Expand Down

0 comments on commit 05686b6

Please sign in to comment.