mirror of
https://github.com/plan-player-analytics/Plan.git
synced 2025-03-10 22:01:00 +01:00
Fixed date formatting of the date fields
This commit is contained in:
parent
e8e7258443
commit
54a698136e
@ -229,24 +229,35 @@ function createFilterSelector(parent, index, filter) {
|
|||||||
|
|
||||||
function isValidDate(value) {
|
function isValidDate(value) {
|
||||||
if (!value) return true;
|
if (!value) return true;
|
||||||
const date = value.match(/^(\d{1,2})\/(\d{1,2})\/(\d{4,5})$/);
|
const d = value.match(
|
||||||
return date ? new Date(date[3], date[2] - 1, date[1]) : null;
|
/^(0\d|\d{2})[\/|\-]?(0\d|\d{2})[\/|\-]?(\d{4,5})$/
|
||||||
|
);
|
||||||
|
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/Date
|
||||||
|
const parsedDay = Number(d[1]);
|
||||||
|
const parsedMonth = Number(d[2]) - 1; // 0=January, 11=December
|
||||||
|
const parsedYear = Number(d[3]);
|
||||||
|
return d ? new Date(parsedYear, parsedMonth, parsedDay) : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
function correctDate(value) {
|
function correctDate(value) {
|
||||||
const d = value.match(
|
const d = value.match(
|
||||||
/^(0\d{1}|\d{2})[\/|\-]?(0\d{1}|\d{2})[\/|\-]?(\d{4,5})$/
|
/^(0\d|\d{2})[\/|\-]?(0\d|\d{2})[\/|\-]?(\d{4,5})$/
|
||||||
);
|
);
|
||||||
if (!d) return value;
|
if (!d) return value;
|
||||||
|
|
||||||
const date = d ? new Date(d[3], d[2] - 1, d[1]) : null;
|
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/Date
|
||||||
const day = "" + (date.getUTCDate() + 1);
|
const parsedDay = Number(d[1]);
|
||||||
const month = "" + (date.getUTCMonth() + 1);
|
const parsedMonth = Number(d[2]) - 1; // 0=January, 11=December
|
||||||
const year = "" + date.getUTCFullYear();
|
const parsedYear = Number(d[3]);
|
||||||
|
const date = d ? new Date(parsedYear, parsedMonth, parsedDay) : null;
|
||||||
|
|
||||||
|
const day = `${date.getDate()}`;
|
||||||
|
const month = `${date.getMonth() + 1}`;
|
||||||
|
const year = `${date.getFullYear()}`;
|
||||||
return (
|
return (
|
||||||
(day.length === 1 ? "0" + day : day) +
|
(day.length === 1 ? `0${day}` : day) +
|
||||||
"/" +
|
"/" +
|
||||||
(month.length === 1 ? "0" + month : month) +
|
(month.length === 1 ? `0${month}` : month) +
|
||||||
"/" +
|
"/" +
|
||||||
year
|
year
|
||||||
);
|
);
|
||||||
|
Loading…
Reference in New Issue
Block a user