Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parse Backup file date from file name #2497

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
const ExportDropdown = ({ checklist }) => {
const label = (
<>
<FontAwesomeIcon icon={faDownload} className="mr-2"/>
<FontAwesomeIcon icon={faDownload} className="mr-2" />
<Trans>Export</Trans>
</>
);
Expand Down
28 changes: 27 additions & 1 deletion site/gatsby-site/src/templates/backups.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,31 @@ 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) => {
pdcp1 marked this conversation as resolved.
Show resolved Hide resolved
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 (
<>
<AiidHelmet path={props.location.pathname}>
Expand Down Expand Up @@ -65,10 +90,11 @@ const Backups = ({ pageContext, ...props }) => {
.map((b) => ({
...b,
Url: `${config.cloudflareR2.publicBucketUrl}/${b.Key}`,
CreationDate: parseCreationDate(b.Key),
}))
.map((value) => (
<li key={`snapshot-${value['Key']}`}>
{format(new Date(value['LastModified']), 'yyyy-MM-dd hh:mm a')} &middot;{' '}
{format(new Date(value['CreationDate']), 'yyyy-MM-dd hh:mm a')} &middot;{' '}
{(value['Size'] / 1000000).toFixed(2)} MB &middot;{' '}
<Link to={value['Url']}>{value['Key']}</Link>
</li>
Expand Down
Loading