removes initial idea of performing conversion on the server since this would be a breaking change, instead we can easily do this on the client side - and this works much better. Have added pre-values to the date/time picker to be able to enable offset times. This is enabled for the publish-at pickers since those must be offset. When the datetime is offset, it shows the server time in small text underneath the picker. Have added js unit tests for the date conversions. Have updated the datepicker controller to set the model date in a single place/method so it's consistent.

This commit is contained in:
Shannon
2016-05-25 09:43:31 +02:00
parent b69580967e
commit 2504586c26
13 changed files with 190 additions and 64 deletions

View File

@@ -0,0 +1,53 @@
describe('date helper tests', function () {
var dateHelper;
beforeEach(module('umbraco.services'));
beforeEach(inject(function ($injector) {
dateHelper = $injector.get('dateHelper');
}));
describe('converting to local moments', function () {
it('converts from a positive offset', function () {
var offsetMin = 600; //+10
var strDate = "2016-01-01 10:00:00";
var result = dateHelper.convertToLocalMomentTime(strDate, offsetMin);
expect(result.format("YYYY-MM-DD HH:mm:ss Z")).toBe("2016-01-01 01:00:00 +01:00");
});
it('converts from a negataive offset', function () {
var offsetMin = -420; //-7
var strDate = "2016-01-01 10:00:00";
var result = dateHelper.convertToLocalMomentTime(strDate, offsetMin);
expect(result.format("YYYY-MM-DD HH:mm:ss Z")).toBe("2016-01-01 18:00:00 +01:00");
});
});
describe('converting to server strings', function () {
it('converts to a positive offset', function () {
var offsetMin = 600; //+10
var localDate = moment("2016-01-01 10:00:00");
var result = dateHelper.convertToServerStringTime(localDate, offsetMin, "YYYY-MM-DD HH:mm:ss Z");
expect(result).toBe("2016-01-01 19:00:00 +10:00");
});
it('converts from a negataive offset', function () {
var offsetMin = -420; //-7
var localDate = moment("2016-01-01 10:00:00");
var result = dateHelper.convertToServerStringTime(localDate, offsetMin, "YYYY-MM-DD HH:mm:ss Z");
expect(result).toBe("2016-01-01 02:00:00 -07:00");
});
});
});