Skip to content

Commit

Permalink
Properly pluralize durations (#228)
Browse files Browse the repository at this point in the history
  • Loading branch information
benwerd committed Sep 7, 2018
1 parent 64583c9 commit be453a7
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 1 deletion.
1 change: 1 addition & 0 deletions unlock-app/src/__tests__/utils/duration.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ describe('durations', () => {
it('should return the right durations in English', () => {
expect(durationsAsTextFromSeconds(0)).toEqual('')
expect(durationsAsTextFromSeconds(1)).toEqual('1 second')
expect(durationsAsTextFromSeconds(0.5)).toEqual('0.5 seconds')
expect(durationsAsTextFromSeconds(123)).toEqual('2 minutes and 3 seconds')
expect(durationsAsTextFromSeconds(60*60)).toEqual('1 hour')
expect(durationsAsTextFromSeconds(60 * 60 * 24 * 265 + 60 * 60 * 27 + 60 * 58 + 8797)).toEqual('266 days, 6 hours, 24 minutes and 37 seconds')
Expand Down
2 changes: 1 addition & 1 deletion unlock-app/src/utils/durations.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export function durations(seconds, intervals) {
export function durationsAsTextFromSeconds(seconds) {
const d = durations(seconds, {})
const asArrayOfValues = Object.keys(d).map(duration => {
if (d[duration] > 1) {
if (d[duration] != 1) { // Singular should only be used when there is exactly 1; otherwise plural is needed
return `${d[duration]} ${duration}`
}
return `${d[duration]} ${duration.slice(0, -1)}` // remove the s!
Expand Down

0 comments on commit be453a7

Please sign in to comment.