Skip to content

Commit 6f3441a

Browse files
committed
Adds default date format
1 parent 64ae820 commit 6f3441a

File tree

11 files changed

+45
-23
lines changed

11 files changed

+45
-23
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this p
1212
- Improves performance
1313
- Optimized git output parsing to increase speed and reduce memory usage
1414
- Defers diff chunk parsing until it is actually required
15+
- Adds `gitlens.defaultDateFormat` setting to specify how all absolute dates will be formatted by default
1516

1617
### Fixed
1718
- Fixes excessive memory usage when parsing diffs

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,7 @@ GitLens is highly customizable and provides many configuration settings to allow
219219

220220
|Name | Description
221221
|-----|------------
222+
|`gitlens.defaultDateFormat`|Specifies how all absolute dates will be formatted by default\nSee https://momentjs.com/docs/#/displaying/format/ for valid formats
222223
|`gitlens.insiders`|Opts into the insiders channel -- provides access to upcoming features
223224
|`gitlens.outputLevel`|Specifies how much (if any) output will be sent to the GitLens output channel
224225

package.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -402,6 +402,11 @@
402402
"default": false,
403403
"description": "Specifies whether or not to show debug information in code lens"
404404
},
405+
"gitlens.defaultDateFormat": {
406+
"type": "string",
407+
"default": null,
408+
"description": "Specifies how all absolute dates will be formatted by default\nSee https://momentjs.com/docs/#/displaying/format/ for valid formats"
409+
},
405410
"gitlens.statusBar.enabled": {
406411
"type": "boolean",
407412
"default": true,

src/annotations/annotations.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,8 @@ export class Annotations {
5959
} as DecorationOptions;
6060
}
6161

62-
static detailsHover(commit: GitCommit): DecorationOptions {
63-
const message = CommitFormatter.toHoverAnnotation(commit);
62+
static detailsHover(commit: GitCommit, dateFormat: string | null): DecorationOptions {
63+
const message = CommitFormatter.toHoverAnnotation(commit, dateFormat);
6464
return {
6565
hoverMessage: message
6666
} as DecorationOptions;
@@ -127,9 +127,9 @@ export class Annotations {
127127
} as IRenderOptions;
128128
}
129129

130-
static hover(commit: GitCommit, renderOptions: IRenderOptions, heatmap: boolean): DecorationOptions {
130+
static hover(commit: GitCommit, renderOptions: IRenderOptions, heatmap: boolean, dateFormat: string | null): DecorationOptions {
131131
return {
132-
hoverMessage: CommitFormatter.toHoverAnnotation(commit),
132+
hoverMessage: CommitFormatter.toHoverAnnotation(commit, dateFormat),
133133
renderOptions: heatmap ? { before: { ...renderOptions.before } } : undefined
134134
} as DecorationOptions;
135135
}

src/annotations/gutterBlameAnnotationProvider.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,15 @@ export class GutterBlameAnnotationProvider extends BlameAnnotationProviderBase {
2525
}, {} as { [token: string]: ICommitFormatOptions });
2626

2727
const options: ICommitFormatOptions = {
28-
dateFormat: cfg.dateFormat,
28+
dateFormat: cfg.dateFormat === null ? this._config.defaultDateFormat : cfg.dateFormat,
2929
tokenOptions: tokenOptions
3030
};
3131

3232
const now = moment();
3333
const offset = this.uri.offset;
3434
let previousLine: string | undefined = undefined;
3535
const renderOptions = Annotations.gutterRenderOptions(this._config.theme, cfg.heatmap);
36+
const dateFormat = this._config.defaultDateFormat;
3637

3738
const decorations: DecorationOptions[] = [];
3839

@@ -58,7 +59,7 @@ export class GutterBlameAnnotationProvider extends BlameAnnotationProviderBase {
5859
decorations.push(gutter);
5960

6061
if (cfg.hover.details) {
61-
const details = Annotations.detailsHover(commit);
62+
const details = Annotations.detailsHover(commit, dateFormat);
6263
details.range = cfg.hover.wholeLine
6364
? this.editor.document.validateRange(new Range(line, 0, line, endOfLineIndex))
6465
: gutter.range;

src/annotations/hoverBlameAnnotationProvider.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ export class HoverBlameAnnotationProvider extends BlameAnnotationProviderBase {
1818
const now = moment();
1919
const offset = this.uri.offset;
2020
const renderOptions = Annotations.hoverRenderOptions(this._config.theme, cfg.heatmap);
21+
const dateFormat = this._config.defaultDateFormat;
2122

2223
const decorations: DecorationOptions[] = [];
2324

@@ -27,7 +28,7 @@ export class HoverBlameAnnotationProvider extends BlameAnnotationProviderBase {
2728

2829
const line = l.line + offset;
2930

30-
const hover = Annotations.hover(commit, renderOptions, cfg.heatmap.enabled);
31+
const hover = Annotations.hover(commit, renderOptions, cfg.heatmap.enabled, dateFormat);
3132

3233
const endIndex = cfg.wholeLine ? endOfLineIndex : this.editor.document.lineAt(line).firstNonWhitespaceCharacterIndex;
3334
hover.range = this.editor.document.validateRange(new Range(line, 0, line, endIndex));

src/annotations/recentChangesAnnotationProvider.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ export class RecentChangesAnnotationProvider extends AnnotationProviderBase {
2121
if (diff === undefined) return false;
2222

2323
const cfg = this._config.annotations.file.recentChanges;
24+
const dateFormat = this._config.defaultDateFormat;
2425

2526
const decorators: DecorationOptions[] = [];
2627

@@ -42,7 +43,7 @@ export class RecentChangesAnnotationProvider extends AnnotationProviderBase {
4243

4344
if (cfg.hover.details) {
4445
decorators.push({
45-
hoverMessage: CommitFormatter.toHoverAnnotation(commit),
46+
hoverMessage: CommitFormatter.toHoverAnnotation(commit, dateFormat),
4647
range: range
4748
} as DecorationOptions);
4849
}

src/configuration.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ export interface IConfig {
216216
file: {
217217
gutter: {
218218
format: string;
219-
dateFormat: string;
219+
dateFormat: string | null;
220220
compact: boolean;
221221
heatmap: {
222222
enabled: boolean;
@@ -252,7 +252,7 @@ export interface IConfig {
252252

253253
trailing: {
254254
format: string;
255-
dateFormat: string;
255+
dateFormat: string | null;
256256
hover: {
257257
changes: boolean;
258258
details: boolean;
@@ -301,12 +301,14 @@ export interface IConfig {
301301
debug: boolean;
302302
};
303303

304+
defaultDateFormat: string | null;
305+
304306
statusBar: {
305307
enabled: boolean;
306308
alignment: 'left' | 'right';
307309
command: StatusBarCommand;
308310
format: string;
309-
dateFormat: string;
311+
dateFormat: string | null;
310312
};
311313

312314
strings: {

src/currentLineController.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,7 @@ export class CurrentLineController extends Disposable {
291291
showDetailsInStartingWhitespace = true;
292292
}
293293

294-
const decoration = Annotations.trailing(commit, cfgAnnotations.format, cfgAnnotations.dateFormat, this._config.theme);
294+
const decoration = Annotations.trailing(commit, cfgAnnotations.format, cfgAnnotations.dateFormat === null ? this._config.defaultDateFormat : cfgAnnotations.dateFormat, this._config.theme);
295295
decoration.range = editor.document.validateRange(new Range(line, endOfLineIndex, line, endOfLineIndex));
296296
decorationOptions.push(decoration);
297297

@@ -395,7 +395,7 @@ export class CurrentLineController extends Disposable {
395395
// I have no idea why I need this protection -- but it happens
396396
if (editor.document === undefined) return;
397397

398-
const decoration = Annotations.detailsHover(logCommit || commit);
398+
const decoration = Annotations.detailsHover(logCommit || commit, this._config.defaultDateFormat);
399399
decoration.range = editor.document.validateRange(new Range(line, showDetailsStartIndex, line, endOfLineIndex));
400400
decorationOptions.push(decoration);
401401

@@ -429,7 +429,7 @@ export class CurrentLineController extends Disposable {
429429
const cfg = this._config.statusBar;
430430
if (!cfg.enabled || this._statusBarItem === undefined) return;
431431

432-
this._statusBarItem.text = `$(git-commit) ${CommitFormatter.fromTemplate(cfg.format, commit, cfg.dateFormat)}`;
432+
this._statusBarItem.text = `$(git-commit) ${CommitFormatter.fromTemplate(cfg.format, commit, cfg.dateFormat === null ? this._config.defaultDateFormat : cfg.dateFormat)}`;
433433

434434
switch (cfg.command) {
435435
case StatusBarCommand.BlameAnnotate:

src/git/formatters/commit.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,11 @@ export class CommitFormatter {
158158
return Strings.interpolate(template, new CommitFormatter(commit, options));
159159
}
160160

161-
static toHoverAnnotation(commit: GitCommit, dateFormat: string = 'MMMM Do, YYYY h:MMa'): string | string[] {
161+
static toHoverAnnotation(commit: GitCommit, dateFormat: string | null): string | string[] {
162+
if (dateFormat === null) {
163+
dateFormat = 'MMMM Do, YYYY h:MMa';
164+
}
165+
162166
const message = commit.isUncommitted ? '' : `\n\n> ${commit.message.replace(/\n/g, ' \n')}`;
163167
return `\`${commit.shortSha}\`   __${commit.author}__, ${moment(commit.date).fromNow()}   _(${moment(commit.date).format(dateFormat)})_${message}`;
164168
}

0 commit comments

Comments
 (0)