mirror of
https://github.com/stashapp/stash.git
synced 2025-12-18 21:04:37 +03:00
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user