From e62c4302b0e4f3e28bbcb0f3b6e46bb00e39679c Mon Sep 17 00:00:00 2001 From: Eric Amodio Date: Thu, 26 Mar 2020 00:10:33 -0400 Subject: [PATCH] Removes day.js dependency; uses Intl instead --- extensions/git/package.json | 1 - extensions/git/src/timelineProvider.ts | 21 ++++++--------------- extensions/git/yarn.lock | 5 ----- 3 files changed, 6 insertions(+), 21 deletions(-) diff --git a/extensions/git/package.json b/extensions/git/package.json index 7077d7e128c..75306b8a785 100644 --- a/extensions/git/package.json +++ b/extensions/git/package.json @@ -1808,7 +1808,6 @@ }, "dependencies": { "byline": "^5.0.0", - "dayjs": "1.8.19", "file-type": "^7.2.0", "iconv-lite": "^0.4.24", "jschardet": "2.1.1", diff --git a/extensions/git/src/timelineProvider.ts b/extensions/git/src/timelineProvider.ts index 23cb39f09b6..da301ffc0aa 100644 --- a/extensions/git/src/timelineProvider.ts +++ b/extensions/git/src/timelineProvider.ts @@ -4,19 +4,13 @@ *--------------------------------------------------------------------------------------------*/ import * as nls from 'vscode-nls'; -import * as dayjs from 'dayjs'; -import * as advancedFormat from 'dayjs/plugin/advancedFormat'; -import { CancellationToken, Disposable, Event, EventEmitter, ThemeIcon, Timeline, TimelineChangeEvent, TimelineItem, TimelineOptions, TimelineProvider, Uri, workspace } from 'vscode'; +import { CancellationToken, Disposable, env, Event, EventEmitter, ThemeIcon, Timeline, TimelineChangeEvent, TimelineItem, TimelineOptions, TimelineProvider, Uri, workspace } from 'vscode'; import { Model } from './model'; import { Repository, Resource } from './repository'; import { debounce } from './decorators'; -dayjs.extend(advancedFormat); - const localize = nls.loadMessageBundle(); -// TODO@eamodio: Localize or use a setting for date format - export class GitTimelineItem extends TimelineItem { static is(item: TimelineItem): item is GitTimelineItem { return item instanceof GitTimelineItem; @@ -145,16 +139,15 @@ export class GitTimelineProvider implements TimelineProvider { commits.splice(commits.length - 1, 1); } - let dateFormatter: dayjs.Dayjs; + const dateFormatter = new Intl.DateTimeFormat(env.language, { year: 'numeric', month: 'long', day: 'numeric', hour: 'numeric', minute: 'numeric' }); + const items = commits.map((c, i) => { const date = c.commitDate; // c.authorDate - dateFormatter = dayjs(date); - const item = new GitTimelineItem(c.hash, commits[i + 1]?.hash ?? `${c.hash}^`, c.message, date?.getTime() ?? 0, c.hash, 'git:file:commit'); item.iconPath = new (ThemeIcon as any)('git-commit'); item.description = c.authorName; - item.detail = `${c.authorName} (${c.authorEmail}) \u2014 ${c.hash.substr(0, 8)}\n${dateFormatter.format('MMMM Do, YYYY h:mma')}\n\n${c.message}`; + item.detail = `${c.authorName} (${c.authorEmail}) \u2014 ${c.hash.substr(0, 8)}\n${dateFormatter.format(date)}\n\n${c.message}`; item.command = { title: 'Open Comparison', command: 'git.timeline.openDiff', @@ -170,13 +163,12 @@ export class GitTimelineProvider implements TimelineProvider { const index = repo.indexGroup.resourceStates.find(r => r.resourceUri.fsPath === uri.fsPath); if (index) { const date = this.repoStatusDate ?? new Date(); - dateFormatter = dayjs(date); const item = new GitTimelineItem('~', 'HEAD', localize('git.timeline.stagedChanges', 'Staged Changes'), date.getTime(), 'index', 'git:file:index'); // TODO@eamodio: Replace with a better icon -- reflecting its status maybe? item.iconPath = new (ThemeIcon as any)('git-commit'); item.description = ''; - item.detail = localize('git.timeline.detail', '{0} \u2014 {1}\n{2}\n\n{3}', you, localize('git.index', 'Index'), dateFormatter.format('MMMM Do, YYYY h:mma'), Resource.getStatusText(index.type)); + item.detail = localize('git.timeline.detail', '{0} \u2014 {1}\n{2}\n\n{3}', you, localize('git.index', 'Index'), dateFormatter.format(date), Resource.getStatusText(index.type)); item.command = { title: 'Open Comparison', command: 'git.timeline.openDiff', @@ -189,13 +181,12 @@ export class GitTimelineProvider implements TimelineProvider { const working = repo.workingTreeGroup.resourceStates.find(r => r.resourceUri.fsPath === uri.fsPath); if (working) { const date = new Date(); - dateFormatter = dayjs(date); const item = new GitTimelineItem('', index ? '~' : 'HEAD', localize('git.timeline.uncommitedChanges', 'Uncommited Changes'), date.getTime(), 'working', 'git:file:working'); // TODO@eamodio: Replace with a better icon -- reflecting its status maybe? item.iconPath = new (ThemeIcon as any)('git-commit'); item.description = ''; - item.detail = localize('git.timeline.detail', '{0} \u2014 {1}\n{2}\n\n{3}', you, localize('git.workingTree', 'Working Tree'), dateFormatter.format('MMMM Do, YYYY h:mma'), Resource.getStatusText(working.type)); + item.detail = localize('git.timeline.detail', '{0} \u2014 {1}\n{2}\n\n{3}', you, localize('git.workingTree', 'Working Tree'), dateFormatter.format(date), Resource.getStatusText(working.type)); item.command = { title: 'Open Comparison', command: 'git.timeline.openDiff', diff --git a/extensions/git/yarn.lock b/extensions/git/yarn.lock index 17866c54593..f72600de7bc 100644 --- a/extensions/git/yarn.lock +++ b/extensions/git/yarn.lock @@ -185,11 +185,6 @@ dashdash@^1.12.0: dependencies: assert-plus "^1.0.0" -dayjs@1.8.19: - version "1.8.19" - resolved "https://registry.yarnpkg.com/dayjs/-/dayjs-1.8.19.tgz#5117dc390d8f8e586d53891dbff3fa308f51abfe" - integrity sha512-7kqOoj3oQSmqbvtvGFLU5iYqies+SqUiEGNT0UtUPPxcPYgY1BrkXR0Cq2R9HYSimBXN+xHkEN4Hi399W+Ovlg== - debug@2.6.8: version "2.6.8" resolved "https://registry.yarnpkg.com/debug/-/debug-2.6.8.tgz#e731531ca2ede27d188222427da17821d68ff4fc"