Bert Leunis pushed to branch feature/CHANNELMGR-1391 at cms-community / hippo-addon-channel-manager
Commits: 105708e5 by Bert Leunis at 2018-03-08T13:19:17+01:00 CHANNELMGR-1391 use moment.js for date manipulation - - - - - 3 changed files: - frontend-ng/package-lock.json - frontend-ng/package.json - frontend-ng/src/app/channel/sidePanels/rightSidePanel/contentEditor/fields/dateField/dateField.controller.js Changes: ===================================== frontend-ng/package-lock.json ===================================== --- a/frontend-ng/package-lock.json +++ b/frontend-ng/package-lock.json @@ -10185,6 +10185,19 @@ } } }, + "moment": { + "version": "2.21.0", + "resolved": "https://registry.npmjs.org/moment/-/moment-2.21.0.tgz", + "integrity": "sha1-KhFLUdKm7J5tg8+AP4OKh42KAjo=" + }, + "moment-timezone": { + "version": "0.5.14", + "resolved": "https://registry.npmjs.org/moment-timezone/-/moment-timezone-0.5.14.tgz", + "integrity": "sha1-TrOP+VOLgBCLpGekWPPtQmjM/LE=", + "requires": { + "moment": "2.21.0" + } + }, "move-concurrently": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/move-concurrently/-/move-concurrently-1.0.1.tgz", ===================================== frontend-ng/package.json ===================================== --- a/frontend-ng/package.json +++ b/frontend-ng/package.json @@ -36,6 +36,7 @@ "angular-ui-tree": "2.22.6", "es6-shim": "0.35.3", "jquery": "3.2.1", + "moment-timezone": "0.5.14", "mutation-summary": "0.1.1", "ng-device-detector": "4.0.3", "ng-focus-if": "1.0.7", ===================================== frontend-ng/src/app/channel/sidePanels/rightSidePanel/contentEditor/fields/dateField/dateField.controller.js ===================================== --- a/frontend-ng/src/app/channel/sidePanels/rightSidePanel/contentEditor/fields/dateField/dateField.controller.js +++ b/frontend-ng/src/app/channel/sidePanels/rightSidePanel/contentEditor/fields/dateField/dateField.controller.js @@ -14,75 +14,27 @@ * limitations under the License. */ +import moment from 'moment-timezone'; + class DateValue { constructor(value) { - this.value = value; + this.value = moment(value); } - /** - * @returns {string} - */ get hours() { - const timestamp = Date.parse(this.value); - if (angular.isNumber(timestamp)) { - return String(new Date(timestamp).getHours()); - } - return ''; + return this.value.hours(); } - /** - * @param {string} hours - */ set hours(hours) { - if (hours && hours.length > 0 && !DateValue.isNumeric(hours)) { - return; - } - - const timestamp = Date.parse(this.value); - if (angular.isNumber(timestamp)) { - const date = new Date(timestamp); - date.setHours(hours); - this.value = this.value.substr(0, 11) + DateValue.pad(date.getUTCHours(), 2) + this.value.substr(13); - } + this.value.hours(hours); } - /** - * @returns {string} - */ get minutes() { - const timestamp = Date.parse(this.value); - if (angular.isNumber(timestamp)) { - return String(new Date(timestamp).getMinutes()); - } - return ''; + return this.value.minutes(); } - /** - * @param {string} minutes - */ set minutes(minutes) { - if (minutes && minutes.length > 0 && !DateValue.isNumeric(minutes)) { - return; - } - - const timestamp = Date.parse(this.value); - if (angular.isNumber(timestamp)) { - const date = new Date(timestamp); - date.setMinutes(minutes); - this.value = this.value.substr(0, 14) + DateValue.pad(date.getUTCMinutes(), 2) + this.value.substr(16); - } - } - - static pad(num, size) { - let result = String(num); - while (result.length < size) { - result = `0${result}`; - } - return result; - } - - static isNumeric(n) { - return !isNaN(parseFloat(n)) && isFinite(n); + this.value.minute(minutes); } } @@ -142,7 +94,7 @@ class DateFieldController { _updateFieldValues() { for (let i = 0; i < this.fieldValues.length; i += 1) { - this.fieldValues[i].value = this.dateValues[i].value; + this.fieldValues[i].value = this.dateValues[i].value.format('YYYY-MM-DDTHH:mm:ss.SSSZ'); } } View it on GitLab: https://code.onehippo.org/cms-community/hippo-addon-channel-manager/commit/105708e5ac0f47e3e09dd8ebcb517b1b7c847780 --- View it on GitLab: https://code.onehippo.org/cms-community/hippo-addon-channel-manager/commit/105708e5ac0f47e3e09dd8ebcb517b1b7c847780 You're receiving this email because of your account on code.onehippo.org.
_______________________________________________ Hippocms-svn mailing list Hippocms-svn@lists.onehippo.org https://lists.onehippo.org/mailman/listinfo/hippocms-svn