From dbda8ab2274732af854f8d46260511e4eb5e0c47 Mon Sep 17 00:00:00 2001 From: Mats Byrkjeland Date: Thu, 16 May 2019 18:06:20 +0200 Subject: [PATCH] Add locale nn for Norwegian Nynorsk --- CHANGELOG.md | 3 + src/esm/locale/index.js | 1 + src/locale/index.js | 1 + src/locale/index.js.flow | 1 + src/locale/nn/_lib/formatDistance/index.js | 117 +++++ src/locale/nn/_lib/formatDistance/test.js | 285 ++++++++++++ src/locale/nn/_lib/formatLong/index.js | 41 ++ src/locale/nn/_lib/formatRelative/index.js | 12 + src/locale/nn/_lib/localize/index.js | 124 ++++++ src/locale/nn/_lib/match/index.js | 136 ++++++ src/locale/nn/index.d.ts | 4 + src/locale/nn/index.js | 27 ++ src/locale/nn/index.js.flow | 33 ++ src/locale/nn/test.js | 484 +++++++++++++++++++++ typings.d.ts | 40 ++ 15 files changed, 1309 insertions(+) create mode 100644 src/locale/nn/_lib/formatDistance/index.js create mode 100644 src/locale/nn/_lib/formatDistance/test.js create mode 100644 src/locale/nn/_lib/formatLong/index.js create mode 100644 src/locale/nn/_lib/formatRelative/index.js create mode 100644 src/locale/nn/_lib/localize/index.js create mode 100644 src/locale/nn/_lib/match/index.js create mode 100644 src/locale/nn/index.d.ts create mode 100644 src/locale/nn/index.js create mode 100644 src/locale/nn/index.js.flow create mode 100644 src/locale/nn/test.js diff --git a/CHANGELOG.md b/CHANGELOG.md index 8309491ca5..db0f27a161 100755 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -78,6 +78,9 @@ for the list of changes made since `v2.0.0-alpha.1`. - is locale [is updated for v2 format](https://github.com/date-fns/date-fns/pull/1026). Kudos to [@lamayg](https://github.com/lamayg). +- [Norwegian Nynorsk locale (nn)](https://github.com/date-fns/date-fns/pull/1172) + (thanks to Mats Byrkjeland)[@draperunner](https://github.com/draperunner) + - [Ukrainian locale (ua)](https://github.com/date-fns/date-fns/pull/532) (thanks to Andrii Korzh [@korzhyk](https://github.com/korzhyk)) diff --git a/src/esm/locale/index.js b/src/esm/locale/index.js index fb4cbfee9f..af1af71501 100644 --- a/src/esm/locale/index.js +++ b/src/esm/locale/index.js @@ -20,6 +20,7 @@ export { default as ja } from './ja/index.js' export { default as lt } from './lt/index.js' export { default as nb } from './nb/index.js' export { default as nl } from './nl/index.js' +export { default as nn } from './nn/index.js' export { default as pt } from './pt/index.js' export { default as ptBR } from './pt-BR/index.js' export { default as ru } from './ru/index.js' diff --git a/src/locale/index.js b/src/locale/index.js index 2a42546296..7f3e3de0f4 100644 --- a/src/locale/index.js +++ b/src/locale/index.js @@ -21,6 +21,7 @@ module.exports = { lt: require('./lt/index.js'), nb: require('./nb/index.js'), nl: require('./nl/index.js'), + nn: require('./nn/index.js'), pt: require('./pt/index.js'), ptBR: require('./pt-BR/index.js'), ru: require('./ru/index.js'), diff --git a/src/locale/index.js.flow b/src/locale/index.js.flow index fa9ac6f606..2bfbf876c0 100644 --- a/src/locale/index.js.flow +++ b/src/locale/index.js.flow @@ -69,6 +69,7 @@ declare module.exports: { nb: Locale, nl: Locale, nlBE: Locale, + nn: Locale, pl: Locale, pt: Locale, ptBR: Locale, diff --git a/src/locale/nn/_lib/formatDistance/index.js b/src/locale/nn/_lib/formatDistance/index.js new file mode 100644 index 0000000000..23715825e8 --- /dev/null +++ b/src/locale/nn/_lib/formatDistance/index.js @@ -0,0 +1,117 @@ +var formatDistanceLocale = { + lessThanXSeconds: { + singular: 'mindre enn eitt sekund', + plural: 'mindre enn {{count}} sekund' + }, + + xSeconds: { + singular: 'eitt sekund', + plural: '{{count}} sekund' + }, + + halfAMinute: 'eit halvt minutt', + + lessThanXMinutes: { + singular: 'mindre enn eitt minutt', + plural: 'mindre enn {{count}} minutt' + }, + + xMinutes: { + singular: 'eitt minutt', + plural: '{{count}} minutt' + }, + + aboutXHours: { + singular: 'omtrent ein time', + plural: 'omtrent {{count}} timar' + }, + + xHours: { + singular: 'ein time', + plural: '{{count}} timar' + }, + + xDays: { + singular: 'ein dag', + plural: '{{count}} dagar' + }, + + aboutXMonths: { + singular: 'omtrent ein månad', + plural: 'omtrent {{count}} månader' + }, + + xMonths: { + singular: 'ein månad', + plural: '{{count}} månader' + }, + + aboutXYears: { + singular: 'omtrent eitt år', + plural: 'omtrent {{count}} år' + }, + + xYears: { + singular: 'eitt år', + plural: '{{count}} år' + }, + + overXYears: { + singular: 'over eitt år', + plural: 'over {{count}} år' + }, + + almostXYears: { + singular: 'nesten eitt år', + plural: 'nesten {{count}} år' + } +} + +var wordMapping = [ + 'null', + 'ein', + 'to', + 'tre', + 'fire', + 'fem', + 'seks', + 'sju', + 'åtte', + 'ni', + 'ti', + 'elleve', + 'tolv' +] + +export default function formatDistance(token, count, options) { + options = options || { + onlyNumeric: false + } + + var translation = formatDistanceLocale[token] + var result + if (typeof translation === 'string') { + result = translation + } else if (count === 0 || count > 1) { + if (options.onlyNumeric) { + result = translation.plural.replace('{{count}}', count) + } else { + result = translation.plural.replace( + '{{count}}', + count < 13 ? wordMapping[count] : count + ) + } + } else { + result = translation.singular + } + + if (options.addSuffix) { + if (options.comparison > 0) { + return 'om ' + result + } else { + return result + ' sidan' + } + } + + return result +} diff --git a/src/locale/nn/_lib/formatDistance/test.js b/src/locale/nn/_lib/formatDistance/test.js new file mode 100644 index 0000000000..e63a730b2c --- /dev/null +++ b/src/locale/nn/_lib/formatDistance/test.js @@ -0,0 +1,285 @@ +// @flow +/* eslint-env mocha */ + +import assert from 'power-assert' +import formatDistance from '.' + +describe('nn locale > formatDistance', function() { + describe('lessThanXSeconds', function() { + context('when the count equals 1', function() { + it('returns a proper string', function() { + assert( + formatDistance('lessThanXSeconds', 1) === 'mindre enn eitt sekund' + ) + }) + }) + + context('when the count equals 12', function() { + it('returns a proper string', function() { + assert( + formatDistance('lessThanXSeconds', 12) === 'mindre enn tolv sekund' + ) + }) + }) + + context('when the count is more than 12', function() { + it('returns a proper string', function() { + assert( + formatDistance('lessThanXSeconds', 13) === 'mindre enn 13 sekund' + ) + }) + }) + }) + + describe('xSeconds', function() { + context('when the count equals 1', function() { + it('returns a proper string', function() { + assert(formatDistance('xSeconds', 1) === 'eitt sekund') + }) + }) + + context('when the count equals 12', function() { + it('returns a proper string', function() { + assert(formatDistance('xSeconds', 12) === 'tolv sekund') + }) + }) + + context('when the count is more than 12', function() { + it('returns a proper string', function() { + assert(formatDistance('xSeconds', 13) === '13 sekund') + }) + }) + }) + + describe('halfAMinute', function() { + it('returns a proper string', function() { + assert(formatDistance('halfAMinute') === 'eit halvt minutt') + }) + + it('ignores the second argument', function() { + assert(formatDistance('halfAMinute', 123) === 'eit halvt minutt') + }) + }) + + describe('lessThanXMinutes', function() { + context('when the count equals 1', function() { + it('returns a proper string', function() { + assert( + formatDistance('lessThanXMinutes', 1) === 'mindre enn eitt minutt' + ) + }) + }) + + context('when the count equals 12', function() { + it('returns a proper string', function() { + assert( + formatDistance('lessThanXMinutes', 12) === 'mindre enn tolv minutt' + ) + }) + }) + + context('when the count is more than 12', function() { + it('returns a proper string', function() { + assert( + formatDistance('lessThanXMinutes', 13) === 'mindre enn 13 minutt' + ) + }) + }) + }) + + describe('xMinutes', function() { + context('when the count equals 1', function() { + it('returns a proper string', function() { + assert(formatDistance('xMinutes', 1) === 'eitt minutt') + }) + }) + + context('when the count equals 12', function() { + it('returns a proper string', function() { + assert(formatDistance('xMinutes', 12) === 'tolv minutt') + }) + }) + + context('when the count is more than 12', function() { + it('returns a proper string', function() { + assert(formatDistance('xMinutes', 13) === '13 minutt') + }) + }) + }) + + describe('aboutXHours', function() { + context('when the count equals 1', function() { + it('returns a proper string', function() { + assert(formatDistance('aboutXHours', 1) === 'omtrent ein time') + }) + }) + + context('when the count equals 12', function() { + it('returns a proper string', function() { + assert(formatDistance('aboutXHours', 12) === 'omtrent tolv timar') + }) + }) + + context('when the count is more than 12', function() { + it('returns a proper string', function() { + assert(formatDistance('aboutXHours', 13) === 'omtrent 13 timar') + }) + }) + }) + + describe('xHours', function() { + context('when the count equals 1', function() { + it('returns a proper string', function() { + assert(formatDistance('xHours', 1) === 'ein time') + }) + }) + + context('when the count equals 12', function() { + it('returns a proper string', function() { + assert(formatDistance('xHours', 12) === 'tolv timar') + }) + }) + + context('when the count is more than 12', function() { + it('returns a proper string', function() { + assert(formatDistance('xHours', 13) === '13 timar') + }) + }) + }) + + describe('xDays', function() { + context('when the count equals 1', function() { + it('returns a proper string', function() { + assert(formatDistance('xDays', 1) === 'ein dag') + }) + }) + + context('when the count equals 11', function() { + it('returns a proper string', function() { + assert(formatDistance('xDays', 11) === 'elleve dagar') + }) + }) + + context('when the count is more than 12', function() { + it('returns a proper string', function() { + assert(formatDistance('xDays', 13) === '13 dagar') + }) + }) + }) + + describe('aboutXMonths', function() { + context('when the count equals 1', function() { + it('returns a proper string', function() { + assert(formatDistance('aboutXMonths', 1) === 'omtrent ein månad') + }) + }) + + context('when the count equals 12', function() { + it('returns a proper string', function() { + assert(formatDistance('aboutXMonths', 12) === 'omtrent tolv månader') + }) + }) + + context('when the count is more than 12', function() { + it('returns a proper string', function() { + assert(formatDistance('aboutXMonths', 13) === 'omtrent 13 månader') + }) + }) + }) + + describe('xMonths', function() { + context('when the count equals 1', function() { + it('returns a proper string', function() { + assert(formatDistance('xMonths', 1) === 'ein månad') + }) + }) + + context('when the count is more than 12', function() { + it('returns a proper string', function() { + assert(formatDistance('xMonths', 13) === '13 månader') + }) + }) + }) + + describe('aboutXYears', function() { + context('when the count equals 1', function() { + it('returns a proper string', function() { + assert(formatDistance('aboutXYears', 1) === 'omtrent eitt år') + }) + }) + + context('when the count equals 12', function() { + it('returns a proper string', function() { + assert(formatDistance('aboutXYears', 12) === 'omtrent tolv år') + }) + }) + + context('when the count is more than 12', function() { + it('returns a proper string', function() { + assert(formatDistance('aboutXYears', 13) === 'omtrent 13 år') + }) + }) + }) + + describe('xYears', function() { + context('when the count equals 1', function() { + it('returns a proper string', function() { + assert(formatDistance('xYears', 1) === 'eitt år') + }) + }) + + context('when the count is more than 12', function() { + it('returns a proper string', function() { + assert(formatDistance('xYears', 13) === '13 år') + }) + }) + }) + + describe('overXYears', function() { + context('when the count equals 1', function() { + it('returns a proper string', function() { + assert(formatDistance('overXYears', 1) === 'over eitt år') + }) + }) + + context('when the count is more than 12', function() { + it('returns a proper string', function() { + assert(formatDistance('overXYears', 13) === 'over 13 år') + }) + }) + }) + + describe('almostXYears', function() { + context('when the count equals 1', function() { + it('returns a proper string', function() { + assert(formatDistance('almostXYears', 1) === 'nesten eitt år') + }) + }) + + context('when the count is more than 12', function() { + it('returns a proper string', function() { + assert(formatDistance('almostXYears', 13) === 'nesten 13 år') + }) + }) + }) + + context('with a past suffix', function() { + it('adds `sidan` to a string', function() { + var result = formatDistance('aboutXYears', 1, { + addSuffix: true, + comparison: -1 + }) + assert(result === 'omtrent eitt år sidan') + }) + }) + + context('with a future suffix', function() { + it('adds `om` to a string', function() { + var result = formatDistance('halfAMinute', null, { + addSuffix: true, + comparison: 1 + }) + assert(result === 'om eit halvt minutt') + }) + }) +}) diff --git a/src/locale/nn/_lib/formatLong/index.js b/src/locale/nn/_lib/formatLong/index.js new file mode 100644 index 0000000000..d600cd4392 --- /dev/null +++ b/src/locale/nn/_lib/formatLong/index.js @@ -0,0 +1,41 @@ +import buildFormatLongFn from '../../../_lib/buildFormatLongFn/index.js' + +var dateFormats = { + full: 'EEEE d. MMMM y', + long: 'd. MMMM y', + medium: 'd. MMM y', + short: 'dd.MM.y' +} + +var timeFormats = { + full: "'kl'. HH:mm:ss zzzz", + long: 'HH:mm:ss z', + medium: 'HH:mm:ss', + short: 'HH:mm' +} + +var dateTimeFormats = { + full: "{{date}} 'kl.' {{time}}", + long: "{{date}} 'kl.' {{time}}", + medium: '{{date}} {{time}}', + short: '{{date}} {{time}}' +} + +var formatLong = { + date: buildFormatLongFn({ + formats: dateFormats, + defaultWidth: 'full' + }), + + time: buildFormatLongFn({ + formats: timeFormats, + defaultWidth: 'full' + }), + + dateTime: buildFormatLongFn({ + formats: dateTimeFormats, + defaultWidth: 'full' + }) +} + +export default formatLong diff --git a/src/locale/nn/_lib/formatRelative/index.js b/src/locale/nn/_lib/formatRelative/index.js new file mode 100644 index 0000000000..c3031c249e --- /dev/null +++ b/src/locale/nn/_lib/formatRelative/index.js @@ -0,0 +1,12 @@ +var formatRelativeLocale = { + lastWeek: "'førre' eeee 'kl.' p", + yesterday: "'i går kl.' p", + today: "'i dag kl.' p", + tomorrow: "'i morgon kl.' p", + nextWeek: "EEEE 'kl.' p", + other: 'P' +} + +export default function formatRelative(token, date, baseDate, options) { + return formatRelativeLocale[token] +} diff --git a/src/locale/nn/_lib/localize/index.js b/src/locale/nn/_lib/localize/index.js new file mode 100644 index 0000000000..4ae4434ada --- /dev/null +++ b/src/locale/nn/_lib/localize/index.js @@ -0,0 +1,124 @@ +import buildLocalizeFn from '../../../_lib/buildLocalizeFn/index.js' + +var eraValues = { + narrow: ['f.Kr.', 'e.Kr.'], + abbreviated: ['f.Kr.', 'e.Kr.'], + wide: ['før Kristus', 'etter Kristus'] +} + +var quarterValues = { + narrow: ['1', '2', '3', '4'], + abbreviated: ['Q1', 'Q2', 'Q3', 'Q4'], + wide: ['1. kvartal', '2. kvartal', '3. kvartal', '4. kvartal'] +} + +var monthValues = { + narrow: ['J', 'F', 'M', 'A', 'M', 'J', 'J', 'A', 'S', 'O', 'N', 'D'], + abbreviated: [ + 'jan.', + 'feb.', + 'mars', + 'apr.', + 'mai', + 'juni', + 'juli', + 'aug.', + 'sep.', + 'okt.', + 'nov.', + 'des.' + ], + wide: [ + 'januar', + 'februar', + 'mars', + 'april', + 'mai', + 'juni', + 'juli', + 'august', + 'september', + 'oktober', + 'november', + 'desember' + ] +} + +var dayValues = { + narrow: ['S', 'M', 'T', 'O', 'T', 'F', 'L'], + short: ['su', 'må', 'ty', 'on', 'to', 'fr', 'lau'], + abbreviated: ['sun', 'mån', 'tys', 'ons', 'tor', 'fre', 'laur'], + wide: ['sundag', 'måndag', 'tysdag', 'onsdag', 'torsdag', 'fredag', 'laurdag'] +} + +var dayPeriodValues = { + narrow: { + am: 'a', + pm: 'p', + midnight: 'midnatt', + noon: 'middag', + morning: 'på morg.', + afternoon: 'på etterm.', + evening: 'på kvelden', + night: 'på natta' + }, + abbreviated: { + am: 'a.m.', + pm: 'p.m.', + midnight: 'midnatt', + noon: 'middag', + morning: 'på morg.', + afternoon: 'på etterm.', + evening: 'på kvelden', + night: 'på natta' + }, + wide: { + am: 'a.m.', + pm: 'p.m.', + midnight: 'midnatt', + noon: 'middag', + morning: 'på morgonen', + afternoon: 'på ettermiddagen', + evening: 'på kvelden', + night: 'på natta' + } +} + +function ordinalNumber(dirtyNumber) { + var number = Number(dirtyNumber) + return number + '.' +} + +var localize = { + ordinalNumber: ordinalNumber, + + era: buildLocalizeFn({ + values: eraValues, + defaultWidth: 'wide' + }), + + quarter: buildLocalizeFn({ + values: quarterValues, + defaultWidth: 'wide', + argumentCallback: function(quarter) { + return Number(quarter) - 1 + } + }), + + month: buildLocalizeFn({ + values: monthValues, + defaultWidth: 'wide' + }), + + day: buildLocalizeFn({ + values: dayValues, + defaultWidth: 'wide' + }), + + dayPeriod: buildLocalizeFn({ + values: dayPeriodValues, + defaultWidth: 'wide' + }) +} + +export default localize diff --git a/src/locale/nn/_lib/match/index.js b/src/locale/nn/_lib/match/index.js new file mode 100644 index 0000000000..9ed5e79254 --- /dev/null +++ b/src/locale/nn/_lib/match/index.js @@ -0,0 +1,136 @@ +import buildMatchPatternFn from '../../../_lib/buildMatchPatternFn/index.js' +import buildMatchFn from '../../../_lib/buildMatchFn/index.js' + +var matchOrdinalNumberPattern = /^(\d+)\.?/i +var parseOrdinalNumberPattern = /\d+/i + +var matchEraPatterns = { + narrow: /^(f\.? ?Kr\.?|fvt\.?|e\.? ?Kr\.?|evt\.?)/i, + abbreviated: /^(f\.? ?Kr\.?|fvt\.?|e\.? ?Kr\.?|evt\.?)/i, + wide: /^(før Kristus|før vår tid|etter Kristus|vår tid)/i +} +var parseEraPatterns = { + any: [/^f/i, /^e/i] +} + +var matchQuarterPatterns = { + narrow: /^[1234]/i, + abbreviated: /^q[1234]/i, + wide: /^[1234](\.)? kvartal/i +} +var parseQuarterPatterns = { + any: [/1/i, /2/i, /3/i, /4/i] +} + +var matchMonthPatterns = { + narrow: /^[jfmasond]/i, + abbreviated: /^(jan|feb|mar|apr|mai|jun|jul|aug|sep|okt|nov|des)\.?/i, + wide: /^(januar|februar|mars|april|mai|juni|juli|august|september|oktober|november|desember)/i +} +var parseMonthPatterns = { + narrow: [ + /^j/i, + /^f/i, + /^m/i, + /^a/i, + /^m/i, + /^j/i, + /^j/i, + /^a/i, + /^s/i, + /^o/i, + /^n/i, + /^d/i + ], + any: [ + /^ja/i, + /^f/i, + /^mar/i, + /^ap/i, + /^mai/i, + /^jun/i, + /^jul/i, + /^aug/i, + /^s/i, + /^o/i, + /^n/i, + /^d/i + ] +} + +var matchDayPatterns = { + narrow: /^[smtofl]/i, + short: /^(su|må|ty|on|to|fr|la)/i, + abbreviated: /^(sun|mån|tys|ons|tor|fre|laur)/i, + wide: /^(sundag|måndag|tysdag|onsdag|torsdag|fredag|laurdag)/i +} +var parseDayPatterns = { + any: [/^s/i, /^m/i, /^ty/i, /^o/i, /^to/i, /^f/i, /^l/i] +} + +var matchDayPeriodPatterns = { + narrow: /^(midnatt|middag|(på) (morgonen|ettermiddagen|kvelden|natta)|[ap])/i, + any: /^([ap]\.?\s?m\.?|midnatt|middag|(på) (morgonen|ettermiddagen|kvelden|natta))/i +} +var parseDayPeriodPatterns = { + any: { + am: /^a(\.?\s?m\.?)?$/i, + pm: /^p(\.?\s?m\.?)?$/i, + midnight: /^midn/i, + noon: /^midd/i, + morning: /morgon/i, + afternoon: /ettermiddag/i, + evening: /kveld/i, + night: /natt/i + } +} + +var match = { + ordinalNumber: buildMatchPatternFn({ + matchPattern: matchOrdinalNumberPattern, + parsePattern: parseOrdinalNumberPattern, + valueCallback: function(value) { + return parseInt(value, 10) + } + }), + + era: buildMatchFn({ + matchPatterns: matchEraPatterns, + defaultMatchWidth: 'wide', + parsePatterns: parseEraPatterns, + defaultParseWidth: 'any' + }), + + quarter: buildMatchFn({ + matchPatterns: matchQuarterPatterns, + defaultMatchWidth: 'wide', + parsePatterns: parseQuarterPatterns, + defaultParseWidth: 'any', + valueCallback: function(index) { + return index + 1 + } + }), + + month: buildMatchFn({ + matchPatterns: matchMonthPatterns, + defaultMatchWidth: 'wide', + parsePatterns: parseMonthPatterns, + defaultParseWidth: 'any' + }), + + day: buildMatchFn({ + matchPatterns: matchDayPatterns, + defaultMatchWidth: 'wide', + parsePatterns: parseDayPatterns, + defaultParseWidth: 'any' + }), + + dayPeriod: buildMatchFn({ + matchPatterns: matchDayPeriodPatterns, + defaultMatchWidth: 'any', + parsePatterns: parseDayPeriodPatterns, + defaultParseWidth: 'any' + }) +} + +export default match diff --git a/src/locale/nn/index.d.ts b/src/locale/nn/index.d.ts new file mode 100644 index 0000000000..594a00a6bc --- /dev/null +++ b/src/locale/nn/index.d.ts @@ -0,0 +1,4 @@ +// This file is generated automatically by `scripts/build/typings.js`. Please, don't change it. + +import { nn } from 'date-fns/locale' +export = nn diff --git a/src/locale/nn/index.js b/src/locale/nn/index.js new file mode 100644 index 0000000000..f51296c04c --- /dev/null +++ b/src/locale/nn/index.js @@ -0,0 +1,27 @@ +import formatDistance from './_lib/formatDistance/index.js' +import formatLong from './_lib/formatLong/index.js' +import formatRelative from './_lib/formatRelative/index.js' +import localize from './_lib/localize/index.js' +import match from './_lib/match/index.js' + +/** + * @type {Locale} + * @category Locales + * @summary Norwegian Nynorsk locale. + * @language Norwegian Nynorsk + * @iso-639-2 nno + * @author Mats Byrkjeland [@draperunner]{@link https://github.com/draperunner} + */ +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/nn/index.js.flow b/src/locale/nn/index.js.flow new file mode 100644 index 0000000000..1fb5c2c1c0 --- /dev/null +++ b/src/locale/nn/index.js.flow @@ -0,0 +1,33 @@ +// @flow +// This file is generated automatically by `scripts/build/typings.js`. Please, don't change it. + +type Locale = { + formatDistance: Function, + formatRelative: Function, + localize: { + ordinalNumber: Function, + era: Function, + quarter: Function, + month: Function, + day: Function, + dayPeriod: Function + }, + formatLong: Object, + date: Function, + time: Function, + dateTime: Function, + match: { + ordinalNumber: Function, + era: Function, + quarter: Function, + month: Function, + day: Function, + dayPeriod: Function + }, + options?: { + weekStartsOn?: 0 | 1 | 2 | 3 | 4 | 5 | 6, + firstWeekContainsDate?: 1 | 2 | 3 | 4 | 5 | 6 | 7 + } +} + +declare module.exports: Locale diff --git a/src/locale/nn/test.js b/src/locale/nn/test.js new file mode 100644 index 0000000000..a4401f625d --- /dev/null +++ b/src/locale/nn/test.js @@ -0,0 +1,484 @@ +// @flow +/* eslint-env mocha */ + +import assert from 'power-assert' +import locale from '.' + +import format from '../../format' +import formatDistance from '../../formatDistance' +import formatDistanceStrict from '../../formatDistanceStrict' +import formatRelative from '../../formatRelative' +import parse from '../../parse' + +describe('nn locale', function() { + context('with `format`', function() { + var date = new Date(1986, 3 /* Apr */, 5, 10, 32, 0, 900) + + it('era', function() { + var result = format(date, 'G, GGGG, GGGGG', { locale: locale }) + assert(result === 'e.Kr., etter Kristus, e.Kr.') + }) + + describe('year', function() { + it('ordinal regular year', function() { + var result = format(date, "yo 'året'", { locale: locale }) + assert(result === '1986. året') + }) + + it('ordinal local week-numbering year', function() { + var result = format(date, "Yo 'veketeljande år'", { locale: locale }) + assert(result === '1986. veketeljande år') + }) + }) + + describe('quarter', function() { + it('formatting quarter', function() { + var result = format(date, "Qo 'kvartal', QQQ, QQQQ, QQQQQ", { + locale: locale + }) + assert(result === '2. kvartal, Q2, 2. kvartal, 2') + }) + + it('stand-alone quarter', function() { + var result = format(date, "qo 'kvartal', qqq, qqqq, qqqqq", { + locale: locale + }) + assert(result === '2. kvartal, Q2, 2. kvartal, 2') + }) + }) + + describe('month', function() { + it('formatting month', function() { + var result = format(date, 'do MMMM', { locale: locale }) + assert(result === '5. april') + }) + + it('stand-alone month', function() { + var result = format(date, "Lo 'månaden', LLL, LLLL", { locale: locale }) + assert(result === '4. månaden, apr., april') + }) + }) + + describe('week', function() { + it('ordinal local week of year', function() { + var date = new Date(1986, 3 /* Apr */, 6) + var result = format(date, "wo 'veka'", { locale: locale }) + assert(result === '14. veka') + }) + + it('ordinal ISO week of year', function() { + var date = new Date(1986, 3 /* Apr */, 6) + var result = format(date, "Io 'ISO-veka'", { locale: locale }) + assert(result === '14. ISO-veka') + }) + }) + + describe('day', function() { + it('ordinal date', function() { + var result = format(date, "'i dag er den' do", { locale: locale }) + assert(result === 'i dag er den 5.') + }) + + it('ordinal day of year', function() { + var result = format(date, "Do 'dagen i året'", { locale: locale }) + assert(result === '95. dagen i året') + }) + }) + + describe('week day', function() { + it('day of week', function() { + var result = format(date, 'E, EEEE, EEEEE, EEEEEE', { locale: locale }) + assert(result === 'laur, laurdag, L, lau') + }) + + it('ordinal day of week', function() { + var result = format(date, "eo 'dagen i veka'", { locale: locale }) + assert(result === '6. dagen i veka') + }) + }) + + describe('day period and hour', function() { + it('ordinal hour', function() { + var result = format(date, "ho 'timen'", { locale: locale }) + assert(result === '10. timen') + }) + + it('AM, PM', function() { + var result = format(date, 'h a, h aaaa, haaaaa', { locale: locale }) + assert(result === '10 a.m., 10 a.m., 10a') + }) + + it('AM, PM, noon, midnight', function() { + var result = format(new Date(1986, 3 /* Apr */, 6, 0), 'b, bbbb', { + locale: locale + }) + assert(result === 'midnatt, midnatt') + }) + + it('flexible day periods', function() { + it('works as expected', function() { + var result = format(date, 'h B', { locale: locale }) + assert(result === '10 på morgonen') + }) + }) + }) + + it('ordinal minute', function() { + var result = format(date, "mo 'minutt'", { locale: locale }) + assert(result === '32. minutt') + }) + + it('ordinal second', function() { + var result = format(date, "so 'sekund'", { locale: locale }) + assert(result === '0. sekund') + }) + + describe('long format', function() { + it('short date', function() { + var result = format(date, 'P', { locale: locale }) + assert(result === '05.04.1986') + }) + + it('medium date', function() { + var result = format(date, 'PP', { locale: locale }) + assert(result === '5. apr. 1986') + }) + + it('long date', function() { + var result = format(date, 'PPP', { locale: locale }) + assert(result === '5. april 1986') + }) + + it('full date', function() { + var result = format(date, 'PPPP', { locale: locale }) + assert(result === 'laurdag 5. april 1986') + }) + + it('short time', function() { + var result = format(date, 'p', { locale: locale }) + assert(result === '10:32') + }) + + it('medium time', function() { + var result = format(date, 'pp', { locale: locale }) + assert(result === '10:32:00') + }) + + it('short date + time', function() { + var result = format(date, 'Pp', { locale: locale }) + assert(result === '05.04.1986 10:32') + }) + + it('medium date + time', function() { + var result = format(date, 'PPpp', { locale: locale }) + assert(result === '5. apr. 1986 10:32:00') + }) + + it('long date + time', function() { + var result = format(date, 'PPPp', { locale: locale }) + assert(result === '5. april 1986 kl. 10:32') + }) + + it('full date + time', function() { + var result = format(date, 'PPPPp', { locale: locale }) + assert(result === 'laurdag 5. april 1986 kl. 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 === 'eit halvt minutt') + }) + + 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 === 'om mindre enn ti sekund') + }) + + 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 === 'omtrent ein time sidan') + }) + }) + }) + + 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: 'minute' } + ) + assert(result === '120 minutt') + }) + + 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 === 'om 25 sekund') + }) + + 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 === 'ein time sidan') + }) + }) + }) + + 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 === 'førre tysdag kl. 00:00') + }) + + it('yesterday', function() { + var result = formatRelative( + new Date(1986, 3 /* Apr */, 3, 22, 22), + baseDate, + { locale: locale } + ) + assert(result === 'i går kl. 22:22') + }) + + it('today', function() { + var result = formatRelative( + new Date(1986, 3 /* Apr */, 4, 16, 50), + baseDate, + { locale: locale } + ) + assert(result === 'i dag kl. 16:50') + }) + + it('tomorrow', function() { + var result = formatRelative( + new Date(1986, 3 /* Apr */, 5, 7, 30), + baseDate, + { locale: locale } + ) + assert(result === 'i morgon kl. 07:30') + }) + + it('next week', function() { + var result = formatRelative( + new Date(1986, 3 /* Apr */, 6, 12, 0), + baseDate, + { locale: locale } + ) + assert(result === 'sundag kl. 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 `parse`', function() { + var baseDate = new Date(1986, 3 /* Apr */, 4, 10, 32, 0, 900) + + describe('era', function() { + it('abbreviated', function() { + var result = parse('10000 f.Kr.', 'yyyyy G', baseDate, { + locale: locale + }) + assert.deepEqual(result, new Date(-9999, 0 /* Jan */, 1)) + }) + + it('wide', function() { + var result = parse('2018 etter Kristus', 'yyyy GGGG', baseDate, { + locale: locale + }) + assert.deepEqual(result, new Date(2018, 0 /* Jan */, 1)) + }) + + it('narrow', function() { + var result = parse('44 f.Kr.', 'y GGGGG', baseDate, { locale: locale }) + assert.deepEqual(result, new Date(-43, 0 /* Jan */, 1)) + }) + }) + + it('ordinal year', function() { + var result = parse('2017.', 'yo', baseDate, { locale: locale }) + assert.deepEqual(result, new Date(2017, 0 /* Jan */, 1)) + }) + + describe('quarter', function() { + it('ordinal', function() { + var result = parse('1.', 'Qo', baseDate, { locale: locale }) + assert.deepEqual(result, new Date(1986, 0 /* Jan */, 1)) + }) + + it('abbreviated', function() { + var result = parse('Q3', 'QQQ', baseDate, { locale: locale }) + assert.deepEqual(result, new Date(1986, 6 /* Jul */, 1)) + }) + + it('wide', function() { + var result = parse('4. kvartal', 'QQQQ', baseDate, { locale: locale }) + assert.deepEqual(result, new Date(1986, 9 /* Oct */, 1)) + }) + + it('narrow', function() { + var result = parse('1', 'QQQQQ', baseDate, { locale: locale }) + assert.deepEqual(result, new Date(1986, 0 /* Jan */, 1)) + }) + }) + + describe('month', function() { + it('ordinal', function() { + var result = parse('6.', 'Mo', baseDate, { locale: locale }) + assert.deepEqual(result, new Date(1986, 5 /* Jun */, 1)) + }) + + it('abbreviated', function() { + var result = parse('nov.', 'MMM', baseDate, { locale: locale }) + assert.deepEqual(result, new Date(1986, 10 /* Nov */, 1)) + }) + + it('wide', function() { + var result = parse('februar', 'MMMM', baseDate, { locale: locale }) + assert.deepEqual(result, new Date(1986, 1 /* Feb */, 1)) + }) + + it('narrow', function() { + var result = parse('J', 'MMMMM', baseDate, { locale: locale }) + assert.deepEqual(result, new Date(1986, 0 /* Jan */, 1)) + }) + }) + + it('ordinal week of year', function() { + var result = parse('49.', 'wo', baseDate, { locale: locale }) + assert.deepEqual(result, new Date(1986, 10 /* Nov */, 31)) + }) + + it('ordinal day of month', function() { + var result = parse('28.', 'do', baseDate, { locale: locale }) + assert.deepEqual(result, new Date(1986, 3 /* Apr */, 28)) + }) + + it('ordinal day of year', function() { + var result = parse('200.', 'Do', baseDate, { locale: locale }) + assert.deepEqual(result, new Date(1986, 6 /* Jul */, 19)) + }) + + describe('day of week', function() { + it('abbreviated', function() { + var result = parse('mån', 'E', baseDate, { locale: locale }) + assert.deepEqual(result, new Date(1986, 2 /* Mar */, 31)) + }) + + it('wide', function() { + var result = parse('tysdag', 'EEEE', baseDate, { locale: locale }) + assert.deepEqual(result, new Date(1986, 3 /* Apr */, 1)) + }) + + it('narrow', function() { + var result = parse('O', 'EEEEE', baseDate, { locale: locale }) + assert.deepEqual(result, new Date(1986, 3 /* Apr */, 2)) + }) + + it('short', function() { + var result = parse('to', 'EEEEEE', baseDate, { locale: locale }) + assert.deepEqual(result, new Date(1986, 3 /* Apr */, 3)) + }) + }) + + it('ordinal local day of week', function() { + var result = parse('2.', 'eo', baseDate, { locale: locale }) + assert.deepEqual(result, new Date(1986, 3 /* Apr */, 1)) + }) + + describe('AM, PM', function() { + it('abbreviated', function() { + var result = parse('5 AM', 'h a', baseDate, { locale: locale }) + assert.deepEqual(result, new Date(1986, 3 /* Apr */, 4, 5)) + }) + + it('wide', function() { + var result = parse('5 p.m.', 'h aaaa', baseDate, { locale: locale }) + assert.deepEqual(result, new Date(1986, 3 /* Apr */, 4, 17)) + }) + + it('narrow', function() { + var result = parse('11 a', 'h aaaaa', baseDate, { locale: locale }) + assert.deepEqual(result, new Date(1986, 3 /* Apr */, 4, 11)) + }) + }) + + describe('AM, PM, noon, midnight', function() { + it('abbreviated', function() { + var result = parse('middag', 'b', baseDate, { locale: locale }) + assert.deepEqual(result, new Date(1986, 3 /* Apr */, 4, 12)) + }) + + it('wide', function() { + var result = parse('midnatt', 'bbbb', baseDate, { locale: locale }) + assert.deepEqual(result, new Date(1986, 3 /* Apr */, 4, 0)) + }) + + it('narrow', function() { + var result = parse('midnatt', 'bbbbb', baseDate, { locale: locale }) + assert.deepEqual(result, new Date(1986, 3 /* Apr */, 4, 0)) + }) + }) + + describe('flexible day period', function() { + it('abbreviated', function() { + var result = parse('02 på natta', 'HH B', baseDate, { locale: locale }) + assert.deepEqual(result, new Date(1986, 3 /* Apr */, 4, 2)) + }) + + it('wide', function() { + var result = parse('12 på ettermiddagen', 'HH BBBB', baseDate, { + locale: locale + }) + assert.deepEqual(result, new Date(1986, 3 /* Apr */, 4, 12)) + }) + + it('narrow', function() { + var result = parse('17 på kvelden', 'HH BBBBB', baseDate, { + locale: locale + }) + assert.deepEqual(result, new Date(1986, 3 /* Apr */, 4, 17)) + }) + }) + + it('ordinal time', function() { + var dateString = '1. time, 2. minuttet, 3. sekundet' + var formatString = "ho 'time', mo 'minuttet', so 'sekundet'" + var result = parse(dateString, formatString, baseDate, { locale: locale }) + assert.deepEqual(result, new Date(1986, 3 /* Apr */, 4, 1, 2, 3)) + }) + }) +}) diff --git a/typings.d.ts b/typings.d.ts index f6d5dcc595..8a8b37aa11 100644 --- a/typings.d.ts +++ b/typings.d.ts @@ -14269,6 +14269,11 @@ declare module 'date-fns/locale' { } + const nn: Locale + namespace nn { + + } + const pl: Locale namespace pl { @@ -14535,6 +14540,11 @@ declare module 'date-fns/locale/nl-BE' { export = nlBE } +declare module 'date-fns/locale/nn' { + import { nn } from 'date-fns/locale' + export = nn +} + declare module 'date-fns/locale/pl' { import { pl } from 'date-fns/locale' export = pl @@ -14800,6 +14810,11 @@ declare module 'date-fns/locale/nl-BE/index' { export = nlBE } +declare module 'date-fns/locale/nn/index' { + import { nn } from 'date-fns/locale' + export = nn +} + declare module 'date-fns/locale/pl/index' { import { pl } from 'date-fns/locale' export = pl @@ -15065,6 +15080,11 @@ declare module 'date-fns/locale/nl-BE/index.js' { export = nlBE } +declare module 'date-fns/locale/nn/index.js' { + import { nn } from 'date-fns/locale' + export = nn +} + declare module 'date-fns/locale/pl/index.js' { import { pl } from 'date-fns/locale' export = pl @@ -15333,6 +15353,11 @@ declare module 'date-fns/esm/locale' { } + const nn: Locale + namespace nn { + + } + const pl: Locale namespace pl { @@ -15599,6 +15624,11 @@ declare module 'date-fns/esm/locale/nl-BE' { export default nlBE } +declare module 'date-fns/esm/locale/nn' { + import { nn } from 'date-fns/esm/locale' + export default nn +} + declare module 'date-fns/esm/locale/pl' { import { pl } from 'date-fns/esm/locale' export default pl @@ -15864,6 +15894,11 @@ declare module 'date-fns/esm/locale/nl-BE/index' { export default nlBE } +declare module 'date-fns/esm/locale/nn/index' { + import { nn } from 'date-fns/esm/locale' + export default nn +} + declare module 'date-fns/esm/locale/pl/index' { import { pl } from 'date-fns/esm/locale' export default pl @@ -16129,6 +16164,11 @@ declare module 'date-fns/esm/locale/nl-BE/index.js' { export default nlBE } +declare module 'date-fns/esm/locale/nn/index.js' { + import { nn } from 'date-fns/esm/locale' + export default nn +} + declare module 'date-fns/esm/locale/pl/index.js' { import { pl } from 'date-fns/esm/locale' export default pl