Skip to content

Commit

Permalink
Removes dayjs & uses platform Intl formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
eamodio committed Jan 3, 2022
1 parent 6148927 commit 76e9abd
Show file tree
Hide file tree
Showing 11 changed files with 267 additions and 180 deletions.
3 changes: 1 addition & 2 deletions package.json
Expand Up @@ -10135,7 +10135,6 @@
"@octokit/graphql": "4.8.0",
"@vscode/codicons": "0.0.27",
"chroma-js": "2.1.2",
"dayjs": "1.10.7",
"iconv-lite": "0.6.3",
"lodash-es": "4.17.21",
"md5.js": "1.3.5",
Expand Down Expand Up @@ -10166,7 +10165,7 @@
"eslint-config-prettier": "8.3.0",
"eslint-import-resolver-typescript": "2.5.0",
"eslint-plugin-anti-trojan-source": "1.1.0",
"eslint-plugin-import": "2.25.3",
"eslint-plugin-import": "2.25.4",
"fork-ts-checker-webpack-plugin": "6.5.0",
"html-loader": "3.0.1",
"html-webpack-plugin": "5.5.0",
Expand Down
11 changes: 6 additions & 5 deletions src/config.ts
@@ -1,4 +1,5 @@
'use strict';
import { DateTimeFormat } from './system/date';

export const enum OutputLevel {
Silent = 'silent',
Expand All @@ -12,7 +13,7 @@ export interface Config {
blame: {
avatars: boolean;
compact: boolean;
dateFormat: string | null;
dateFormat: DateTimeFormat | string | null;
format: string;
heatmap: {
enabled: boolean;
Expand Down Expand Up @@ -41,12 +42,12 @@ export interface Config {
scrollable: boolean;
};
debug: boolean;
defaultDateFormat: string | null;
defaultDateShortFormat: string | null;
defaultDateFormat: DateTimeFormat | string | null;
defaultDateShortFormat: DateTimeFormat | string | null;
defaultDateSource: DateSource;
defaultDateStyle: DateStyle;
defaultGravatarsStyle: GravatarDefaultStyle;
defaultTimeFormat: string | null;
defaultTimeFormat: DateTimeFormat | string | null;
fileAnnotations: {
command: string | null;
};
Expand Down Expand Up @@ -127,7 +128,7 @@ export interface Config {
statusBar: {
alignment: 'left' | 'right';
command: StatusBarCommand;
dateFormat: string | null;
dateFormat: DateTimeFormat | string | null;
enabled: boolean;
format: string;
reduceFlicker: boolean;
Expand Down
6 changes: 3 additions & 3 deletions src/git/formatters/commitFormatter.ts
Expand Up @@ -87,7 +87,7 @@ export class CommitFormatter extends Formatter<GitCommit, CommitFormatOptions> {
}

private get _authorDateAgoShort() {
return this._item.formatCommitterDateFromNow('en-short');
return this._item.formatCommitterDateFromNow(true);
}

private get _committerDate() {
Expand All @@ -99,7 +99,7 @@ export class CommitFormatter extends Formatter<GitCommit, CommitFormatOptions> {
}

private get _committerDateAgoShort() {
return this._item.formatCommitterDateFromNow('en-short');
return this._item.formatCommitterDateFromNow(true);
}

private get _date() {
Expand All @@ -111,7 +111,7 @@ export class CommitFormatter extends Formatter<GitCommit, CommitFormatOptions> {
}

private get _dateAgoShort() {
return this._item.formatDateFromNow('en-short');
return this._item.formatDateFromNow(true);
}

private get _pullRequestDate() {
Expand Down
12 changes: 6 additions & 6 deletions src/git/models/commit.ts
Expand Up @@ -195,8 +195,8 @@ export abstract class GitCommit implements GitRevisionReference {
return this.authorDateFormatter.format(format);
}

formatAuthorDateFromNow(locale?: string) {
return this.authorDateFormatter.fromNow(locale);
formatAuthorDateFromNow(short?: boolean) {
return this.authorDateFormatter.fromNow(short);
}

@memoize<GitCommit['formatCommitterDate']>(format => (format == null ? 'MMMM Do, YYYY h:mma' : format))
Expand All @@ -208,8 +208,8 @@ export abstract class GitCommit implements GitRevisionReference {
return this.committerDateFormatter.format(format);
}

formatCommitterDateFromNow(locale?: string) {
return this.committerDateFormatter.fromNow(locale);
formatCommitterDateFromNow(short?: boolean) {
return this.committerDateFormatter.fromNow(short);
}

@memoize<GitCommit['formatDate']>(format => (format == null ? 'MMMM Do, YYYY h:mma' : format))
Expand All @@ -221,8 +221,8 @@ export abstract class GitCommit implements GitRevisionReference {
return this.dateFormatter.format(format);
}

formatDateFromNow(locale?: string) {
return this.dateFormatter.fromNow(locale);
formatDateFromNow(short?: boolean) {
return this.dateFormatter.fromNow(short);
}

getFormattedPath(options: { relativeTo?: string; suffix?: string; truncateTo?: number } = {}): string {
Expand Down
4 changes: 2 additions & 2 deletions src/git/models/contributor.ts
Expand Up @@ -86,8 +86,8 @@ export class GitContributor {
return this.dateFormatter.format(format);
}

formatDateFromNow(locale?: string) {
return this.dateFormatter.fromNow(locale);
formatDateFromNow(short?: boolean) {
return this.dateFormatter.fromNow(short);
}

getAvatarUri(options?: { defaultStyle?: GravatarDefaultStyle; size?: number }): Uri | Promise<Uri> {
Expand Down
10 changes: 7 additions & 3 deletions src/git/models/repository.ts
Expand Up @@ -40,6 +40,10 @@ import { GitStash } from './stash';
import { GitStatus } from './status';
import { GitTag, TagSortOptions } from './tag';

const millisecondsPerMinute = 60 * 1000;
const millisecondsPerHour = 60 * 60 * 1000;
const millisecondsPerDay = 24 * 60 * 60 * 1000;

export const enum RepositoryChange {
// FileSystem = 'filesystem',
Unknown = 'unknown',
Expand Down Expand Up @@ -145,7 +149,7 @@ export interface RepositoryFileSystemChangeEvent {
export class Repository implements Disposable {
static formatLastFetched(lastFetched: number, short: boolean = true): string {
const formatter = Dates.getFormatter(new Date(lastFetched));
if (Date.now() - lastFetched < Dates.MillisecondsPerDay) {
if (Date.now() - lastFetched < millisecondsPerDay) {
return formatter.fromNow();
}

Expand All @@ -164,8 +168,8 @@ export class Repository implements Disposable {

static getLastFetchedUpdateInterval(lastFetched: number): number {
const timeDiff = Date.now() - lastFetched;
return timeDiff < Dates.MillisecondsPerDay
? (timeDiff < Dates.MillisecondsPerHour ? Dates.MillisecondsPerMinute : Dates.MillisecondsPerHour) / 2
return timeDiff < millisecondsPerDay
? (timeDiff < millisecondsPerHour ? millisecondsPerMinute : millisecondsPerHour) / 2
: 0;
}

Expand Down

0 comments on commit 76e9abd

Please sign in to comment.