Images Table: Add clones table for AWS composes

This commit is contained in:
lucasgarfield 2022-10-24 16:10:24 +02:00 committed by Sanne Raymaekers
parent ed9325615c
commit 5c37e3b45b
11 changed files with 419 additions and 217 deletions

View file

@ -1,15 +1,3 @@
export const timestampToISO8601 = (timestamp) => {
if (!timestamp) {
return '';
}
const date = timestamp.slice(0, 10);
const time = timestamp.slice(11, 26);
return `${date}T${time}+0000`;
};
export const timestampToDisplayString = (ts) => {
// timestamp has format 2021-04-27 12:31:12.794809 +0000 UTC
// must be converted to ms timestamp and then reformatted to Apr 27, 2021
@ -24,3 +12,30 @@ export const timestampToDisplayString = (ts) => {
const tsDisplay = new Intl.DateTimeFormat('en-US', options).format(ms);
return tsDisplay;
};
export const convertStringToDate = (createdAtAsString) => {
if (isNaN(Date.parse(createdAtAsString))) {
// converts property created_at of the image object from string to UTC
const [dateValues, timeValues] = createdAtAsString.split(' ');
const datetimeString = `${dateValues}T${timeValues}Z`;
return Date.parse(datetimeString);
} else {
return Date.parse(createdAtAsString);
}
};
export const hoursToExpiration = (imageCreatedAt) => {
if (imageCreatedAt) {
const currentTime = Date.now();
// miliseconds in hour - needed for calculating the difference
// between current date and the date of the image creation
const msInHour = 1000 * 60 * 60;
const timeUntilExpiration = Math.floor(
(currentTime - convertStringToDate(imageCreatedAt)) / msInHour
);
return timeUntilExpiration;
} else {
// when creating a new image, the compose.created_at can be undefined when first queued
return 0;
}
};