Reworks date parsing, formatting etc for perf

Isolates moment.js
This commit is contained in:
Eric Amodio
2017-09-14 21:33:04 -04:00
parent 11eacb27a1
commit aacf7cc2b5
18 changed files with 87 additions and 42 deletions

View File

@@ -1,5 +1,5 @@
'use strict';
import { Strings } from '../../system';
import { Dates, Strings } from '../../system';
import { Uri } from 'vscode';
import { GlyphChars } from '../../constants';
import { Git } from '../git';
@@ -73,6 +73,22 @@ export class GitCommit {
return Uri.file(path.resolve(this.repoPath, this.originalFileName || this.fileName));
}
private _dateFormatter?: Dates.IDateFormatter;
formatDate(format: string) {
if (this._dateFormatter === undefined) {
this._dateFormatter = Dates.toFormatter(this.date);
}
return this._dateFormatter.format(format);
}
fromNow() {
if (this._dateFormatter === undefined) {
this._dateFormatter = Dates.toFormatter(this.date);
}
return this._dateFormatter.fromNow();
}
getFormattedPath(separator: string = Strings.pad(GlyphChars.Dot, 2, 2)): string {
return GitUri.getFormattedPath(this.fileName, separator);
}