Skip to content

Commit ccfefa2

Browse files
committed
chore: make const for date format
1 parent e9e7d5b commit ccfefa2

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

developer/src/kmc/src/util/getLastGitCommitDate.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
import { execFileSync } from 'child_process';
22

3+
// RFC3339 pattern, UTC
4+
export const expectedGitDateFormat = /^\d\d\d\d-\d\d-\d\dT\d\d:\d\d:\d\dZ$/;
5+
36
/**
47
* Returns the date and time of the last commit from git for the passed in path
58
* @param path Path for which to retrieve the last commit message
@@ -37,7 +40,7 @@ export function getLastGitCommitDate(path: string): string {
3740

3841
// We'll only return the result if it walks like a date, swims like a date,
3942
// and quacks like a date.
40-
if (!result.match(/^\d\d\d\d-\d\d-\d\dT\d\d:\d\d:\d\dZ$/)) {
43+
if (!result.match(expectedGitDateFormat)) {
4144
return null;
4245
}
4346

developer/src/kmc/test/test-getLastGitCommitDate.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import { assert } from 'chai';
22
import 'mocha';
33
import { makePathToFixture } from './helpers/index.js';
4-
import { getLastGitCommitDate } from '../src/util/getLastGitCommitDate.js';
4+
import { expectedGitDateFormat, getLastGitCommitDate } from '../src/util/getLastGitCommitDate.js';
55

66
describe('getLastGitCommitDate', function () {
77
it('should return a valid date for a folder in this repo', async function() {
88
const path = makePathToFixture('.');
99
const date = getLastGitCommitDate(path);
10-
assert.match(date, /^\d\d\d\d-\d\d-\d\dT\d\d:\d\d:\d\dZ$/);
10+
assert.match(date, expectedGitDateFormat);
1111
});
1212

1313
it('should return null for a folder outside the repo', async function() {

0 commit comments

Comments
 (0)