[FIX] web: wrong condition in time helpers
closes odoo/odoo#71871 X-original-commit: a299fb2dd2f49edc1e5d088e6a0cd672583a76eb Signed-off-by: Aaron Bohy (aab) <aab@odoo.com>
This commit is contained in:
@@ -306,7 +306,7 @@ const dateFormatWoZeroCache = {};
|
||||
*/
|
||||
function getLangDateFormatWoZero() {
|
||||
const dateFormat = getLangDateFormat();
|
||||
if (!dateFormat in dateFormatWoZeroCache) {
|
||||
if (!(dateFormat in dateFormatWoZeroCache)) {
|
||||
dateFormatWoZeroCache[dateFormat] = dateFormat
|
||||
.replace('MM', 'M')
|
||||
.replace('DD', 'D');
|
||||
@@ -320,7 +320,7 @@ const timeFormatWoZeroCache = {};
|
||||
*/
|
||||
function getLangTimeFormatWoZero() {
|
||||
const timeFormat = getLangTimeFormat();
|
||||
if (!timeFormat in timeFormatWoZeroCache) {
|
||||
if (!(timeFormat in timeFormatWoZeroCache)) {
|
||||
timeFormatWoZeroCache[timeFormat] = timeFormat
|
||||
.replace('HH', 'H')
|
||||
.replace('mm', 'm')
|
||||
|
||||
@@ -467,7 +467,7 @@ function parseDate(value, field, options) {
|
||||
return false;
|
||||
}
|
||||
var datePattern = time.getLangDateFormat();
|
||||
var datePatternWoZero = datePattern.replace('MM', 'M').replace('DD', 'D');
|
||||
var datePatternWoZero = time.getLangDateFormatWoZero();
|
||||
var date;
|
||||
const smartDate = parseSmartDateInput(value);
|
||||
if (smartDate) {
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
odoo.define('web.time_tests', function (require) {
|
||||
"use strict";
|
||||
|
||||
const core = require('web.core');
|
||||
var time = require('web.time');
|
||||
|
||||
QUnit.module('core', {}, function () {
|
||||
@@ -145,6 +146,20 @@ QUnit.module('core', {}, function () {
|
||||
assert.strictEqual(time.time_to_str(date), "12:34:23");
|
||||
});
|
||||
|
||||
QUnit.test("Get lang datetime format", (assert) => {
|
||||
assert.expect(4);
|
||||
const originalParameters = Object.assign({}, core._t.database.parameters);
|
||||
Object.assign(core._t.database.parameters, {
|
||||
date_format: '%m/%d/%Y',
|
||||
time_format: '%H:%M:%S',
|
||||
});
|
||||
assert.strictEqual(time.getLangDateFormat(), "MM/DD/YYYY");
|
||||
assert.strictEqual(time.getLangDateFormatWoZero(), "M/D/YYYY");
|
||||
assert.strictEqual(time.getLangTimeFormat(), "HH:mm:ss");
|
||||
assert.strictEqual(time.getLangTimeFormatWoZero(), "H:m:s");
|
||||
Object.assign(core._t.database.parameters, originalParameters);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
Reference in New Issue
Block a user