-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
43 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import pluralise from './pluralise' | ||
|
||
const periodToString = (years: number, months: number): string => { | ||
let text = '' | ||
|
||
if (years > 0) text += `${years} ${pluralise('year', years)}` | ||
if (years > 0 && months > 0) text += ' and ' | ||
if (months > 0) text += `${months} ${pluralise('month', months)}` | ||
|
||
return text | ||
} | ||
|
||
export default periodToString |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import periodToString from '../../src/utils/periodToString' | ||
import { expect } from 'chai' | ||
|
||
describe('periodToString', () => { | ||
it('returns \'3 years\' when the years are 3 and the months are 0', () => { | ||
const result = periodToString(3, 0) | ||
|
||
expect(result).to.equal('3 years') | ||
}) | ||
|
||
it('returns \'3 months\' when the years are 0 and the months are 3', () => { | ||
const result = periodToString(0, 3) | ||
|
||
expect(result).to.equal('3 months') | ||
}) | ||
|
||
it('returns \'1 year and 1 month\' when the years are 1 and the months are 1', () => { | ||
const result = periodToString(1, 1) | ||
|
||
expect(result).to.equal('1 year and 1 month') | ||
}) | ||
|
||
it('returns \'3 years and 3 months\' when the years are 3 and the months are 3', () => { | ||
const result = periodToString(3, 3) | ||
|
||
expect(result).to.equal('3 years and 3 months') | ||
}) | ||
}) |