Skip to content

Commit

Permalink
fix pluralization
Browse files Browse the repository at this point in the history
  • Loading branch information
lukeed committed Sep 21, 2018
1 parent 7d4b80f commit e3572d6
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')));
}
}

Expand Down
8 changes: 4 additions & 4 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});

0 comments on commit e3572d6

Please sign in to comment.