Fix performer age timezone issues (#1251)

* Parse date string manually
This commit is contained in:
peolic
2021-04-02 02:09:10 +03:00
committed by GitHub
parent 2c1300cae0
commit 7671465334

View File

@@ -69,11 +69,27 @@ const fileNameFromPath = (path: string) => {
return path.replace(/^.*[\\/]/, "");
};
const stringToDate = (dateString: string) => {
if (!dateString) return null;
const parts = dateString.split("-");
// Invalid date string
if (parts.length !== 3) return null;
const year = Number(parts[0]);
const monthIndex = Math.max(0, Number(parts[1]) - 1);
const day = Number(parts[2]);
return new Date(year, monthIndex, day, 0, 0, 0, 0);
};
const getAge = (dateString?: string | null, fromDateString?: string) => {
if (!dateString) return 0;
const birthdate = new Date(dateString);
const fromDate = fromDateString ? new Date(fromDateString) : new Date();
const birthdate = stringToDate(dateString);
const fromDate = fromDateString ? stringToDate(fromDateString) : new Date();
if (!birthdate || !fromDate) return 0;
let age = fromDate.getFullYear() - birthdate.getFullYear();
if (
@@ -176,6 +192,7 @@ const TextUtils = {
fileSizeFractionalDigits,
secondsToTimestamp,
fileNameFromPath,
stringToDate,
age: getAge,
bitRate,
resolution,