diff --git a/README.md b/README.md index 9675347..22479c5 100644 --- a/README.md +++ b/README.md @@ -52,10 +52,10 @@ If set, will limits the return to display a *maximum* number of non-null segment ```js // zero=true -"2 years, 0 month, 12 hours, 57 minutes" +"2 years, 0 months, 12 hours, 57 minutes" // zero=true; max=2 -"2 years, 0 month" +"2 years, 0 months" // zero=false "2 years, 12 hours, 57 minutes" @@ -108,7 +108,7 @@ fromNow("Sun Jun 14 2015 15:14:05"); //=> "2 minutes" fromNow("Sun Jun 14 2015 15:14:05", { zero:true }); -//=> "0 year, 0 month, 0 day, 0 hour, 2 minutes" +//=> "0 years, 0 months, 0 days, 0 hours, 2 minutes" ``` ## Examples diff --git a/src/index.js b/src/index.js index 81d6c74..17d2eb3 100644 --- a/src/index.js +++ b/src/index.js @@ -26,7 +26,7 @@ export default function (date, opts) { if (keep.length < max) { val = Math.floor(periods[k]); if (!val && !opts.zero) continue; - keep.push(val + ' ' + ((val > 1) ? (k + 's') : k)); + keep.push(val + ' ' + ((val == 1) ? k : (k + 's'))); } } diff --git a/test/index.js b/test/index.js index 65a9010..10d1e8d 100644 --- a/test/index.js +++ b/test/index.js @@ -71,10 +71,10 @@ test('fromNow :: options.zero=false', t => { test('fromNow :: options.zero=true', t => { // target = 'Sun Jun 14 2015 15:12:05' - t.is(fn('Sun Jun 14 2015 15:14:05', { zero:true }), '0 year, 0 month, 0 day, 0 hour, 2 minutes'); - t.is(fn('Sun Jun 14 2015 14:09:05', { zero:true, and:true, suffix:true }), '0 year, 0 month, 0 day, 1 hour, and 3 minutes ago'); - t.is(fn('Sun Jun 14 2017 14:09:05', { zero:true, and:true, suffix:true, max:2 }), '2 years and 0 month from now'); - t.is(fn('Sun Jun 14 2015 14:09:05', { zero:true, suffix:true, max:1 }), '0 year ago'); + t.is(fn('Sun Jun 14 2015 15:14:05', { zero:true }), '0 years, 0 months, 0 days, 0 hours, 2 minutes'); + t.is(fn('Sun Jun 14 2015 14:09:05', { zero:true, and:true, suffix:true }), '0 years, 0 months, 0 days, 1 hour, and 3 minutes ago'); + t.is(fn('Sun Jun 14 2017 14:09:05', { zero:true, and:true, suffix:true, max:2 }), '2 years and 0 months from now'); + t.is(fn('Sun Jun 14 2015 14:09:05', { zero:true, suffix:true, max:1 }), '0 years ago'); t.end(); });