Skip to content

Commit

Permalink
Removes day.js dependency; uses Intl instead
Browse files Browse the repository at this point in the history
  • Loading branch information
Eric Amodio committed Mar 26, 2020
1 parent fc7ac81 commit e62c430
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 21 deletions.
1 change: 0 additions & 1 deletion extensions/git/package.json
Expand Up @@ -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",
Expand Down
21 changes: 6 additions & 15 deletions extensions/git/src/timelineProvider.ts
Expand Up @@ -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;
Expand Down Expand Up @@ -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<GitTimelineItem>((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',
Expand All @@ -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',
Expand All @@ -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',
Expand Down
5 changes: 0 additions & 5 deletions extensions/git/yarn.lock
Expand Up @@ -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"
Expand Down

0 comments on commit e62c430

Please sign in to comment.