38 lines
909 B
TypeScript
38 lines
909 B
TypeScript
import moment from "moment";
|
|
|
|
const convertAniListDateToString = (date: {
|
|
year?: number;
|
|
month?: number;
|
|
day?: number;
|
|
}): string => {
|
|
if (
|
|
date.year === undefined ||
|
|
(date.year === 0 && date.month === undefined) ||
|
|
(date.month === 0 && date.day === undefined) ||
|
|
date.day === 0
|
|
) {
|
|
return "";
|
|
}
|
|
const newISODate = new Date(date.year, date.month - 1, date.day);
|
|
const newMoment = moment(newISODate);
|
|
return newMoment.format("MM-DD-YYYY");
|
|
};
|
|
|
|
const convertAniListDateToDate = (date: {
|
|
year?: number;
|
|
month?: number;
|
|
day?: number;
|
|
}): Date | null => {
|
|
if (
|
|
date.year === undefined ||
|
|
(date.year === 0 && date.month === undefined) ||
|
|
(date.month === 0 && date.day === undefined) ||
|
|
date.day === 0
|
|
) {
|
|
return null;
|
|
}
|
|
return new Date(date.year, date.month - 1, date.day);
|
|
};
|
|
|
|
export { convertAniListDateToString, convertAniListDateToDate };
|