Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add en-CA locale #688

Merged
merged 1 commit into from Feb 15, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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
4 changes: 4 additions & 0 deletions src/locale/en-CA/index.d.ts
@@ -0,0 +1,4 @@
// This file is generated automatically by `scripts/build/typings.js`. Please, don't change it.

import {enUS} from 'date-fns/locale'
export = enUS
26 changes: 26 additions & 0 deletions src/locale/en-CA/index.js
@@ -0,0 +1,26 @@
import formatDistance from './_lib/formatDistance/index.js'
import formatLong from './_lib/formatLong/index.js'
import formatRelative from '../en-US/_lib/formatRelative/index.js'
import localize from '../en-US/_lib/localize/index.js'
import match from '../en-US/_lib/match/index.js'

/**
* @type {Locale}
* @category Locales
* @summary English locale (Canada).
* @language English
* @iso-639-2 eng
*/
var locale = {
formatDistance: formatDistance,
formatLong: formatLong,
formatRelative: formatRelative,
localize: localize,
match: match,
options: {
weekStartsOn: 0 /* Sunday */,
firstWeekContainsDate: 1
}
}

export default locale
37 changes: 37 additions & 0 deletions src/locale/en-CA/index.js.flow
@@ -0,0 +1,37 @@
// @flow
// This file is generated automatically by `scripts/build/typings.js`. Please, don't change it.

type Locale = {
formatDistance: Function,
formatLong: Function,
formatRelative: Function,
localize: {
ordinalNumber: Function,
weekday: Function,
weekdays: Function,
month: Function,
months: Function,
timeOfDay: Function,
timesOfDay: Function
},
match: {
ordinalNumbers: Function,
ordinalNumber: Function,
weekdays: Function,
weekday: Function,
months: Function,
month: Function,
timesOfDay: Function,
timeOfDay: Function
},
formatters?: Object,
formattingTokensRegExp?: RegExp,
units?: Object,
parsers?: Object,
parsingTokensRegExp?: RegExp,
options?: {
weekStartsOn?: 0 | 1 | 2 | 3 | 4 | 5 | 6
}
}

declare module.exports: Locale