From 563ff04054e86cac347da2b711a579fa8af0ff9b Mon Sep 17 00:00:00 2001 From: regexowl Date: Tue, 7 Jan 2025 15:52:25 +0100 Subject: [PATCH] Wizard: Parse old snapshot dates when editing This updates format of the snapshot date when the blueprint with the old format gets edited. --- .../utilities/requestMapper.ts | 20 ++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/src/Components/CreateImageWizard/utilities/requestMapper.ts b/src/Components/CreateImageWizard/utilities/requestMapper.ts index f0511a28..61b01d1b 100644 --- a/src/Components/CreateImageWizard/utilities/requestMapper.ts +++ b/src/Components/CreateImageWizard/utilities/requestMapper.ts @@ -173,9 +173,27 @@ function commonRequestToState( (image) => image.image_type === 'azure' ); - const snapshot_date = + const snapshotDateFromRequest = request.image_requests.find((image) => !!image.snapshot_date) ?.snapshot_date || ''; + let snapshot_date = ''; + + // Previously DateOnly format of the snapshot date was used (YYYY-MM-DD), + // meaning this is a format that can be present in already existing blueprints. + // Currently used format is RFC3339 (YYYY-MM-DDTHH:MM:SSZ), this condition + // checks which format is getting parsed and converts DateOnly to RFC3339 + // when necessary. + if ( + /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\+\d{2}:\d{2}$/.test( + snapshotDateFromRequest + ) + ) { + snapshot_date = snapshotDateFromRequest; + } else if (/^\d{4}-\d{2}-\d{2}$/.test(snapshotDateFromRequest)) { + snapshot_date = snapshotDateFromRequest + 'T00:00:00+00:00'; + } else { + snapshot_date = ''; + } const awsUploadOptions = aws?.upload_request .options as AwsUploadRequestOptions;