From 1be77ad9cc5e2f0c387e9e6b969a4a070f29923f Mon Sep 17 00:00:00 2001 From: Pablo Costa Date: Fri, 15 Dec 2023 15:38:24 -0300 Subject: [PATCH 1/2] Parse Backup file date from file name --- site/gatsby-site/src/templates/backups.js | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/site/gatsby-site/src/templates/backups.js b/site/gatsby-site/src/templates/backups.js index 95754aaa76..f6850eb765 100644 --- a/site/gatsby-site/src/templates/backups.js +++ b/site/gatsby-site/src/templates/backups.js @@ -15,6 +15,22 @@ const Backups = ({ pageContext, ...props }) => { return null; } + const parseCreationDate = (key) => { + const stringDate = key.split('backup-')[1].split('.')[0]; + + const year = stringDate.substring(0, 4); + + const month = stringDate.substring(4, 6); + + const day = stringDate.substring(6, 8); + + const hour = stringDate.substring(8, 10); + + const minute = stringDate.substring(10, 12); + + return new Date(year, month - 1, day, hour, minute); + }; + return ( <> @@ -65,10 +81,11 @@ const Backups = ({ pageContext, ...props }) => { .map((b) => ({ ...b, Url: `${config.cloudflareR2.publicBucketUrl}/${b.Key}`, + CreationDate: parseCreationDate(b.Key), })) .map((value) => (
  • - {format(new Date(value['LastModified']), 'yyyy-MM-dd hh:mm a')} ·{' '} + {format(new Date(value['CreationDate']), 'yyyy-MM-dd hh:mm a')} ·{' '} {(value['Size'] / 1000000).toFixed(2)} MB ·{' '} {value['Key']}
  • From 1a400a83318bd3506a79f1bf21058d22d9572957 Mon Sep 17 00:00:00 2001 From: Pablo Costa Date: Thu, 4 Jan 2024 20:03:30 -0300 Subject: [PATCH 2/2] Add the expected input format/example input for `parseCreationDate` function --- site/gatsby-site/src/templates/backups.js | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/site/gatsby-site/src/templates/backups.js b/site/gatsby-site/src/templates/backups.js index f6850eb765..1839193505 100644 --- a/site/gatsby-site/src/templates/backups.js +++ b/site/gatsby-site/src/templates/backups.js @@ -15,6 +15,15 @@ const Backups = ({ pageContext, ...props }) => { return null; } + /** + * Parses the creation date from the backup key. + * + * The expected format of the key is "backup-YYYYMMDDHHmmss.tar.bz2" (e.g. "backup-20240101101425.tar.bz2"). + * The function extracts the date and time from the key and returns a JavaScript Date object. + * + * @param {string} key - The backup key. + * @returns {Date} The creation date of the backup. + */ const parseCreationDate = (key) => { const stringDate = key.split('backup-')[1].split('.')[0];