From 5ad5873dd15817502964c94112870bffdaf56e2c Mon Sep 17 00:00:00 2001 From: Albin Jacobsson Date: Mon, 5 Jun 2017 20:04:42 +0200 Subject: [PATCH] Correct plural/singular for monehts. Closes #16 --- src/textdecorator.ts | 2 +- test/extension.test.ts | 7 ++++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/textdecorator.ts b/src/textdecorator.ts index ca048b57..2a861563 100644 --- a/src/textdecorator.ts +++ b/src/textdecorator.ts @@ -41,7 +41,7 @@ export class TextDecorator { return days + ' days ago'; } else { - return months + ' months ago'; + return months + ' ' + (months === 1 ? 'month' : 'months') + ' ago'; } } diff --git a/test/extension.test.ts b/test/extension.test.ts index 112a6bdf..07e8535b 100644 --- a/test/extension.test.ts +++ b/test/extension.test.ts @@ -1,4 +1,4 @@ -// +// // Note: This example test is leveraging the Mocha test framework. // Please refer to their documentation on https://mochajs.org/ for help. // @@ -15,10 +15,15 @@ suite('GitBlame Tests', () => { test('Date Calculations', () => { assert.equal('3 months ago', TextDecorator.toDateText(new Date(2015, 4), new Date(2015, 1))); + assert.equal('1 month ago', TextDecorator.toDateText(new Date(2015, 2, 20), new Date(2015, 1))); assert.equal('4 days ago', TextDecorator.toDateText(new Date(2015, 1, 5), new Date(2015, 1, 1))); assert.equal('2 hours ago', TextDecorator.toDateText(new Date(2015, 1, 1, 3, 0, 0), new Date(2015, 1, 1, 1, 0, 0))); assert.equal('30 minutes ago', TextDecorator.toDateText(new Date(2015, 1, 1, 1, 30, 0), new Date(2015, 1, 1, 1, 0, 0))); assert.equal('right now', TextDecorator.toDateText(new Date(2015, 1, 1, 1, 1, 0), new Date(2015, 1, 1, 1, 0, 0))); + + assert.notEqual('1 days ago', TextDecorator.toDateText(new Date(2015, 1, 2), new Date(2015, 1, 1))); + assert.notEqual('1 hours ago', TextDecorator.toDateText(new Date(2015, 1, 1, 1, 0, 0), new Date(2015, 1, 1, 0, 0, 0))); + assert.notEqual('1 minutes ago', TextDecorator.toDateText(new Date(2015, 1, 1, 1, 1, 0), new Date(2015, 1, 1, 1, 0, 0))); }); test('Token Parser', () => {