Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use moment's fromNow formatter #17

Closed
wants to merge 1 commit into from
Closed
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
25 changes: 1 addition & 24 deletions src/textdecorator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,30 +19,7 @@ export class TextDecorator {
}

static toDateText(dateNow: Date, dateThen: Date): string {

const momentNow = moment(dateNow);
const momentThen = moment(dateThen);

const months = momentNow.diff(momentThen, 'months');
const days = momentNow.diff(momentThen, 'days');
const hours = momentNow.diff(momentThen, 'hours');
const minutes = momentNow.diff(momentThen, 'minutes');

if (minutes <= 4) {
return 'right now';
}
else if (minutes <= 70) {
return minutes + ' minutes ago';
}
else if (hours <= 47) {
return hours + ' hours ago';
}
else if (days <= 40) {
return days + ' days ago';
}
else {
return months + ' months ago';
}
return moment(dateThen).fromNow();
}

static parseTokens(target: string, tokens: object = {}): string {
Expand Down