Skip to content

Commit e62c430

Browse files
author
Eric Amodio
committed
Removes day.js dependency; uses Intl instead
1 parent fc7ac81 commit e62c430

3 files changed

Lines changed: 6 additions & 21 deletions

File tree

extensions/git/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1808,7 +1808,6 @@
18081808
},
18091809
"dependencies": {
18101810
"byline": "^5.0.0",
1811-
"dayjs": "1.8.19",
18121811
"file-type": "^7.2.0",
18131812
"iconv-lite": "^0.4.24",
18141813
"jschardet": "2.1.1",

extensions/git/src/timelineProvider.ts

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,13 @@
44
*--------------------------------------------------------------------------------------------*/
55

66
import * as nls from 'vscode-nls';
7-
import * as dayjs from 'dayjs';
8-
import * as advancedFormat from 'dayjs/plugin/advancedFormat';
9-
import { CancellationToken, Disposable, Event, EventEmitter, ThemeIcon, Timeline, TimelineChangeEvent, TimelineItem, TimelineOptions, TimelineProvider, Uri, workspace } from 'vscode';
7+
import { CancellationToken, Disposable, env, Event, EventEmitter, ThemeIcon, Timeline, TimelineChangeEvent, TimelineItem, TimelineOptions, TimelineProvider, Uri, workspace } from 'vscode';
108
import { Model } from './model';
119
import { Repository, Resource } from './repository';
1210
import { debounce } from './decorators';
1311

14-
dayjs.extend(advancedFormat);
15-
1612
const localize = nls.loadMessageBundle();
1713

18-
// TODO@eamodio: Localize or use a setting for date format
19-
2014
export class GitTimelineItem extends TimelineItem {
2115
static is(item: TimelineItem): item is GitTimelineItem {
2216
return item instanceof GitTimelineItem;
@@ -145,16 +139,15 @@ export class GitTimelineProvider implements TimelineProvider {
145139
commits.splice(commits.length - 1, 1);
146140
}
147141

148-
let dateFormatter: dayjs.Dayjs;
142+
const dateFormatter = new Intl.DateTimeFormat(env.language, { year: 'numeric', month: 'long', day: 'numeric', hour: 'numeric', minute: 'numeric' });
143+
149144
const items = commits.map<GitTimelineItem>((c, i) => {
150145
const date = c.commitDate; // c.authorDate
151146

152-
dateFormatter = dayjs(date);
153-
154147
const item = new GitTimelineItem(c.hash, commits[i + 1]?.hash ?? `${c.hash}^`, c.message, date?.getTime() ?? 0, c.hash, 'git:file:commit');
155148
item.iconPath = new (ThemeIcon as any)('git-commit');
156149
item.description = c.authorName;
157-
item.detail = `${c.authorName} (${c.authorEmail}) \u2014 ${c.hash.substr(0, 8)}\n${dateFormatter.format('MMMM Do, YYYY h:mma')}\n\n${c.message}`;
150+
item.detail = `${c.authorName} (${c.authorEmail}) \u2014 ${c.hash.substr(0, 8)}\n${dateFormatter.format(date)}\n\n${c.message}`;
158151
item.command = {
159152
title: 'Open Comparison',
160153
command: 'git.timeline.openDiff',
@@ -170,13 +163,12 @@ export class GitTimelineProvider implements TimelineProvider {
170163
const index = repo.indexGroup.resourceStates.find(r => r.resourceUri.fsPath === uri.fsPath);
171164
if (index) {
172165
const date = this.repoStatusDate ?? new Date();
173-
dateFormatter = dayjs(date);
174166

175167
const item = new GitTimelineItem('~', 'HEAD', localize('git.timeline.stagedChanges', 'Staged Changes'), date.getTime(), 'index', 'git:file:index');
176168
// TODO@eamodio: Replace with a better icon -- reflecting its status maybe?
177169
item.iconPath = new (ThemeIcon as any)('git-commit');
178170
item.description = '';
179-
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));
171+
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));
180172
item.command = {
181173
title: 'Open Comparison',
182174
command: 'git.timeline.openDiff',
@@ -189,13 +181,12 @@ export class GitTimelineProvider implements TimelineProvider {
189181
const working = repo.workingTreeGroup.resourceStates.find(r => r.resourceUri.fsPath === uri.fsPath);
190182
if (working) {
191183
const date = new Date();
192-
dateFormatter = dayjs(date);
193184

194185
const item = new GitTimelineItem('', index ? '~' : 'HEAD', localize('git.timeline.uncommitedChanges', 'Uncommited Changes'), date.getTime(), 'working', 'git:file:working');
195186
// TODO@eamodio: Replace with a better icon -- reflecting its status maybe?
196187
item.iconPath = new (ThemeIcon as any)('git-commit');
197188
item.description = '';
198-
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));
189+
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));
199190
item.command = {
200191
title: 'Open Comparison',
201192
command: 'git.timeline.openDiff',

extensions/git/yarn.lock

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -185,11 +185,6 @@ dashdash@^1.12.0:
185185
dependencies:
186186
assert-plus "^1.0.0"
187187

188-
dayjs@1.8.19:
189-
version "1.8.19"
190-
resolved "https://registry.yarnpkg.com/dayjs/-/dayjs-1.8.19.tgz#5117dc390d8f8e586d53891dbff3fa308f51abfe"
191-
integrity sha512-7kqOoj3oQSmqbvtvGFLU5iYqies+SqUiEGNT0UtUPPxcPYgY1BrkXR0Cq2R9HYSimBXN+xHkEN4Hi399W+Ovlg==
192-
193188
debug@2.6.8:
194189
version "2.6.8"
195190
resolved "https://registry.yarnpkg.com/debug/-/debug-2.6.8.tgz#e731531ca2ede27d188222427da17821d68ff4fc"

0 commit comments

Comments
 (0)