Skip to content

Commit 1193eeb

Browse files
oritwoenharlan-zw
andauthored
refactor: reuse current ISO date helper (#72)
Co-authored-by: Harlan Wilton <harlan@harlanzw.com>
1 parent 132cfdf commit 1193eeb

8 files changed

Lines changed: 32 additions & 12 deletions

File tree

src/agent/prompts/skill.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import type { FeaturesConfig } from '../../core/config.ts'
66
import { writeFileSync } from 'node:fs'
77
import { join } from 'pathe'
8+
import { todayIsoDate } from '../../core/formatting.ts'
89
import { repairMarkdown, sanitizeMarkdown } from '../../core/sanitize.ts'
910
import { resolveSkilldCommand } from '../../core/shared.ts'
1011
import { yamlEscape } from '../../core/yaml.ts'
@@ -232,7 +233,7 @@ function generateFrontmatter({ name, version, description: pkgDescription, globs
232233
metaEntries.push(` version: ${yamlEscape(version)}`)
233234
if (body && generatedBy)
234235
metaEntries.push(` generated_by: ${yamlEscape(generatedBy)}`)
235-
metaEntries.push(` generated_at: ${new Date().toISOString().split('T')[0]}`)
236+
metaEntries.push(` generated_at: ${todayIsoDate()}`)
236237
if (metaEntries.length) {
237238
lines.push('metadata:')
238239
lines.push(...metaEntries)

src/commands/prepare.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import { defineCommand } from 'citty'
1313
import { join } from 'pathe'
1414
import { agents, linkSkillToAgents } from '../agent/index.ts'
1515
import { resolveAgent } from '../cli-helpers.ts'
16+
import { todayIsoDate } from '../core/formatting.ts'
1617
import { readLock, writeLock } from '../core/lockfile.ts'
1718
import { getShippedSkills, linkShippedSkill, restorePkgSymlink } from '../core/prepare.ts'
1819
import { getSharedSkillsDir } from '../core/shared.ts'
@@ -91,7 +92,7 @@ export const prepareCommandDef = defineCommand({
9192
packageName: entry.packageName,
9293
version,
9394
source: 'shipped',
94-
syncedAt: new Date().toISOString().split('T')[0],
95+
syncedAt: todayIsoDate(),
9596
generator: 'skilld',
9697
})
9798

src/commands/sync-git.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import {
2727
resolvePkgDir,
2828
} from '../cache/index.ts'
2929
import { defaultFeatures, readConfig, registerProject } from '../core/config.ts'
30-
import { timedSpinner } from '../core/formatting.ts'
30+
import { timedSpinner, todayIsoDate } from '../core/formatting.ts'
3131
import { writeLock } from '../core/lockfile.ts'
3232
import { sanitizeMarkdown } from '../core/sanitize.ts'
3333
import { getSharedSkillsDir } from '../core/shared.ts'
@@ -154,7 +154,7 @@ export async function syncGitSkills(opts: GitSyncOptions): Promise<void> {
154154
repo: source.type === 'local' ? source.localPath : `${source.owner}/${source.repo}`,
155155
path: skill.path || undefined,
156156
ref: source.ref || 'main',
157-
syncedAt: new Date().toISOString().split('T')[0],
157+
syncedAt: todayIsoDate(),
158158
generator: 'external',
159159
})
160160
}
@@ -271,7 +271,7 @@ async function syncGitHubRepo(opts: GitSyncOptions): Promise<void> {
271271
version,
272272
repo: `${owner}/${repo}`,
273273
source: resources.docSource,
274-
syncedAt: new Date().toISOString().split('T')[0],
274+
syncedAt: todayIsoDate(),
275275
generator: 'skilld',
276276
})
277277

src/commands/sync-parallel.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ import {
3232
resolvePkgDir,
3333
} from '../cache/index.ts'
3434
import { defaultFeatures, readConfig, registerProject } from '../core/config.ts'
35-
import { formatDuration } from '../core/formatting.ts'
35+
import { formatDuration, todayIsoDate } from '../core/formatting.ts'
3636
import { parsePackageNames, parsePackages, readLock, writeLock } from '../core/lockfile.ts'
3737
import { parseFrontmatter } from '../core/markdown.ts'
3838
import { getSharedSkillsDir, semverDiff, SHARED_SKILLS_DIR } from '../core/shared.ts'
@@ -566,7 +566,7 @@ async function syncBaseSkill(
566566
version,
567567
repo: repoSlug,
568568
source: resources.docSource,
569-
syncedAt: new Date().toISOString().split('T')[0],
569+
syncedAt: todayIsoDate(),
570570
generator: 'skilld',
571571
})
572572

src/commands/sync-shared.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ import {
3636
} from '../cache/index.ts'
3737
import { isInteractive, NO_MODELS_MESSAGE, pickModel } from '../cli-helpers.ts'
3838
import { defaultFeatures, readConfig, registerProject, updateConfig } from '../core/config.ts'
39+
import { todayIsoDate } from '../core/formatting.ts'
3940
import { parsePackages, readLock, writeLock } from '../core/lockfile.ts'
4041
import { parseFrontmatter } from '../core/markdown.ts'
4142
import { readPackageJsonSafe } from '../core/package-json.ts'
@@ -239,7 +240,7 @@ export function handleShippedSkills(
239240
packageName,
240241
version,
241242
source: 'shipped',
242-
syncedAt: new Date().toISOString().split('T')[0],
243+
syncedAt: todayIsoDate(),
243244
generator: 'skilld',
244245
})
245246
}

src/commands/sync.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ import {
3535
} from '../cache/index.ts'
3636
import { getInstalledGenerators, introLine, isInteractive, promptForAgent, resolveAgent, sharedArgs, suggestPrepareHook } from '../cli-helpers.ts'
3737
import { defaultFeatures, hasCompletedWizard, readConfig, registerProject } from '../core/config.ts'
38-
import { timedSpinner } from '../core/formatting.ts'
38+
import { timedSpinner, todayIsoDate } from '../core/formatting.ts'
3939
import { parsePackageNames, parsePackages, readLock, removeLockEntry, writeLock } from '../core/lockfile.ts'
4040
import { parseFrontmatter } from '../core/markdown.ts'
4141
import { parseSkillInput, resolveSkillName, toStoragePackageName } from '../core/prefix.ts'
@@ -467,7 +467,7 @@ async function syncSinglePackage(packageSpec: string, config: SyncConfig): Promi
467467
version,
468468
repo: repoSlug,
469469
source: existingLock.source,
470-
syncedAt: new Date().toISOString().split('T')[0],
470+
syncedAt: todayIsoDate(),
471471
generator: 'skilld',
472472
})
473473

@@ -579,7 +579,7 @@ async function syncSinglePackage(packageSpec: string, config: SyncConfig): Promi
579579
version,
580580
repo: repoSlug,
581581
source: resources.docSource,
582-
syncedAt: new Date().toISOString().split('T')[0],
582+
syncedAt: todayIsoDate(),
583583
generator: 'skilld',
584584
})
585585

@@ -1255,7 +1255,7 @@ export async function exportPortablePrompts(packageSpec: string, opts: {
12551255
version,
12561256
repo: repoSlug,
12571257
source: resources.docSource,
1258-
syncedAt: new Date().toISOString().split('T')[0],
1258+
syncedAt: todayIsoDate(),
12591259
generator: 'skilld',
12601260
})
12611261

src/core/formatting.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@ import type { SearchSnippet } from '../retriv/index.ts'
22
import type { ProjectState } from './skills.ts'
33
import * as p from '@clack/prompts'
44

5+
export function todayIsoDate(): string {
6+
return new Date().toISOString().split('T')[0]!
7+
}
8+
59
export function timeAgo(iso?: string): string {
610
if (!iso)
711
return ''

test/unit/formatting.test.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { describe, expect, it, vi } from 'vitest'
2+
import { todayIsoDate } from '../../src/core/formatting'
3+
4+
describe('formatting', () => {
5+
it('formats the current UTC day as YYYY-MM-DD', () => {
6+
vi.useFakeTimers()
7+
vi.setSystemTime(new Date('2026-04-28T23:59:59.000Z'))
8+
9+
expect(todayIsoDate()).toBe('2026-04-28')
10+
11+
vi.useRealTimers()
12+
})
13+
})

0 commit comments

Comments
 (0)