summaryrefslogtreecommitdiff
path: root/addons
diff options
context:
space:
mode:
authorHarpritsinh Sisodiya <hsi@odoo.com>2020-05-15 14:29:17 +0000
committerAaron Bohy <aab@odoo.com>2020-07-28 14:02:10 +0000
commit6aa6c321a6cfc08e5490781c4fc7ee62beeebb15 (patch)
treeb7a47b11ca4bdbdc148db850a9536c0bc78a2bec /addons
parent684b628c5acc298af83791fbaf8da0b774140425 (diff)
[IMP] web: remove min date limitation of year 1900
Before this commit, user could not selecta a date before year 1900. This was an historical limitation due to python < 3.2 that didn't support dates before 1900. After this commit, user can select any date, user can select any date from 01/01/0001. taskID: 2166761 Fixes #41788 Closes #43055 closes odoo/odoo#51406 Signed-off-by: Géry Debongnie (ged) <ged@openerp.com> Co-authored-by: Mohammed Shekha <msh@odoo.com> Co-authored-by: Aaron Bohy <aab@odoo.com>
Diffstat (limited to 'addons')
-rw-r--r--addons/survey/static/src/js/survey_form.js2
-rw-r--r--addons/web/static/src/js/components/datepicker.js2
-rw-r--r--addons/web/static/src/js/fields/field_utils.js23
-rw-r--r--addons/web/static/src/js/widgets/date_picker.js2
-rw-r--r--addons/web/static/tests/fields/field_utils_tests.js15
-rw-r--r--addons/web_editor/static/src/js/editor/snippets.options.js2
-rw-r--r--addons/website/static/src/js/menu/content.js2
-rw-r--r--addons/website_form/static/src/snippets/s_website_form/000.js2
8 files changed, 28 insertions, 22 deletions
diff --git a/addons/survey/static/src/js/survey_form.js b/addons/survey/static/src/js/survey_form.js
index 7d77dcab579..e4bcf76fea9 100644
--- a/addons/survey/static/src/js/survey_form.js
+++ b/addons/survey/static/src/js/survey_form.js
@@ -894,7 +894,7 @@ publicWidget.registry.SurveyFormWidget = publicWidget.Widget.extend({
var minDate = minDateData
? this._formatDateTime(minDateData, datetimepickerFormat)
- : moment({ y: 1900 });
+ : moment({ y: 1 });
var maxDate = maxDateData
? this._formatDateTime(maxDateData, datetimepickerFormat)
diff --git a/addons/web/static/src/js/components/datepicker.js b/addons/web/static/src/js/components/datepicker.js
index 715e594e077..d7d62ba104e 100644
--- a/addons/web/static/src/js/components/datepicker.js
+++ b/addons/web/static/src/js/components/datepicker.js
@@ -167,7 +167,7 @@ odoo.define('web.DatePickerOwl', function (require) {
},
locale: moment.locale(),
maxDate: moment({ y: 9999, M: 11, d: 31 }),
- minDate: moment({ y: 1900 }),
+ minDate: moment({ y: 1 }),
useCurrent: false,
widgetParent: 'body',
};
diff --git a/addons/web/static/src/js/fields/field_utils.js b/addons/web/static/src/js/fields/field_utils.js
index b62a3db7921..8f8b9bbb2ab 100644
--- a/addons/web/static/src/js/fields/field_utils.js
+++ b/addons/web/static/src/js/fields/field_utils.js
@@ -431,9 +431,10 @@ function parseDate(value, field, options) {
return false;
}
var datePattern = time.getLangDateFormat();
- var datePatternWoZero = datePattern.replace('MM','M').replace('DD','D');
+ var datePatternWoZero = datePattern.replace('MM', 'M').replace('DD', 'D');
var date;
if (options && options.isUTC) {
+ value = value.padStart(10, "0"); // server may send "932-10-10" for "0932-10-10" on some OS
date = moment.utc(value);
} else {
date = moment.utc(value, [datePattern, datePatternWoZero, moment.ISO_8601]);
@@ -442,12 +443,10 @@ function parseDate(value, field, options) {
if (date.year() === 0) {
date.year(moment.utc().year());
}
- if (date.year() >= 1900) {
- date.toJSON = function () {
- return this.clone().locale('en').format('YYYY-MM-DD');
- };
- return date;
- }
+ date.toJSON = function () {
+ return this.clone().locale('en').format('YYYY-MM-DD');
+ };
+ return date;
}
throw new Error(_.str.sprintf(core._t("'%s' is not a correct date"), value));
}
@@ -489,12 +488,10 @@ function parseDateTime(value, field, options) {
if (datetime.year() === 0) {
datetime.year(moment.utc().year());
}
- if (datetime.year() >= 1900) {
- datetime.toJSON = function () {
- return this.clone().locale('en').format('YYYY-MM-DD HH:mm:ss');
- };
- return datetime;
- }
+ datetime.toJSON = function () {
+ return this.clone().locale('en').format('YYYY-MM-DD HH:mm:ss');
+ };
+ return datetime;
}
throw new Error(_.str.sprintf(core._t("'%s' is not a correct datetime"), value));
}
diff --git a/addons/web/static/src/js/widgets/date_picker.js b/addons/web/static/src/js/widgets/date_picker.js
index 0b19f0c4506..b989cc87355 100644
--- a/addons/web/static/src/js/widgets/date_picker.js
+++ b/addons/web/static/src/js/widgets/date_picker.js
@@ -30,7 +30,7 @@ var DateWidget = Widget.extend({
this.options = _.extend({
locale: moment.locale(),
format : this.type_of_date === 'datetime' ? time.getLangDatetimeFormat() : time.getLangDateFormat(),
- minDate: moment({ y: 1900 }),
+ minDate: moment({ y: 1 }),
maxDate: moment({ y: 9999, M: 11, d: 31 }),
useCurrent: false,
icons: {
diff --git a/addons/web/static/tests/fields/field_utils_tests.js b/addons/web/static/tests/fields/field_utils_tests.js
index d25d4610d4d..f3ab43260ae 100644
--- a/addons/web/static/tests/fields/field_utils_tests.js
+++ b/addons/web/static/tests/fields/field_utils_tests.js
@@ -316,7 +316,7 @@ QUnit.test('parse percentage', function(assert) {
});
QUnit.test('parse datetime', function (assert) {
- assert.expect(5);
+ assert.expect(6);
var originalParameters = _.clone(core._t.database.parameters);
var originalLocale = moment.locale();
@@ -343,8 +343,12 @@ QUnit.test('parse datetime', function (assert) {
moment.locale('englishForTest');
_.extend(core._t.database.parameters, {date_format: '%m/%d/%Y', time_format: '%H:%M:%S'});
- assert.throws(function () {fieldUtils.parse.datetime("13/01/2019 12:00:00", {}, {})}, /is not a correct/, "Wrongly formated dates should be invalids");
- assert.throws(function () {fieldUtils.parse.datetime("1899-01-01 12:00:00", {}, {})}, /is not a correct/, "Dates before 1900 should be invalids");
+ assert.throws(function () {
+ fieldUtils.parse.datetime("13/01/2019 12:00:00", {}, {});
+ }, /is not a correct/, "Wrongly formated dates should be invalid");
+ assert.throws(function () {
+ fieldUtils.parse.datetime("10000-01-01 12:00:00", {}, {});
+ }, /is not a correct/, "Dates after 9999 should be invalid");
dateStr = '01/13/2019 10:05:45';
date1 = fieldUtils.parse.datetime(dateStr);
@@ -356,6 +360,11 @@ QUnit.test('parse datetime', function (assert) {
date2 = moment.utc(dateStr, ['M/D/YYYY H:m:s'], true);
assert.equal(date1.format(), date2.format(), "Date without leading 0");
+ dateStr = '01/01/0001 10:15:45';
+ date1 = fieldUtils.parse.datetime(dateStr);
+ date2 = moment.utc(dateStr, ['MM/DD/YYYY HH:mm:ss'], true);
+ assert.equal(date1.format(), date2.format(), "can parse dates of year 1");
+
moment.locale('norvegianForTest');
_.extend(core._t.database.parameters, {date_format: '%d. %b %Y', time_format: '%H:%M:%S'});
dateStr = '16. jan. 2019 10:05:45';
diff --git a/addons/web_editor/static/src/js/editor/snippets.options.js b/addons/web_editor/static/src/js/editor/snippets.options.js
index ff2aea2d7b7..c9803a5b142 100644
--- a/addons/web_editor/static/src/js/editor/snippets.options.js
+++ b/addons/web_editor/static/src/js/editor/snippets.options.js
@@ -1443,7 +1443,7 @@ const DatetimePickerUserValueWidget = InputUserValueWidget.extend({
this.inputEl.setAttribute('data-target', '#' + datetimePickerId);
const datepickersOptions = {
- minDate: moment({y: 1900}),
+ minDate: moment({ y: 1 }),
maxDate: moment().add(200, 'y'),
calendarWeeks: true,
defaultDate: moment().format(),
diff --git a/addons/website/static/src/js/menu/content.js b/addons/website/static/src/js/menu/content.js
index dc90d923df2..dac8087bd73 100644
--- a/addons/website/static/src/js/menu/content.js
+++ b/addons/website/static/src/js/menu/content.js
@@ -165,7 +165,7 @@ var PagePropertiesDialog = weWidgets.Dialog.extend({
}));
var datepickersOptions = {
- minDate: moment({y: 1900}),
+ minDate: moment({ y: 1 }),
maxDate: moment().add(200, 'y'),
calendarWeeks: true,
icons : {
diff --git a/addons/website_form/static/src/snippets/s_website_form/000.js b/addons/website_form/static/src/snippets/s_website_form/000.js
index b71ee1a7d44..b2f0f3370b4 100644
--- a/addons/website_form/static/src/snippets/s_website_form/000.js
+++ b/addons/website_form/static/src/snippets/s_website_form/000.js
@@ -37,7 +37,7 @@ odoo.define('website_form.s_website_form', function (require) {
// Initialize datetimepickers
var datepickers_options = {
- minDate: moment({y: 1900}),
+ minDate: moment({ y: 1 }),
maxDate: moment({y: 9999, M: 11, d: 31}),
calendarWeeks: true,
icons: {