Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions preview-src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*--------------------------------------------------------------------------------------------*/
import './index.css';
import * as debounce from 'debounce';
import * as moment from 'moment';
import { dateFromNow } from '../src/common/utils';
import { EventType } from '../src/common/timelineEvent';
import { PullRequestStateEnum } from '../src/github/interface';
import { renderTimelineEvent, getStatus, renderComment, renderReview, ActionsBar } from './pullRequestOverviewRenderer';
Expand Down Expand Up @@ -116,7 +116,7 @@ function setTitleHTML(pr: PullRequest): void {
<div id="${ElementIds.Status}">${getStatus(pr.state)}</div>
<img class="avatar" src="${pr.author.avatarUrl}" alt="">
<span class="author"><a href="${pr.author.htmlUrl}">${pr.author.login}</a> wants to merge changes from <code>${pr.head}</code> to <code>${pr.base}</code>.</span>
<a href=${pr.url} class="created-at timestamp">${moment(pr.createdAt).fromNow()}</a>
<span class="created-at">Created <a href=${pr.url} class="timestamp">${dateFromNow(pr.createdAt)}</a></span>
</div>
</div>
`;
Expand Down
7 changes: 4 additions & 3 deletions preview-src/pullRequestOverviewRenderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/

import * as moment from 'moment';

import { dateFromNow } from '../src/common/utils';
import { TimelineEvent, CommitEvent, ReviewEvent, CommentEvent, EventType, isCommentEvent } from '../src/common/timelineEvent';
import { PullRequestStateEnum } from '../src/github/interface';
import md from './mdRenderer';
Expand Down Expand Up @@ -262,7 +263,7 @@ class CommentNode {
const timestamp: HTMLAnchorElement = document.createElement('a');
timestamp.className = 'timestamp';
timestamp.href = this._comment.html_url;
timestamp.textContent = moment(this._comment.created_at).fromNow();
timestamp.textContent = dateFromNow(this._comment.created_at);

const commentState = document.createElement('span');
commentState.textContent = 'commented';
Expand Down Expand Up @@ -437,7 +438,7 @@ class ReviewNode {
const timestamp: HTMLAnchorElement = document.createElement('a');
timestamp.className = 'timestamp';
timestamp.href = this._review.html_url;
timestamp.textContent = moment(this._review.submitted_at).fromNow();
timestamp.textContent = dateFromNow(this._review.submitted_at);

commentHeader.appendChild(userLogin);
commentHeader.appendChild(reviewState);
Expand Down
14 changes: 13 additions & 1 deletion src/common/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
'use strict';
import { Event } from 'vscode';
import { sep } from 'path';
import * as moment from 'moment';

export function uniqBy<T>(arr: T[], fn: (el: T) => string): T[] {
const seen = Object.create(null);
Expand Down Expand Up @@ -184,6 +185,17 @@ export async function promiseFromEvent<T, U>(
);
}

export function dateFromNow(date: Date | string): string {
const duration = moment.duration(moment().diff(date));

if (duration.asMonths() < 1) {
return moment(date).fromNow();
} else if (duration.asYears() < 1) {
return 'on ' + moment(date).format('MMM d');
} else {
return 'on ' + moment(date).format('MMM d, YYYY');
}
}
export interface Predicate<T> {
(input: T): boolean;
}
}