Skip to content

Commit 24b0247

Browse files
committed
Adds defaultDateShortFormat setting
Changes fetch date to respect date settings
1 parent db68af2 commit 24b0247

File tree

6 files changed

+48
-12
lines changed

6 files changed

+48
-12
lines changed

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,14 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this p
66

77
## [Unreleased]
88

9+
### Added
10+
11+
- Adds `gitlens.defaultDateShortFormat` setting to specify how short absolute dates will be formatted by default
12+
13+
### Changed
14+
15+
- Changes the fetch date in the _Repositories_ view to respect the date style setting (`gitlens.defaultDateStyle`) and uses the new `gitlens.defaultDateShortFormat` setting for formatting
16+
917
### Fixed
1018

1119
- Fixes [#605](https://github.com/eamodio/vscode-gitlens/issues/605) — Show More Commits not working

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -655,6 +655,7 @@ GitLens is highly customizable and provides many configuration settings to allow
655655
| Name | Description |
656656
| ------------------------------------ | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
657657
| `gitlens.defaultDateFormat` | Specifies how absolute dates will be formatted by default. See the [Moment.js docs](https://momentjs.com/docs/#/displaying/format/) for valid formats |
658+
| `gitlens.defaultDateShortFormat` | Specifies how short absolute dates will be formatted by default. See the [Moment.js docs](https://momentjs.com/docs/#/displaying/format/) for valid formats |
658659
| `gitlens.defaultDateStyle` | Specifies how dates will be displayed by default |
659660
| `gitlens.defaultGravatarsStyle` | Specifies the style of the gravatar default (fallback) images<br /><br />`identicon` - a geometric pattern<br />`mm` - a simple, cartoon-style silhouetted outline of a person (does not vary by email hash)<br />`monsterid` - a monster with different colors, faces, etc<br />`retro` - 8-bit arcade-style pixelated faces<br />`robohash` - a robot with different colors, faces, etc<br />`wavatar` - a face with differing features and backgrounds |
660661
| `gitlens.insiders` | Specifies whether to enable experimental features |

package.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -419,6 +419,12 @@
419419
"markdownDescription": "Specifies how absolute dates will be formatted by default. See the [Moment.js docs](https://momentjs.com/docs/#/displaying/format/) for valid formats",
420420
"scope": "window"
421421
},
422+
"gitlens.defaultDateShortFormat": {
423+
"type": "string",
424+
"default": null,
425+
"markdownDescription": "Specifies how short absolute dates will be formatted by default. See the [Moment.js docs](https://momentjs.com/docs/#/displaying/format/) for valid formats",
426+
"scope": "window"
427+
},
422428
"gitlens.defaultDateStyle": {
423429
"type": "string",
424430
"default": "relative",

src/ui/config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ export interface Config {
2727
codeLens: CodeLensConfig;
2828
debug: boolean;
2929
defaultDateFormat: string | null;
30+
defaultDateShortFormat: string | null;
3031
defaultDateStyle: DateStyle;
3132
defaultGravatarsStyle: GravatarDefaultStyle;
3233
heatmap: {
@@ -367,7 +368,6 @@ export interface ViewsConfig {
367368
commitDescriptionFormat: string;
368369
commitFormat: string;
369370
compare: CompareViewConfig;
370-
// dateFormat: string | null;
371371
defaultItemLimit: number;
372372
lineHistory: LineHistoryViewConfig;
373373
repositories: RepositoriesViewConfig;

src/ui/settings/index.html

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,23 @@ <h3 class="settings-group__header">Default Date/Time Display</h3>
107107
<i class="icon icon__info"></i>
108108
</a>
109109
</div>
110+
<div class="settings-group__setting nowrap">
111+
<label for="defaultDateShortFormat">Absolute&nbsp;short&nbsp;date&nbsp;format</label>
112+
<input
113+
class="setting"
114+
id="defaultDateShortFormat"
115+
name="defaultDateShortFormat"
116+
type="text"
117+
placeholder="MMM D, YYYY"
118+
/>
119+
<a
120+
class="link__learn-more"
121+
title="See Moment.js docs for valid date formats"
122+
href="https://momentjs.com/docs/#/displaying/format/"
123+
>
124+
<i class="icon icon__info"></i>
125+
</a>
126+
</div>
110127
</div>
111128

112129
<h3 class="settings-group__header">Keyboard Shortcuts</h3>

src/views/nodes/repositoryNode.ts

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import {
1212
RepositoryFileSystemChangeEvent
1313
} from '../../git/gitService';
1414
import { Dates, debug, Functions, gate, log, Strings } from '../../system';
15+
import { DateStyle } from '../../ui/config';
1516
import { RepositoriesView } from '../repositoriesView';
1617
import { BranchesNode } from './branchesNode';
1718
import { BranchNode } from './branchNode';
@@ -97,7 +98,7 @@ export class RepositoryNode extends SubscribeableViewNode<RepositoriesView> {
9798

9899
const lastFetchedTooltip = this.formatLastFetched({
99100
prefix: `${Strings.pad(GlyphChars.Dash, 2, 2)}Last fetched on `,
100-
format: 'dddd MMMM Do, YYYY h:mm a'
101+
format: Container.config.defaultDateFormat || 'dddd MMMM Do, YYYY h:mm a'
101102
});
102103

103104
let description;
@@ -200,14 +201,14 @@ export class RepositoryNode extends SubscribeableViewNode<RepositoriesView> {
200201
protected async subscribe() {
201202
const disposables = [this.repo.onDidChange(this.onRepoChanged, this)];
202203

204+
if (Container.config.defaultDateStyle === DateStyle.Relative) {
205+
disposables.push(Functions.interval(() => void this.updateLastFetched(), 60000));
206+
}
207+
203208
if (this.includeWorkingTree) {
204-
disposables.push(
205-
this.repo.onDidChangeFileSystem(this.onFileSystemChanged, this),
206-
{
207-
dispose: () => this.repo.stopWatchingFileSystem()
208-
},
209-
Functions.interval(() => void this.updateLastFetched(), 60000)
210-
);
209+
disposables.push(this.repo.onDidChangeFileSystem(this.onFileSystemChanged, this), {
210+
dispose: () => this.repo.stopWatchingFileSystem()
211+
});
211212

212213
this.repo.startWatchingFileSystem();
213214
}
@@ -279,12 +280,15 @@ export class RepositoryNode extends SubscribeableViewNode<RepositoriesView> {
279280
private formatLastFetched(options: { prefix?: string; format?: string } = {}) {
280281
if (this._lastFetched === 0) return '';
281282

282-
if (options.format === undefined && Date.now() - this._lastFetched < Dates.MillisecondsPerDay) {
283-
return `${options.prefix || ''}${Dates.toFormatter(new Date(this._lastFetched)).fromNow()}`;
283+
if (options.format === undefined && Container.config.defaultDateStyle === DateStyle.Relative) {
284+
// If less than a day has passed show a relative date
285+
if (Date.now() - this._lastFetched < Dates.MillisecondsPerDay) {
286+
return `${options.prefix || ''}${Dates.toFormatter(new Date(this._lastFetched)).fromNow()}`;
287+
}
284288
}
285289

286290
return `${options.prefix || ''}${Dates.toFormatter(new Date(this._lastFetched)).format(
287-
options.format || 'MMM DD, YYYY'
291+
options.format || Container.config.defaultDateShortFormat || 'MMM D, YYYY'
288292
)}`;
289293
}
290294

0 commit comments

Comments
 (0)