Merge pull request #3055 from ulferts/fix/timezone_on_dates

consider all dates without a timezone (i.e. local) on the front end
pull/3041/head
Jan Sandbrink 10 years ago
commit 3c87e3225b
  1. 31
      frontend/app/services/timezone-service.js
  2. 2
      frontend/app/ui_components/authoring-directive.js
  3. 4
      frontend/app/work_packages/helpers/work-packages-helper.js
  4. 4
      frontend/tests/integration/mocks/work-package.json
  5. 4
      frontend/tests/integration/mocks/work-packages/819_patch.json
  6. 4
      frontend/tests/integration/mocks/work-packages/820.json
  7. 4
      frontend/tests/integration/mocks/work-packages/821.json
  8. 4
      frontend/tests/integration/mocks/work-packages/822.json
  9. 2
      frontend/tests/integration/mocks/work-packages/823.json
  10. 2
      frontend/tests/integration/mocks/work-packages/824.json
  11. 2
      frontend/tests/integration/mocks/work-packages/825.json
  12. 27
      frontend/tests/unit/tests/services/timezone-service-test.js
  13. 2
      frontend/tests/unit/tests/ui_components/authoring-directive-test.js

@ -33,8 +33,8 @@ module.exports = function(ConfigurationService, I18n) {
moment.locale(I18n.locale);
},
parseDate: function(date, format) {
var d = moment.utc(date, format);
parseDatetime: function(datetime, format) {
var d = moment.utc(datetime, format);
if (ConfigurationService.isTimezoneSet()) {
d.local();
@ -44,18 +44,27 @@ module.exports = function(ConfigurationService, I18n) {
return d;
},
parseDate: function(date, format) {
return moment(date, format);
},
parseISODate: function(date) {
return TimezoneService.parseDate(date, 'YYYY-MM-DD');
},
formattedDate: function(date) {
var format = ConfigurationService.dateFormatPresent() ? ConfigurationService.dateFormat() : 'L';
return TimezoneService.parseDate(date).format(format);
var d = TimezoneService.parseDate(date);
return d.format(TimezoneService.getDateFormat());
},
formattedTime: function(datetimeString) {
return TimezoneService.parseDatetime(datetimeString).format(TimezoneService.getTimeFormat());
},
formattedTime: function(date) {
var format = ConfigurationService.timeFormatPresent() ? ConfigurationService.timeFormat() : 'LT';
return TimezoneService.parseDate(date).format(format);
formattedDatetime: function(datetimeString) {
var d = TimezoneService.parseDatetime(datetimeString);
return d.format(TimezoneService.getDateFormat()) + ' ' +
d.format(TimezoneService.getTimeFormat());
},
formattedISODate: function(date) {
@ -66,6 +75,14 @@ module.exports = function(ConfigurationService, I18n) {
var format = dateFormat || (ConfigurationService.dateFormatPresent() ?
ConfigurationService.dateFormat() : 'L');
return moment(date, [format]).isValid();
},
getDateFormat: function() {
return ConfigurationService.dateFormatPresent() ? ConfigurationService.dateFormat() : 'L';
},
getTimeFormat: function() {
return ConfigurationService.timeFormatPresent() ? ConfigurationService.timeFormat() : 'LT';
}
};

@ -36,7 +36,7 @@ module.exports = function(I18n, PathHelper, TimezoneService) {
link: function(scope, element, attrs) {
moment.locale(I18n.locale);
var createdOn = TimezoneService.parseDate(scope.createdOn);
var createdOn = TimezoneService.parseDatetime(scope.createdOn);
var timeago = createdOn.fromNow();
var time = createdOn.format('LLL');

@ -141,9 +141,7 @@ module.exports =function(TimezoneService, currencyFilter, CustomFieldHelper) {
case 'datetime':
var dateTime;
if (value) {
dateTime = TimezoneService.formattedDate(value) +
' ' +
TimezoneService.formattedTime(value);
dateTime = TimezoneService.formattedDatetime(value);
}
return dateTime || '';
case 'date':

@ -86,8 +86,8 @@
"raw": "Sapiente terra dolores tempore debitis stultus. Adeo aduro repellendus. Vereor vulgivagus maxime ulciscor barba deleniti cognomen ustulo. Hic tubineus sumptus argumentum animi arcesso. Voluntarius dolore et. Apostolus vobis ultra delego acervus averto vitae."
},
"priority": "Normal",
"startDate": "2014-02-28T00:00:00+00:00",
"dueDate": "2014-04-28T00:00:00+00:00",
"startDate": "2014-02-28",
"dueDate": "2014-04-28",
"estimatedTime": {
"units": "hours",
"value": null

@ -107,8 +107,8 @@
"status": "specified",
"isClosed": false,
"priority": "Normal",
"startDate": "2014-10-23T00:00:00+00:00",
"dueDate": "2014-12-27T00:00:00+00:00",
"startDate": "2014-10-23",
"dueDate": "2014-12-27",
"estimatedTime": "PT0S",
"spentTime": "PT0S",
"percentageDone": 0,

@ -93,8 +93,8 @@
"raw": "#54\n2"
},
"priority": "Normal",
"startDate": "2014-10-23T00:00:00+00:00",
"dueDate": "2014-12-27T00:00:00+00:00",
"startDate": "2014-10-23",
"dueDate": "2014-12-27",
"estimatedTime": "PT0S",
"spentTime": "PT0S",
"percentageDone": 0,

@ -103,8 +103,8 @@
"raw": "#54\n2"
},
"priority": "Normal",
"startDate": "2014-10-23T00:00:00+00:00",
"dueDate": "2014-12-27T00:00:00+00:00",
"startDate": "2014-10-23",
"dueDate": "2014-12-27",
"estimatedTime": "PT0S",
"spentTime": "PT0S",
"percentageDone": 0,

@ -105,8 +105,8 @@
"description": "",
"rawDescription": "",
"priority": "Normal",
"startDate": "2014-10-23T00:00:00+00:00",
"dueDate": "2014-12-27T00:00:00+00:00",
"startDate": "2014-10-23",
"dueDate": "2014-12-27",
"estimatedTime": "PT0S",
"spentTime": "PT12H",
"percentageDone": 0,

@ -109,7 +109,7 @@
},
"priority": "Normal",
"startDate": null,
"dueDate": "2014-12-27T00:00:00+00:00",
"dueDate": "2014-12-27",
"estimatedTime": "PT0S",
"spentTime": "PT0S",
"percentageDone": 0,

@ -108,7 +108,7 @@
"raw": "#54"
},
"priority": "Normal",
"startDate": "2014-10-23T00:00:00+00:00",
"startDate": "2014-10-23",
"dueDate": null,
"estimatedTime": "PT0S",
"spentTime": "PT0S",

@ -112,7 +112,7 @@
"raw": "#54"
},
"priority": "Normal",
"startDate": "2014-10-23T00:00:00+00:00",
"startDate": "2014-10-23",
"dueDate": null,
"estimatedTime": "PT0S",
"spentTime": "PT0S",

@ -31,6 +31,7 @@
describe('TimezoneService', function() {
var TIME = '2013-02-08T09:30:26';
var DATE = '2013-02-08';
var TimezoneService;
var ConfigurationService;
var isTimezoneSetStub;
@ -42,15 +43,15 @@ describe('TimezoneService', function() {
TimezoneService = _TimezoneService_;
ConfigurationService = _ConfigurationService_;
isTimezoneSetStub = sinon.stub(ConfigurationService, "isTimezoneSet");
timezoneStub = sinon.stub(ConfigurationService, "timezone");
isTimezoneSetStub = sinon.stub(ConfigurationService, 'isTimezoneSet');
timezoneStub = sinon.stub(ConfigurationService, 'timezone');
}));
describe('#parseDate', function() {
describe('#parseDatetime', function() {
it('is UTC', function() {
var time = TimezoneService.parseDate(TIME);
var time = TimezoneService.parseDatetime(TIME);
expect(time.zone()).to.equal(0);
expect(time.format("HH:mm")).to.eq("09:30");
expect(time.format('HH:mm')).to.eq('09:30');
});
describe('Non-UTC timezone', function() {
@ -61,12 +62,24 @@ describe('TimezoneService', function() {
isTimezoneSetStub.returns(true);
timezoneStub.returns(timezone);
date = TimezoneService.parseDate(TIME);
date = TimezoneService.parseDatetime(TIME);
});
it('is ' + timezone, function() {
expect(date.format("HH:mm")).to.eq("01:30");
expect(date.format('HH:mm')).to.eq('01:30');
});
});
});
describe('#parseDate', function() {
it('has local time zone', function() {
var time = TimezoneService.parseDate(DATE);
expect(time.zone()).to.equal(time.clone().local().zone());
});
it('has no time information', function() {
var time = TimezoneService.parseDate(DATE);
expect(time.format('HH:mm')).to.eq('00:00');
});
});
});

@ -37,7 +37,7 @@ describe('authoring Directive', function() {
beforeEach(module('openproject.templates', function($provide) {
timezoneService = {};
timezoneService.parseDate = sinon.stub().returns(createdOn);
timezoneService.parseDatetime = sinon.stub().returns(createdOn);
$provide.constant('TimezoneService', timezoneService);
}));

Loading…
Cancel
Save