From ccfefa279fe0fd2ad76c568bdcdd2353563f5dfd Mon Sep 17 00:00:00 2001 From: Marc Durdin Date: Tue, 12 Sep 2023 09:26:03 +0100 Subject: [PATCH] chore: make const for date format --- developer/src/kmc/src/util/getLastGitCommitDate.ts | 5 ++++- developer/src/kmc/test/test-getLastGitCommitDate.ts | 4 ++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/developer/src/kmc/src/util/getLastGitCommitDate.ts b/developer/src/kmc/src/util/getLastGitCommitDate.ts index 7cc730227e..645fcc6820 100644 --- a/developer/src/kmc/src/util/getLastGitCommitDate.ts +++ b/developer/src/kmc/src/util/getLastGitCommitDate.ts @@ -1,5 +1,8 @@ import { execFileSync } from 'child_process'; +// RFC3339 pattern, UTC +export const expectedGitDateFormat = /^\d\d\d\d-\d\d-\d\dT\d\d:\d\d:\d\dZ$/; + /** * Returns the date and time of the last commit from git for the passed in path * @param path Path for which to retrieve the last commit message @@ -37,7 +40,7 @@ export function getLastGitCommitDate(path: string): string { // We'll only return the result if it walks like a date, swims like a date, // and quacks like a date. - if (!result.match(/^\d\d\d\d-\d\d-\d\dT\d\d:\d\d:\d\dZ$/)) { + if (!result.match(expectedGitDateFormat)) { return null; } diff --git a/developer/src/kmc/test/test-getLastGitCommitDate.ts b/developer/src/kmc/test/test-getLastGitCommitDate.ts index 69c2e92f5d..3497ef309d 100644 --- a/developer/src/kmc/test/test-getLastGitCommitDate.ts +++ b/developer/src/kmc/test/test-getLastGitCommitDate.ts @@ -1,13 +1,13 @@ import { assert } from 'chai'; import 'mocha'; import { makePathToFixture } from './helpers/index.js'; -import { getLastGitCommitDate } from '../src/util/getLastGitCommitDate.js'; +import { expectedGitDateFormat, getLastGitCommitDate } from '../src/util/getLastGitCommitDate.js'; describe('getLastGitCommitDate', function () { it('should return a valid date for a folder in this repo', async function() { const path = makePathToFixture('.'); const date = getLastGitCommitDate(path); - assert.match(date, /^\d\d\d\d-\d\d-\d\dT\d\d:\d\d:\d\dZ$/); + assert.match(date, expectedGitDateFormat); }); it('should return null for a folder outside the repo', async function() {