From 5410391c16ecdbf4c3c4ca09b880d664c2fcaa93 Mon Sep 17 00:00:00 2001 From: Alex Kubyshkin Date: Sat, 16 Sep 2017 23:33:18 +0300 Subject: [PATCH 1/4] Added locale en-GB --- src/locale/en-GB/_lib/formatLong/index.js | 12 + src/locale/en-GB/index.js | 26 ++ src/locale/en-GB/index.js.flow | 37 ++ src/locale/en-GB/test.js | 408 ++++++++++++++++++++++ 4 files changed, 483 insertions(+) create mode 100644 src/locale/en-GB/_lib/formatLong/index.js create mode 100644 src/locale/en-GB/index.js create mode 100644 src/locale/en-GB/index.js.flow create mode 100644 src/locale/en-GB/test.js diff --git a/src/locale/en-GB/_lib/formatLong/index.js b/src/locale/en-GB/_lib/formatLong/index.js new file mode 100644 index 0000000000..be992c3519 --- /dev/null +++ b/src/locale/en-GB/_lib/formatLong/index.js @@ -0,0 +1,12 @@ +import buildFormatLongFn from '../../../_lib/buildFormatLongFn/index.js' + +var formatLong = buildFormatLongFn({ + LT: 'HH:mm', + LTS: 'HH:mm:ss', + L: 'DD/MM/YYYY', + LL : 'D MMMM YYYY', + LLL : 'D MMMM YYYY HH:mm', + LLLL : 'dddd, D MMMM YYYY HH:mm' +}) + +export default formatLong diff --git a/src/locale/en-GB/index.js b/src/locale/en-GB/index.js new file mode 100644 index 0000000000..099f964907 --- /dev/null +++ b/src/locale/en-GB/index.js @@ -0,0 +1,26 @@ +import formatDistance from '../en-US/_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 (United Kingdom). + * @language English + * @iso-639-2 eng + */ +var locale = { + formatDistance: formatDistance, + formatLong: formatLong, + formatRelative: formatRelative, + localize: localize, + match: match, + options: { + weekStartsOn: 1 /* Monday */, + firstWeekContainsDate: 4 + } +} + +export default locale diff --git a/src/locale/en-GB/index.js.flow b/src/locale/en-GB/index.js.flow new file mode 100644 index 0000000000..df800ba69c --- /dev/null +++ b/src/locale/en-GB/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 diff --git a/src/locale/en-GB/test.js b/src/locale/en-GB/test.js new file mode 100644 index 0000000000..cf630b54cc --- /dev/null +++ b/src/locale/en-GB/test.js @@ -0,0 +1,408 @@ +// @flow +/* eslint-env mocha */ + +import assert from 'power-assert' +import locale from '.' + +import differenceInCalendarWeeks from '../../differenceInCalendarWeeks' +import endOfWeek from '../../endOfWeek' +import format from '../../format' +import formatDistance from '../../formatDistance' +import formatDistanceStrict from '../../formatDistanceStrict' +import formatRelative from '../../formatRelative' +import isSameWeek from '../../isSameWeek' +import lastDayOfWeek from '../../lastDayOfWeek' +import parse from '../../parse' +import setDay from '../../setDay' +import startOfWeek from '../../startOfWeek' + +describe('en-GB locale', function () { + context('with `differenceInCalendarWeeks`', function () { + it('sets the first day of the week', function () { + var result = differenceInCalendarWeeks( + new Date(2014, 5 /* Jun */, 30, 6, 0), + new Date(2014, 6 /* Jul */, 8, 18, 0), + {locale: locale} + ) + assert(result === -1) + }) + }) + + context('with `endOfWeek`', function () { + it('sets the first day of the week', function () { + var date = new Date(2014, 8 /* Sep */, 2, 11, 55, 0) + var result = endOfWeek(date, {locale: locale}) + assert.deepEqual(result, new Date(2014, 8 /* Sep */, 7, 23, 59, 59, 999)) + }) + }) + + context('with `format`', function () { + var date = new Date(1986, 3 /* Apr */, 4, 10, 32, 0, 900) + + describe('months', function () { + it('Mo', function () { + var result = format(date, 'Mo [month]', {locale: locale}) + assert(result === '4th month') + }) + + it('MMM', function () { + var result = format(date, 'MMM', {locale: locale}) + assert(result === 'Apr') + }) + + it('MMMM', function () { + var result = format(date, 'MMMM', {locale: locale}) + assert(result === 'April') + }) + }) + + describe('quarters', function () { + it('Qo', function () { + var result = format(date, 'Qo [quarter]', {locale: locale}) + assert(result === '2nd quarter') + }) + }) + + describe('days of month', function () { + it('Do', function () { + var result = format(date, 'Do MMMM YYYY', {locale: locale}) + assert(result === '4th April 1986') + }) + }) + + describe('days of year', function () { + it('DDDo', function () { + var result = format(new Date(1992, 0 /* Jan */, 1), 'DDDo [day of the year]', {locale: locale}) + assert(result === '1st day of the year') + }) + }) + + describe('days of week', function () { + it('all variants', function () { + var result = format(date, 'do [day of the week,] dd ddd dddd', {locale: locale}) + assert(result === '5th day of the week, Fr Fri Friday') + }) + }) + + describe('ISO weeks', function () { + it('Wo', function () { + var result = format(date, 'Wo [week]', {locale: locale}) + assert(result === '14th week') + }) + }) + + describe('hours and am/pm', function () { + it('am/pm', function () { + var result = format(date, 'hh:mm a', {locale: locale}) + assert(result === '10:32 am') + }) + + it('12 pm', function () { + var date = new Date(1986, 3 /* Apr */, 4, 12, 0, 0, 900) + var result = format(date, 'hh:mm a', {locale: locale}) + assert(result === '12:00 pm') + }) + + it('12 am', function () { + var date = new Date(1986, 3 /* Apr */, 6, 0, 0, 0, 900) + var result = format(date, 'h:mm a', {locale: locale}) + assert(result === '12:00 am') + }) + + it('12 a.m.', function () { + var date = new Date(1986, 3 /* Apr */, 6, 0, 0, 0, 900) + var result = format(date, 'h:mm aa', {locale: locale}) + assert(result === '12:00 a.m.') + }) + + it('12 p.m.', function () { + var date = new Date(1986, 3 /* Apr */, 4, 12, 0, 0, 900) + var result = format(date, 'hh:mm aa', {locale: locale}) + assert(result === '12:00 p.m.') + }) + + it('12PM', function () { + var date = new Date(1986, 3 /* Apr */, 4, 12, 0, 0, 900) + var result = format(date, 'hh:mmA', {locale: locale}) + assert(result === '12:00PM') + }) + }) + + describe('long formats', function () { + it('LT', function () { + var result = format(date, 'LT', {locale: locale}) + assert(result === '10:32') + }) + + it('LTS', function () { + var result = format(date, 'LTS', {locale: locale}) + assert(result === '10:32:00') + }) + + it('L', function () { + var result = format(new Date(2017, 6 /* Jul */, 2), 'L', {locale: locale}) + assert(result === '02/07/2017') + }) + + it('LL', function () { + var result = format(date, 'LL', {locale: locale}) + assert(result === '4 April 1986') + }) + + it('LLL', function () { + var result = format(date, 'LLL', {locale: locale}) + assert(result === '4 April 1986 10:32') + }) + + it('LLLL', function () { + var result = format(date, 'LLLL', {locale: locale}) + assert(result === 'Friday, 4 April 1986 10:32') + }) + }) + }) + + context('with `formatDistance`', function () { + it('works as expected', function () { + var result = formatDistance( + new Date(1986, 3, 4, 10, 32, 25), + new Date(1986, 3, 4, 10, 32, 0), + {locale: locale, includeSeconds: true} + ) + assert(result === 'half a minute') + }) + + context('when `addSuffix` option is true', function () { + it('adds a future suffix', function () { + var result = formatDistance( + new Date(1986, 3, 4, 10, 32, 7), + new Date(1986, 3, 4, 10, 32, 0), + {locale: locale, includeSeconds: true, addSuffix: true} + ) + assert(result === 'in less than 10 seconds') + }) + + it('adds a past suffix', function () { + var result = formatDistance( + new Date(1986, 3, 4, 10, 32, 0), + new Date(1986, 3, 4, 11, 32, 0), + {locale: locale, addSuffix: true} + ) + assert(result === 'about 1 hour ago') + }) + }) + }) + + context('with `formatDistanceStrict`', function () { + it('works as expected', function () { + var result = formatDistanceStrict( + new Date(1986, 3, 4, 10, 32, 0), + new Date(1986, 3, 4, 12, 32, 0), + {locale: locale, unit: 'm'} + ) + assert(result === '120 minutes') + }) + + describe('when `addSuffix` option is true', function () { + it('adds a future suffix', function () { + var result = formatDistanceStrict( + new Date(1986, 3, 4, 10, 32, 25), + new Date(1986, 3, 4, 10, 32, 0), + {locale: locale, addSuffix: true} + ) + assert(result === 'in 25 seconds') + }) + + it('adds a past suffix', function () { + var result = formatDistanceStrict( + new Date(1986, 3, 4, 10, 32, 0), + new Date(1986, 3, 4, 11, 32, 0), + {locale: locale, addSuffix: true} + ) + assert(result === '1 hour ago') + }) + }) + }) + + context('with `formatRelative`', function () { + var baseDate = new Date(1986, 3 /* Apr */, 4, 10, 32, 0, 900) + + it('last week', function () { + var result = formatRelative(new Date(1986, 3 /* Apr */, 1), baseDate, {locale: locale}) + assert(result === 'last Tuesday at 00:00') + }) + + it('yesterday', function () { + var result = formatRelative(new Date(1986, 3 /* Apr */, 3, 22, 22), baseDate, {locale: locale}) + assert(result === 'yesterday at 22:22') + }) + + it('today', function () { + var result = formatRelative(new Date(1986, 3 /* Apr */, 4, 16, 50), baseDate, {locale: locale}) + assert(result === 'today at 16:50') + }) + + it('tomorrow', function () { + var result = formatRelative(new Date(1986, 3 /* Apr */, 5, 7, 30), baseDate, {locale: locale}) + assert(result === 'tomorrow at 07:30') + }) + + it('next week', function () { + var result = formatRelative(new Date(1986, 3 /* Apr */, 6, 12, 0), baseDate, {locale: locale}) + assert(result === 'Sunday at 12:00') + }) + + it('after the next week', function () { + var result = formatRelative(new Date(1986, 3 /* Apr */, 11, 16, 50), baseDate, {locale: locale}) + assert(result === '11/04/1986') + }) + }) + + context('with `isSameWeek`', function () { + it('sets the first day of the week', function () { + var result = isSameWeek( + new Date(2014, 8 /* Sep */, 1), + new Date(2014, 8 /* Sep */, 4), + {locale: locale} + ) + assert(result === true) + }) + }) + + context('with `lastDayOfWeek`', function () { + it('sets the first day of the week', function () { + var date = new Date(2014, 8 /* Sep */, 2, 11, 55, 0) + var result = lastDayOfWeek(date, {locale: locale}) + assert.deepEqual(result, new Date(2014, 8 /* Sep */, 7)) + }) + }) + + context('with `parse`', function () { + var baseDate = new Date(1986, 3 /* Apr */, 4, 10, 32, 0, 900) + + it('sets the first day of the week', function () { + var result = parse('0', 'd', baseDate, {locale: locale}) + assert.deepEqual(result, new Date(1986, 3 /* Apr */, 6)) + }) + + describe('quarters', function () { + it('Qo', function () { + var result = parse('2000 2nd', 'YYYY Qo', baseDate, {locale: locale}) + assert.deepEqual(result, new Date(2000, 3 /* Apr */, 1)) + }) + }) + + describe('months', function () { + it('Mo', function () { + var result = parse('2014 12th', 'YYYY Mo', baseDate, {locale: locale}) + assert.deepEqual(result, new Date(2014, 11 /* Dec */, 1)) + }) + + it('MMM', function () { + var result = parse('2016 Nov', 'YYYY MMM', baseDate, {locale: locale}) + assert.deepEqual(result, new Date(2016, 10 /* Nov */, 1)) + }) + + it('MMMM', function () { + var result = parse('2016 December', 'YYYY MMMM', baseDate, {locale: locale}) + assert.deepEqual(result, new Date(2016, 11 /* Dec */, 1)) + }) + }) + + describe('ISO weeks', function () { + it('Wo', function () { + var result = parse('2016 3rd', 'GGGG Wo', baseDate, {locale: locale}) + assert.deepEqual(result, new Date(2016, 0 /* Jan */, 18)) + }) + }) + + describe('days of a week', function () { + it('do', function () { + var result = parse('2016 4 0th', 'GGGG W do', baseDate, {locale: locale}) + assert.deepEqual(result, new Date(2016, 0 /* Jan */, 31)) + }) + + it('dd', function () { + var result = parse('2016 4 Mo', 'GGGG W dd', baseDate, {locale: locale}) + assert.deepEqual(result, new Date(2016, 0 /* Jan */, 25)) + }) + + it('ddd', function () { + var result = parse('2016 4 Wed', 'GGGG W ddd', baseDate, {locale: locale}) + assert.deepEqual(result, new Date(2016, 0 /* Jan */, 27)) + }) + + it('dddd', function () { + var result = parse('2016 4 Friday', 'GGGG W dddd', baseDate, {locale: locale}) + assert.deepEqual(result, new Date(2016, 0 /* Jan */, 29)) + }) + }) + + describe('days of a month', function () { + it('Do', function () { + var result = parse('2016 11 15th', 'YYYY MM Do', baseDate, {locale: locale}) + assert.deepEqual(result, new Date(2016, 10 /* Nov */, 15)) + }) + }) + + describe('days of a year', function () { + it('DDDo', function () { + var result = parse('2016 100th', 'YYYY DDDo', baseDate, {locale: locale}) + assert.deepEqual(result, new Date(2016, 3 /* Apr */, 9)) + }) + }) + + describe('a.m./p.m.', function () { + it('AM', function () { + var result = parse('2016-11-25 04 AM', 'YYYY-MM-DD hh A', baseDate, {locale: locale}) + assert.deepEqual(result, new Date(2016, 10 /* Nov */, 25, 4, 0, 0, 0)) + }) + + it('PM', function () { + var result = parse('2016-11-25 04 PM', 'YYYY-MM-DD hh A', baseDate, {locale: locale}) + assert.deepEqual(result, new Date(2016, 10 /* Nov */, 25, 16, 0, 0, 0)) + }) + + it('am', function () { + var result = parse('2016-11-25 04 am', 'YYYY-MM-DD hh a', baseDate, {locale: locale}) + assert.deepEqual(result, new Date(2016, 10 /* Nov */, 25, 4, 0, 0, 0)) + }) + + it('pm', function () { + var result = parse('2016-11-25 04 pm', 'YYYY-MM-DD hh a', baseDate, {locale: locale}) + assert.deepEqual(result, new Date(2016, 10 /* Nov */, 25, 16, 0, 0, 0)) + }) + + it('a.m.', function () { + var result = parse('2016-11-25 04 a.m.', 'YYYY-MM-DD hh aa', baseDate, {locale: locale}) + assert.deepEqual(result, new Date(2016, 10 /* Nov */, 25, 4, 0, 0, 0)) + }) + + it('p.m.', function () { + var result = parse('2016-11-25 04 p.m.', 'YYYY-MM-DD hh aa', baseDate, {locale: locale}) + assert.deepEqual(result, new Date(2016, 10 /* Nov */, 25, 16, 0, 0, 0)) + }) + }) + + describe('long formats', function () { + it('unfolds long formats', function () { + var result = parse('6 April 1987 11:32', 'LLL', baseDate, {locale: locale}) + assert.deepEqual(result, new Date(1987, 3 /* Apr */, 6, 11, 32)) + }) + }) + }) + + context('with `setDay`', function () { + it('sets the first day of the week', function () { + var result = setDay(new Date(2014, 8 /* Sep */, 1), 0, {locale: locale}) + assert.deepEqual(result, new Date(2014, 8 /* sep */, 7)) + }) + }) + + context('with `startOfWeek`', function () { + it('sets the first day of the week', function () { + var date = new Date(2014, 8 /* Sep */, 2, 11, 55, 0) + var result = startOfWeek(date, {locale: locale}) + assert.deepEqual(result, new Date(2014, 8 /* Sep */, 1)) + }) + }) +}) From a3900981c41a28d14c41570069102374cb85b3cf Mon Sep 17 00:00:00 2001 From: Alex Kubyshkin Date: Sat, 16 Sep 2017 23:37:18 +0300 Subject: [PATCH 2/4] Added locale en-GB to locales list --- src/locale/index.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/locale/index.js b/src/locale/index.js index 11b51b6048..9d68aab2d0 100644 --- a/src/locale/index.js +++ b/src/locale/index.js @@ -9,6 +9,7 @@ module.exports = { de: require('./de/index.js'), el: require('./el/index.js'), enUS: require('./en-US/index.js'), + enGB: require('./en-GB/index.js'), eo: require('./eo/index.js'), es: require('./es/index.js'), fi: require('./fi/index.js'), From bcaed394b2fef0d46310a2b8d47e7c731d68b8a4 Mon Sep 17 00:00:00 2001 From: Alex Kubyshkin Date: Sun, 17 Sep 2017 15:08:35 +0300 Subject: [PATCH 3/4] Fixed code style issues --- src/locale/en-GB/_lib/formatLong/index.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/locale/en-GB/_lib/formatLong/index.js b/src/locale/en-GB/_lib/formatLong/index.js index be992c3519..bcefeeed1f 100644 --- a/src/locale/en-GB/_lib/formatLong/index.js +++ b/src/locale/en-GB/_lib/formatLong/index.js @@ -4,9 +4,9 @@ var formatLong = buildFormatLongFn({ LT: 'HH:mm', LTS: 'HH:mm:ss', L: 'DD/MM/YYYY', - LL : 'D MMMM YYYY', - LLL : 'D MMMM YYYY HH:mm', - LLLL : 'dddd, D MMMM YYYY HH:mm' + LL: 'D MMMM YYYY', + LLL: 'D MMMM YYYY HH:mm', + LLLL: 'dddd, D MMMM YYYY HH:mm' }) export default formatLong From 9082312207b23f68782b36a1547d5d729ef9f14a Mon Sep 17 00:00:00 2001 From: Alex Kubyshkin Date: Mon, 18 Sep 2017 15:06:46 +0300 Subject: [PATCH 4/4] Added @author to en-GB locale --- src/locale/en-GB/index.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/locale/en-GB/index.js b/src/locale/en-GB/index.js index 099f964907..a5877b98b2 100644 --- a/src/locale/en-GB/index.js +++ b/src/locale/en-GB/index.js @@ -10,6 +10,7 @@ import match from '../en-US/_lib/match/index.js' * @summary English locale (United Kingdom). * @language English * @iso-639-2 eng + * @author Alex [@glintik]{@link https://github.com/glintik} */ var locale = { formatDistance: formatDistance,