Skip to content

Commit

Permalink
feat: add en-CA locale
Browse files Browse the repository at this point in the history
  • Loading branch information
Mark Owsiak committed Feb 13, 2018
1 parent 21c2c63 commit 4284f06
Show file tree
Hide file tree
Showing 10 changed files with 956 additions and 0 deletions.
91 changes: 91 additions & 0 deletions src/locale/en-CA/_lib/formatDistance/index.js
@@ -0,0 +1,91 @@
var formatDistanceLocale = {
lessThanXSeconds: {
one: 'less than a second',
other: 'less than {{count}} seconds'
},

xSeconds: {
one: 'a few seconds',
other: '{{count}} seconds'
},

halfAMinute: 'half a minute',

lessThanXMinutes: {
one: 'less than a minute',
other: 'less than {{count}} minutes'
},

xMinutes: {
one: 'a minute',
other: '{{count}} minutes'
},

aboutXHours: {
one: 'about an hour',
other: 'about {{count}} hours'
},

xHours: {
one: 'an hour',
other: '{{count}} hours'
},

xDays: {
one: 'a day',
other: '{{count}} days'
},

aboutXMonths: {
one: 'about a month',
other: 'about {{count}} months'
},

xMonths: {
one: 'a month',
other: '{{count}} months'
},

aboutXYears: {
one: 'about a year',
other: 'about {{count}} years'
},

xYears: {
one: 'a year',
other: '{{count}} years'
},

overXYears: {
one: 'over a year',
other: 'over {{count}} years'
},

almostXYears: {
one: 'almost a year',
other: 'almost {{count}} years'
}
}

export default function formatDistance (token, count, options) {
options = options || {}

var result
if (typeof formatDistanceLocale[token] === 'string') {
result = formatDistanceLocale[token]
} else if (count === 1) {
result = formatDistanceLocale[token].one
} else {
result = formatDistanceLocale[token].other.replace('{{count}}', count)
}

if (options.addSuffix) {
if (options.comparison > 0) {
return 'in ' + result
} else {
return result + ' ago'
}
}

return result
}
219 changes: 219 additions & 0 deletions src/locale/en-CA/_lib/formatDistance/test.js
@@ -0,0 +1,219 @@
// @flow
/* eslint-env mocha */

import assert from 'power-assert'
import formatDistance from '.'

describe('en-CA locale > formatDistance', function () {
describe('lessThanXSeconds', function () {
context('when the count equals 1', function () {
it('returns a proper string', function () {
assert(formatDistance('lessThanXSeconds', 1) === 'less than a second')
})
})

context('when the count is more than 1', function () {
it('returns a proper string', function () {
assert(formatDistance('lessThanXSeconds', 2) === 'less than 2 seconds')
})
})
})

describe('xSeconds', function () {
context('when the count equals 1', function () {
it('returns a proper string', function () {
assert(formatDistance('xSeconds', 1) === 'a few seconds')
})
})

context('when the count is more than 1', function () {
it('returns a proper string', function () {
assert(formatDistance('xSeconds', 2) === '2 seconds')
})
})
})

describe('halfAMinute', function () {
it('returns a proper string', function () {
assert(formatDistance('halfAMinute') === 'half a minute')
})

it('ignores the second argument', function () {
assert(formatDistance('halfAMinute', 123) === 'half a minute')
})
})

describe('lessThanXMinutes', function () {
context('when the count equals 1', function () {
it('returns a proper string', function () {
assert(formatDistance('lessThanXMinutes', 1) === 'less than a minute')
})
})

context('when the count is more than 1', function () {
it('returns a proper string', function () {
assert(formatDistance('lessThanXMinutes', 2) === 'less than 2 minutes')
})
})
})

describe('xMinutes', function () {
context('when the count equals 1', function () {
it('returns a proper string', function () {
assert(formatDistance('xMinutes', 1) === 'a minute')
})
})

context('when the count is more than 1', function () {
it('returns a proper string', function () {
assert(formatDistance('xMinutes', 2) === '2 minutes')
})
})
})

describe('aboutXHours', function () {
context('when the count equals 1', function () {
it('returns a proper string', function () {
assert(formatDistance('aboutXHours', 1) === 'about an hour')
})
})

context('when the count is more than 1', function () {
it('returns a proper string', function () {
assert(formatDistance('aboutXHours', 2) === 'about 2 hours')
})
})
})

describe('xHours', function () {
context('when the count equals 1', function () {
it('returns a proper string', function () {
assert(formatDistance('xHours', 1) === 'an hour')
})
})

context('when the count is more than 1', function () {
it('returns a proper string', function () {
assert(formatDistance('xHours', 2) === '2 hours')
})
})
})

describe('xDays', function () {
context('when the count equals 1', function () {
it('returns a proper string', function () {
assert(formatDistance('xDays', 1) === 'a day')
})
})

context('when the count is more than 1', function () {
it('returns a proper string', function () {
assert(formatDistance('xDays', 2) === '2 days')
})
})
})

describe('aboutXMonths', function () {
context('when the count equals 1', function () {
it('returns a proper string', function () {
assert(formatDistance('aboutXMonths', 1) === 'about a month')
})
})

context('when the count is more than 1', function () {
it('returns a proper string', function () {
assert(formatDistance('aboutXMonths', 2) === 'about 2 months')
})
})
})

describe('xMonths', function () {
context('when the count equals 1', function () {
it('returns a proper string', function () {
assert(formatDistance('xMonths', 1) === 'a month')
})
})

context('when the count is more than 1', function () {
it('returns a proper string', function () {
assert(formatDistance('xMonths', 2) === '2 months')
})
})
})

describe('aboutXYears', function () {
context('when the count equals 1', function () {
it('returns a proper string', function () {
assert(formatDistance('aboutXYears', 1) === 'about a year')
})
})

context('when the count is more than 1', function () {
it('returns a proper string', function () {
assert(formatDistance('aboutXYears', 2) === 'about 2 years')
})
})
})

describe('xYears', function () {
context('when the count equals 1', function () {
it('returns a proper string', function () {
assert(formatDistance('xYears', 1) === 'a year')
})
})

context('when the count is more than 1', function () {
it('returns a proper string', function () {
assert(formatDistance('xYears', 2) === '2 years')
})
})
})

describe('overXYears', function () {
context('when the count equals 1', function () {
it('returns a proper string', function () {
assert(formatDistance('overXYears', 1) === 'over a year')
})
})

context('when the count is more than 1', function () {
it('returns a proper string', function () {
assert(formatDistance('overXYears', 2) === 'over 2 years')
})
})
})

describe('almostXYears', function () {
context('when the count equals 1', function () {
it('returns a proper string', function () {
assert(formatDistance('almostXYears', 1) === 'almost a year')
})
})

context('when the count is more than 1', function () {
it('returns a proper string', function () {
assert(formatDistance('almostXYears', 2) === 'almost 2 years')
})
})
})

context('with a past suffix', function () {
it('adds `ago` to a string', function () {
var result = formatDistance('aboutXYears', 1, {
addSuffix: true,
comparison: -1
})
assert(result === 'about a year ago')
})
})

context('with a future suffix', function () {
it('adds `in` to a string', function () {
var result = formatDistance('halfAMinute', null, {
addSuffix: true,
comparison: 1
})
assert(result === 'in half a minute')
})
})
})
12 changes: 12 additions & 0 deletions src/locale/en-CA/_lib/formatLong/index.js
@@ -0,0 +1,12 @@
import buildFormatLongFn from '../../../_lib/buildFormatLongFn/index.js'

var formatLong = buildFormatLongFn({
LT: 'h:mm A',
LTS: 'h:mm:ss A',
L: 'YYYY-MM-DD',
LL: 'MMMM D, YYYY',
LLL: 'MMMM D, YYYY h:mm A',
LLLL: 'dddd, MMMM D, YYYY h:mm A'
})

export default formatLong
12 changes: 12 additions & 0 deletions src/locale/en-CA/_lib/formatRelative/index.js
@@ -0,0 +1,12 @@
var formatRelativeLocale = {
lastWeek: '[last] dddd [at] LT',
yesterday: '[yesterday at] LT',
today: '[today at] LT',
tomorrow: '[tomorrow at] LT',
nextWeek: 'dddd [at] LT',
other: 'L'
}

export default function formatRelative (token, date, baseDate, options) {
return formatRelativeLocale[token]
}

0 comments on commit 4284f06

Please sign in to comment.