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
Mark Owsiak
committed
Feb 13, 2018
1 parent
21c2c63
commit 89433a2
Showing
7 changed files
with
797 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,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 | ||
} |
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,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') | ||
}) | ||
}) | ||
}) |
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,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 |
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,4 @@ | ||
// This file is generated automatically by `scripts/build/typings.js`. Please, don't change it. | ||
|
||
import {enUS} from 'date-fns/locale' | ||
export = enUS |
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,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 |
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,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 |
Oops, something went wrong.