diff --git a/src/lib/generate-date.ts b/src/lib/generate-date.ts new file mode 100644 index 0000000..79aca81 --- /dev/null +++ b/src/lib/generate-date.ts @@ -0,0 +1,18 @@ +import * as debugLib from 'debug'; +const debug = debugLib('snyk:generate-data-script'); + +export function getDate(): string { + let date: string; + const d = new Date(); + debug('creating date'); + date = d.getFullYear().toString() + '-'; + date = date + d.getMonth().toString().padStart(2, '0') + '-'; + date = date + d.getDay().toString().padStart(2, '0') + 'T'; + date = date + d.getHours().toString().padStart(2, '0') + ':'; + date = date + d.getMinutes().toString().padStart(2, '0') + ':'; + date = date + d.getSeconds().toString().padStart(2, '0') + 'Z'; + + debug(date); + + return date; +} diff --git a/src/lib/index.ts b/src/lib/index.ts index d9709ff..e1ec6d8 100644 --- a/src/lib/index.ts +++ b/src/lib/index.ts @@ -3,6 +3,7 @@ import { SnykIssue, SnykTestOutput, SPDXv3, Profile } from '../types'; import { convertSnykIssueToSpdx } from './convert-issue-to-spdx'; import { generateDocumentNameSpace } from './generate-document-namespace'; export { getInputData } from './get-input-data'; +import { getDate } from './generate-date'; export function convertSnykTestOutputToSPDX(data: SnykTestOutput): SPDXv3 { const outputFileName = data.projectName; @@ -15,7 +16,7 @@ export function convertSnykTestOutputToSPDX(data: SnykTestOutput): SPDXv3 { creator: 'Organization: Snyk Ltd', documentNamespace: generateDocumentNameSpace(outputFileName), description: `Snyk test result for project ${data.projectName} in SPDX SBOM format`, - created: Date.now().toString(), + created: getDate(), vulnerabilities: data.vulnerabilities .filter((i: SnykIssue) => i.type == undefined) .map((i: SnykIssue) => convertSnykIssueToSpdx(i)), diff --git a/src/lib/snyk-to-spdx.ts b/src/lib/snyk-to-spdx.ts index a7d4305..c828562 100644 --- a/src/lib/snyk-to-spdx.ts +++ b/src/lib/snyk-to-spdx.ts @@ -1,6 +1,7 @@ import { SnykIssue, SnykTestOutput, SPDXv3, Profile } from '../types'; import { convertSnykIssueToSpdx } from './convert-issue-to-spdx'; import { generateDocumentNameSpace } from './generate-document-namespace'; +import { getDate } from './generate-date'; export function convertSnykTestOutputToSPDX(data: SnykTestOutput): SPDXv3 { const outputFileName = data.projectName; @@ -13,7 +14,7 @@ export function convertSnykTestOutputToSPDX(data: SnykTestOutput): SPDXv3 { creator: 'Organization: Snyk Ltd', documentNamespace: generateDocumentNameSpace(outputFileName), description: `Snyk test result for project ${data.projectName} in SPDX SBOM format`, - created: Date.now().toString(), // TODO: Check the format + created: getDate(), // YYYY-MM-DDThh:mm:ssZ vulnerabilities: data.vulnerabilities.map((i: SnykIssue) => convertSnykIssueToSpdx(i), ),