Skip to content

Commit

Permalink
Adds defaultDateShortFormat setting
Browse files Browse the repository at this point in the history
Changes fetch date to  respect date settings
  • Loading branch information
eamodio committed Dec 26, 2018
1 parent db68af2 commit 24b0247
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 12 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,14 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this p

## [Unreleased]

### Added

- Adds `gitlens.defaultDateShortFormat` setting to specify how short absolute dates will be formatted by default

### Changed

- 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

### Fixed

- Fixes [#605](https://github.com/eamodio/vscode-gitlens/issues/605) — Show More Commits not working
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -655,6 +655,7 @@ GitLens is highly customizable and provides many configuration settings to allow
| Name | Description |
| ------------------------------------ | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `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 |
| `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 |
| `gitlens.defaultDateStyle` | Specifies how dates will be displayed by default |
| `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 |
| `gitlens.insiders` | Specifies whether to enable experimental features |
Expand Down
6 changes: 6 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,12 @@
"markdownDescription": "Specifies how absolute dates will be formatted by default. See the [Moment.js docs](https://momentjs.com/docs/#/displaying/format/) for valid formats",
"scope": "window"
},
"gitlens.defaultDateShortFormat": {
"type": "string",
"default": null,
"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",
"scope": "window"
},
"gitlens.defaultDateStyle": {
"type": "string",
"default": "relative",
Expand Down
2 changes: 1 addition & 1 deletion src/ui/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export interface Config {
codeLens: CodeLensConfig;
debug: boolean;
defaultDateFormat: string | null;
defaultDateShortFormat: string | null;
defaultDateStyle: DateStyle;
defaultGravatarsStyle: GravatarDefaultStyle;
heatmap: {
Expand Down Expand Up @@ -367,7 +368,6 @@ export interface ViewsConfig {
commitDescriptionFormat: string;
commitFormat: string;
compare: CompareViewConfig;
// dateFormat: string | null;
defaultItemLimit: number;
lineHistory: LineHistoryViewConfig;
repositories: RepositoriesViewConfig;
Expand Down
17 changes: 17 additions & 0 deletions src/ui/settings/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,23 @@ <h3 class="settings-group__header">Default Date/Time Display</h3>
<i class="icon icon__info"></i>
</a>
</div>
<div class="settings-group__setting nowrap">
<label for="defaultDateShortFormat">Absolute&nbsp;short&nbsp;date&nbsp;format</label>
<input
class="setting"
id="defaultDateShortFormat"
name="defaultDateShortFormat"
type="text"
placeholder="MMM D, YYYY"
/>
<a
class="link__learn-more"
title="See Moment.js docs for valid date formats"
href="https://momentjs.com/docs/#/displaying/format/"
>
<i class="icon icon__info"></i>
</a>
</div>
</div>

<h3 class="settings-group__header">Keyboard Shortcuts</h3>
Expand Down
26 changes: 15 additions & 11 deletions src/views/nodes/repositoryNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
RepositoryFileSystemChangeEvent
} from '../../git/gitService';
import { Dates, debug, Functions, gate, log, Strings } from '../../system';
import { DateStyle } from '../../ui/config';
import { RepositoriesView } from '../repositoriesView';
import { BranchesNode } from './branchesNode';
import { BranchNode } from './branchNode';
Expand Down Expand Up @@ -97,7 +98,7 @@ export class RepositoryNode extends SubscribeableViewNode<RepositoriesView> {

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

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

if (Container.config.defaultDateStyle === DateStyle.Relative) {
disposables.push(Functions.interval(() => void this.updateLastFetched(), 60000));
}

if (this.includeWorkingTree) {
disposables.push(
this.repo.onDidChangeFileSystem(this.onFileSystemChanged, this),
{
dispose: () => this.repo.stopWatchingFileSystem()
},
Functions.interval(() => void this.updateLastFetched(), 60000)
);
disposables.push(this.repo.onDidChangeFileSystem(this.onFileSystemChanged, this), {
dispose: () => this.repo.stopWatchingFileSystem()
});

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

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

return `${options.prefix || ''}${Dates.toFormatter(new Date(this._lastFetched)).format(
options.format || 'MMM DD, YYYY'
options.format || Container.config.defaultDateShortFormat || 'MMM D, YYYY'
)}`;
}

Expand Down

0 comments on commit 24b0247

Please sign in to comment.