27 lines
708 B
TypeScript
27 lines
708 B
TypeScript
// Function to check if the file (or anything) timestamp was created within the last X minutes
|
|
export let is_datetime_recent = function is_datetime_recent(
|
|
{
|
|
datetime,
|
|
minutes,
|
|
log_lvl = 0
|
|
}: {
|
|
datetime: string,
|
|
minutes: number,
|
|
log_lvl?: number
|
|
}) {
|
|
if (log_lvl) {
|
|
console.log(`*** is_datetime_recent() *** datetime=${datetime} minutes=${minutes}`);
|
|
}
|
|
|
|
let now: any = new Date();
|
|
let then: any = new Date(datetime);
|
|
|
|
let diff = now - then;
|
|
let diff_minutes = Math.floor(diff / 60000);
|
|
|
|
if (diff_minutes < minutes) {
|
|
return true;
|
|
} else {
|
|
return false;
|
|
}
|
|
} |