diff --git a/src/esm/locale/index.js b/src/esm/locale/index.js index b872460dfc..bcde8d7149 100644 --- a/src/esm/locale/index.js +++ b/src/esm/locale/index.js @@ -8,6 +8,8 @@ export {default as eo} from './eo/index.js' export {default as es} from './es/index.js' export {default as fr} from './fr/index.js' export {default as he} from './he/index.js' +export {default as hu} from './hu/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 ptBR} from './pt-BR/index.js' diff --git a/src/locale/hu/_lib/formatDistance/index.js b/src/locale/hu/_lib/formatDistance/index.js new file mode 100644 index 0000000000..ee7fa7c370 --- /dev/null +++ b/src/locale/hu/_lib/formatDistance/index.js @@ -0,0 +1,135 @@ +var formatDistanceLocale = { + lessThanXSeconds: { + one: translate, + other: translate + }, + + xSeconds: { + one: translate, + other: translate + }, + + halfAMinute: 'fél perce', + + lessThanXMinutes: { + one: translate, + other: translate + }, + + xMinutes: { + one: translate, + other: translate + }, + + aboutXHours: { + one: translate, + other: translate + }, + + xHours: { + one: translate, + other: translate + }, + + xDays: { + one: translate, + other: translate + }, + + aboutXMonths: { + one: translate, + other: translate + }, + + xMonths: { + one: translate, + other: translate + }, + + aboutXYears: { + one: translate, + other: translate + }, + + xYears: { + one: translate, + other: translate + }, + + overXYears: { + one: translate, + other: translate + }, + + almostXYears: { + one: translate, + other: translate + } +} + +var translations = { + 'about': 'körülbelül', + 'over': 'több mint', + 'almost': 'majdnem', + 'lessthan': 'kevesebb, mint' +} + +function translate (number, addSuffix, key, isFuture) { + var num = number + switch (key) { + case 'xseconds_one': + return (isFuture || !addSuffix) ? 'néhány másodperc' : 'néhány másodperce' + case 'xseconds_other': + return num + ((isFuture || !addSuffix) ? ' másodperc' : ' másodperce') + case 'xminutes_one': + return 'egy' + (isFuture || !addSuffix ? ' perc' : ' perce') + case 'xminutes_other': + return num + ((isFuture || !addSuffix ? ' perc' : ' perce')) + case 'xhours_one': + return 'egy' + (isFuture || !addSuffix ? ' óra' : ' órája') + case 'xhours_other': + return num + ((isFuture || !addSuffix ? ' óra' : ' órája')) + case 'xdays_one': + return 'egy' + (isFuture || !addSuffix ? ' nap' : ' napja') + case 'xdays_other': + return num + ((isFuture || !addSuffix ? ' nap' : ' napja')) + case 'xmonths_one': + return 'egy' + (isFuture || !addSuffix ? ' hónap' : ' hónapja') + case 'xmonths_other': + return num + ((isFuture || !addSuffix ? ' hónap' : ' hónapja')) + case 'xyears_one': + return 'egy' + (isFuture || !addSuffix ? ' év' : ' éve') + case 'xyears_other': + return num + ((isFuture || !addSuffix ? ' év' : ' éve')) + } + return '' +} + +export default function formatDistance (token, count, options) { + options = options || {} + var adverb = token.match(/about|over|almost|lessthan/i) + var unit = token.replace(adverb, '') + + var result + if (typeof formatDistanceLocale[token] === 'string') { + result = formatDistanceLocale[token] + } else if (count === 1) { + result = formatDistanceLocale[token].one(count, options.addSuffix, unit.toLowerCase() + '_one', options.comparison > 0) + } else { + result = formatDistanceLocale[token].other(count, options.addSuffix, unit.toLowerCase() + '_other', options.comparison > 0) + } + + if (adverb) { + result = translations[adverb[0].toLowerCase()] + ' ' + result + } + + if (options.addSuffix) { + if (options.comparison > 0) { + return result + ' múlva' + } else { + return result + ' ezelőtt' + } + } + + return result +} diff --git a/src/locale/hu/_lib/formatDistance/test.js b/src/locale/hu/_lib/formatDistance/test.js new file mode 100644 index 0000000000..69d595100f --- /dev/null +++ b/src/locale/hu/_lib/formatDistance/test.js @@ -0,0 +1,219 @@ +// @flow +/* eslint-env mocha */ + +import assert from 'power-assert' +import formatDistance from '.' + +describe('hu locale > formatDistance', function () { + describe('lessThanXSeconds', function () { + context('when the count equals 1', function () { + it('returns a proper string', function () { + assert(formatDistance('lessThanXSeconds', 1) === 'kevesebb, mint néhány másodperc') + }) + }) + + context('when the count is more than 1', function () { + it('returns a proper string', function () { + assert(formatDistance('lessThanXSeconds', 2) === 'kevesebb, mint 2 másodperc') + }) + }) + }) + + describe('xSeconds', function () { + context('when the count equals 1', function () { + it('returns a proper string', function () { + assert(formatDistance('xSeconds', 1) === 'néhány másodperc') + }) + }) + + context('when the count is more than 1', function () { + it('returns a proper string', function () { + assert(formatDistance('xSeconds', 2) === '2 másodperc') + }) + }) + }) + + describe('halfAMinute', function () { + it('returns a proper string', function () { + assert(formatDistance('halfAMinute') === 'fél perce') + }) + + it('ignores the second argument', function () { + assert(formatDistance('halfAMinute', 123) === 'fél perce') + }) + }) + + describe('lessThanXMinutes', function () { + context('when the count equals 1', function () { + it('returns a proper string', function () { + assert(formatDistance('lessThanXMinutes', 1) === 'kevesebb, mint egy perc') + }) + }) + + context('when the count is more than 1', function () { + it('returns a proper string', function () { + assert(formatDistance('lessThanXMinutes', 2) === 'kevesebb, mint 2 perc') + }) + }) + }) + + describe('xMinutes', function () { + context('when the count equals 1', function () { + it('returns a proper string', function () { + assert(formatDistance('xMinutes', 1) === 'egy perc') + }) + }) + + context('when the count is more than 1', function () { + it('returns a proper string', function () { + assert(formatDistance('xMinutes', 2) === '2 perc') + }) + }) + }) + + describe('aboutXHours', function () { + context('when the count equals 1', function () { + it('returns a proper string', function () { + assert(formatDistance('aboutXHours', 1) === 'körülbelül egy óra') + }) + }) + + context('when the count is more than 1', function () { + it('returns a proper string', function () { + assert(formatDistance('aboutXHours', 2) === 'körülbelül 2 óra') + }) + }) + }) + + describe('xHours', function () { + context('when the count equals 1', function () { + it('returns a proper string', function () { + assert(formatDistance('xHours', 1) === 'egy óra') + }) + }) + + context('when the count is more than 1', function () { + it('returns a proper string', function () { + assert(formatDistance('xHours', 2) === '2 óra') + }) + }) + }) + + describe('xDays', function () { + context('when the count equals 1', function () { + it('returns a proper string', function () { + assert(formatDistance('xDays', 1) === 'egy nap') + }) + }) + + context('when the count is more than 1', function () { + it('returns a proper string', function () { + assert(formatDistance('xDays', 2) === '2 nap') + }) + }) + }) + + describe('aboutXMonths', function () { + context('when the count equals 1', function () { + it('returns a proper string', function () { + assert(formatDistance('aboutXMonths', 1) === 'körülbelül egy hónap') + }) + }) + + context('when the count is more than 1', function () { + it('returns a proper string', function () { + assert(formatDistance('aboutXMonths', 2) === 'körülbelül 2 hónap') + }) + }) + }) + + describe('xMonths', function () { + context('when the count equals 1', function () { + it('returns a proper string', function () { + assert(formatDistance('xMonths', 1) === 'egy hónap') + }) + }) + + context('when the count is more than 1', function () { + it('returns a proper string', function () { + assert(formatDistance('xMonths', 2) === '2 hónap') + }) + }) + }) + + describe('aboutXYears', function () { + context('when the count equals 1', function () { + it('returns a proper string', function () { + assert(formatDistance('aboutXYears', 1) === 'körülbelül egy év') + }) + }) + + context('when the count is more than 1', function () { + it('returns a proper string', function () { + assert(formatDistance('aboutXYears', 2) === 'körülbelül 2 év') + }) + }) + }) + + describe('xYears', function () { + context('when the count equals 1', function () { + it('returns a proper string', function () { + assert(formatDistance('xYears', 1) === 'egy év') + }) + }) + + context('when the count is more than 1', function () { + it('returns a proper string', function () { + assert(formatDistance('xYears', 2) === '2 év') + }) + }) + }) + + describe('overXYears', function () { + context('when the count equals 1', function () { + it('returns a proper string', function () { + assert(formatDistance('overXYears', 1) === 'több mint egy év') + }) + }) + + context('when the count is more than 1', function () { + it('returns a proper string', function () { + assert(formatDistance('overXYears', 2) === 'több mint 2 év') + }) + }) + }) + + describe('almostXYears', function () { + context('when the count equals 1', function () { + it('returns a proper string', function () { + assert(formatDistance('almostXYears', 1) === 'majdnem egy év') + }) + }) + + context('when the count is more than 1', function () { + it('returns a proper string', function () { + assert(formatDistance('almostXYears', 2) === 'majdnem 2 év') + }) + }) + }) + + context('with a past suffix', function () { + it('adds `ezelőtt` to a string', function () { + var result = formatDistance('aboutXYears', 1, { + addSuffix: true, + comparison: -1 + }) + assert(result === 'körülbelül egy éve ezelőtt') + }) + }) + + context('with a future suffix', function () { + it('adds `múlva` to a string', function () { + var result = formatDistance('halfAMinute', null, { + addSuffix: true, + comparison: 1 + }) + assert(result === 'fél perce múlva') + }) + }) +}) diff --git a/src/locale/hu/_lib/formatLong/index.js b/src/locale/hu/_lib/formatLong/index.js new file mode 100644 index 0000000000..269c1b7c5e --- /dev/null +++ b/src/locale/hu/_lib/formatLong/index.js @@ -0,0 +1,41 @@ +import buildFormatLongFn from '../../../_lib/buildFormatLongFn/index.js' + +var dateFormats = { + full: 'y. MMMM d., EEEE', + long: 'y. MMMM d.', + medium: 'y. MMM d.', + short: 'y. MM. dd.' +} + +var timeFormats = { + full: 'H:mm:ss zzzz', + long: 'H:mm:ss z', + medium: 'H:mm:ss', + short: 'H:mm' +} + +var dateTimeFormats = { + full: '{{date}} {{time}}', + long: '{{date}} {{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/hu/_lib/formatRelative/index.js b/src/locale/hu/_lib/formatRelative/index.js new file mode 100644 index 0000000000..b8b769429c --- /dev/null +++ b/src/locale/hu/_lib/formatRelative/index.js @@ -0,0 +1,27 @@ + +var accusativeWeekdays = ['vasárnap', 'hétfőn', 'kedden', 'szerdán', 'csütörtökön', 'pénteken', 'szombaton'] + +function week (isFuture) { + return function (date, baseDate, options) { + var day = date.getUTCDay() + return (isFuture ? '' : "'múlt' ") + "'" + accusativeWeekdays[day] + "'" + " p'-kor'" + } +} +var formatRelativeLocale = { + lastWeek: week(false), + yesterday: "'tegnap' p'-kor'", + today: "'ma' p'-kor'", + tomorrow: "'holnap' p'-kor'", + nextWeek: week(true), + other: 'P' +} + +export default function formatRelative (token, date, baseDate, options) { + var format = formatRelativeLocale[token] + + if (typeof format === 'function') { + return format(date, baseDate, options) + } + + return format +} diff --git a/src/locale/hu/_lib/localize/index.js b/src/locale/hu/_lib/localize/index.js new file mode 100644 index 0000000000..6ce1d9ad02 --- /dev/null +++ b/src/locale/hu/_lib/localize/index.js @@ -0,0 +1,106 @@ +import buildLocalizeFn from '../../../_lib/buildLocalizeFn/index.js' + +var eraValues = { + narrow: ['ie.', 'isz.'], + abbreviated: ['i. e.', 'i. sz.'], + wide: ['Krisztus előtt', 'időszámításunk szerint'] +} + +var quarterValues = { + narrow: ['1.', '2.', '3.', '4.'], + abbreviated: ['1. n.év', '2. n.év', '3. n.év', '4. n.év'], + wide: ['1. negyedév', '2. negyedév', '3. negyedév', '4. negyedév'] +} + +var formattingQuarterValues = { + narrow: ['I.', 'II.', 'III.', 'IV.'], + abbreviated: ['I. n.év', 'II. n.év', 'III. n.év', 'IV. n.év'], + wide: ['I. negyedév', 'II. negyedév', 'III. negyedév', 'IV. negyedév'] +} + +var monthValues = { + narrow: ['J', 'F', 'M', 'Á', 'M', 'J', 'J', 'A', 'Sz', 'O', 'N', 'D'], + abbreviated: ['jan.', 'febr.', 'márc.', 'ápr.', 'máj.', 'jún.', 'júl.', 'aug.', 'szept.', 'okt.', 'nov.', 'dec.'], + wide: ['január', 'február', 'március', 'április', 'május', 'június', 'július', 'augusztus', 'szeptember', 'október', 'november', 'december'] +} + +var dayValues = { + narrow: ['V', 'H', 'K', 'Sz', 'Cs', 'P', 'Sz'], + short: ['V', 'H', 'K', 'Sze', 'Cs', 'P', 'Szo'], + abbreviated: ['V', 'H', 'K', 'Sze', 'Cs', 'P', 'Szo'], + wide: ['vasárnap', 'hétfő', 'kedd', 'szerda', 'csütörtök', 'péntek', 'szombat'] +} + +var dayPeriodValues = { + narrow: { + am: 'de.', + pm: 'du.', + midnight: 'éjfél', + noon: 'dél', + morning: 'reggel', + afternoon: 'du.', + evening: 'este', + night: 'éjjel' + }, + abbreviated: { + am: 'de.', + pm: 'du.', + midnight: 'éjfél', + noon: 'dél', + morning: 'reggel', + afternoon: 'du.', + evening: 'este', + night: 'éjjel' + }, + wide: { + am: 'de.', + pm: 'du.', + midnight: 'éjfél', + noon: 'dél', + morning: 'reggel', + afternoon: 'délután', + evening: 'este', + night: 'éjjel' + } +} + +function ordinalNumber (dirtyNumber, dirtyOptions) { + var number = Number(dirtyNumber) + return number + '.' +} + +var localize = { + ordinalNumber: ordinalNumber, + + era: buildLocalizeFn({ + values: eraValues, + defaultWidth: 'wide' + }), + + quarter: buildLocalizeFn({ + values: quarterValues, + defaultWidth: 'wide', + formattingValues: formattingQuarterValues, + 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', + defaulFormattingWidth: 'wide' + }) +} + +export default localize diff --git a/src/locale/hu/_lib/match/index.js b/src/locale/hu/_lib/match/index.js new file mode 100644 index 0000000000..d26883923e --- /dev/null +++ b/src/locale/hu/_lib/match/index.js @@ -0,0 +1,112 @@ +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: /^(ie\.|isz\.)/i, + abbreviated: /^(i\.\s?e\.?|b?\s?c\s?e|i\.\s?sz\.?)/i, + wide: /^(Krisztus előtt|időszámításunk előtt|időszámításunk szerint|i\. sz\.)/i +} +var parseEraPatterns = { + narrow: [/ie/i, /isz/i], + abbreviated: [/^(i\.?\s?e\.?|b\s?ce)/i, /^(i\.?\s?sz\.?|c\s?e)/i], + any: [/előtt/i, /(szerint|i. sz.)/i] +} + +var matchQuarterPatterns = { + narrow: /^[1234]\.?/i, + abbreviated: /^[1234]?\.?\s?n\.év/i, + wide: /^([1234]|I|II|III|IV)?\.?\s?negyedév/i +} +var parseQuarterPatterns = { + any: [/1|I$/i, /2|II$/i, /3|III/i, /4|IV/i] +} + +var matchMonthPatterns = { + narrow: /^[jfmaásond]|sz/i, + abbreviated: /^(jan\.?|febr\.?|márc\.?|ápr\.?|máj\.?|jún\.?|júl\.?|aug\.?|szept\.?|okt\.?|nov\.?|dec\.?)/i, + wide: /^(január|február|március|április|május|június|július|augusztus|szeptember|október|november|december)/i +} +var parseMonthPatterns = { + narrow: [/^j/i, /^f/i, /^m/i, /^a|á/i, /^m/i, /^j/i, /^j/i, /^a/i, /^s|sz/i, /^o/i, /^n/i, /^d/i], + any: [/^ja/i, /^f/i, /^már/i, /^áp/i, /^máj/i, /^jún/i, /^júl/i, /^au/i, /^s/i, /^o/i, /^n/i, /^d/i] +} + +var matchDayPatterns = { + narrow: /^([vhkpc]|sz|cs|sz)/i, + short: /^([vhkp]|sze|cs|szo)/i, + abbreviated: /^([vhkp]|sze|cs|szo)/i, + wide: /^(vasárnap|hétfő|kedd|szerda|csütörtök|péntek|szombat)/i +} +var parseDayPatterns = { + narrow: [/^v/i, /^h/i, /^k/i, /^sz/i, /^c/i, /^p/i, /^sz/i], + any: [/^v/i, /^h/i, /^k/i, /^sze/i, /^c/i, /^p/i, /^szo/i] +} + +var matchDayPeriodPatterns = { + any: /^((de|du)\.?|éjfél|délután|dél|reggel|este|éjjel)/i +} +var parseDayPeriodPatterns = { + any: { + am: /^de\.?/i, + pm: /^du\.?/i, + midnight: /^éjf/i, + noon: /^dé/i, + morning: /reg/i, + afternoon: /^délu\.?/i, + evening: /es/i, + night: /éjj/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/hu/index.d.ts b/src/locale/hu/index.d.ts new file mode 100644 index 0000000000..6d85a3484d --- /dev/null +++ b/src/locale/hu/index.d.ts @@ -0,0 +1,4 @@ +// This file is generated automatically by `scripts/build/typings.js`. Please, don't change it. + +import {hu} from 'date-fns/locale' +export = hu diff --git a/src/locale/hu/index.js b/src/locale/hu/index.js new file mode 100644 index 0000000000..ab97fd6910 --- /dev/null +++ b/src/locale/hu/index.js @@ -0,0 +1,31 @@ +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 Hungarian locale. + * @language Hungarian + * + * @iso-639-2 hun + * + * @author Pavlo Shpak [@pshpak]{@link https://github.com/pshpak} + * @author Eduardo Pardo [@eduardopsll]{@link https://github.com/eduardopsll} + */ +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/hu/index.js.flow b/src/locale/hu/index.js.flow new file mode 100644 index 0000000000..1fb5c2c1c0 --- /dev/null +++ b/src/locale/hu/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/hu/test.js b/src/locale/hu/test.js new file mode 100644 index 0000000000..8039661809 --- /dev/null +++ b/src/locale/hu/test.js @@ -0,0 +1,453 @@ +// @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('hu 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 === 'i. sz., időszámításunk szerint, isz.') + }) + + describe('year', function () { + it('ordinal regular year', function () { + var result = format(date, "yo 'Év'", {locale: locale}) + assert(result === '1986. Év') + }) + + it('ordinal local week-numbering year', function () { + var result = format(date, "Yo 'hétszámozási év'", {locale: locale}) + assert(result === '1986. hétszámozási év') + }) + }) + + describe('quarter', function () { + it('formatting quarter', function () { + var result = format(date, 'Qo, QQQ, QQQQ, QQQQQ', {locale: locale}) + assert(result === '2., II. n.év, II. negyedév, II.') + }) + + it('stand-alone quarter', function () { + var result = format(date, 'qo, qqq, qqqq, qqqqq', {locale: locale}) + assert(result === '2., 2. n.év, 2. negyedév, 2.') + }) + }) + + describe('month', function () { + it('formatting month', function () { + var result = format(date, 'MMMM do', {locale: locale}) + assert(result === 'április 5.') + }) + + it('stand-alone month', function () { + var result = format(date, "Lo 'hónap', LLL, LLLL, LLLLL", {locale: locale}) + assert(result === '4. hónap, ápr., április, Á') + }) + }) + + describe('week', function () { + it('ordinal local week of year', function () { + var date = new Date(1986, 3 /* Apr */, 6) + var result = format(date, "wo 'hét'", {locale: locale}) + assert(result === '14. hét') + }) + + it('ordinal ISO week of year', function () { + var date = new Date(1986, 3 /* Apr */, 6) + var result = format(date, "Io 'ISO hét'", {locale: locale}) + assert(result === '14. ISO hét') + }) + }) + + describe('day', function () { + it('ordinal date', function () { + var result = format(date, "'ma az' do", {locale: locale}) + assert(result === 'ma az 5.') + }) + + it('ordinal day of year', function () { + var result = format(date, "'Az év' 95. 'napján'", {locale: locale}) + assert(result === 'Az év 95. napján') + }) + }) + + describe('week day', function () { + it('day of week', function () { + var result = format(date, 'E, EEEE, EEEEE, EEEEEE', {locale: locale}) + assert(result === 'Szo, szombat, Sz, Szo') + }) + + it('ordinal day of week', function () { + var result = format(date, "'A hét' eo 'napja'", {locale: locale}) + assert(result === 'A hét 6. napja') + }) + }) + + describe('day period and hour', function () { + it('ordinal hour', function () { + var result = format(date, "ho 'óra'", {locale: locale}) + assert(result === '10. óra') + }) + + it('AM, PM', function () { + var result = format(date, 'h a, h aaaa, haaaaa', {locale: locale}) + assert(result === '10 de., 10 de., 10de.') + }) + + it('AM, PM, noon, midnight', function () { + var result = format(new Date(1986, 3 /* Apr */, 6, 0), 'b, bbbb, bbbbb', {locale: locale}) + assert(result === 'éjfél, éjfél, éjfél') + }) + + it('flexible day periods', function () { + it('works as expected', function () { + var result = format(date, 'h B', {locale: locale}) + assert(result === '10 in the morning') + }) + }) + }) + + it('ordinal minute', function () { + var result = format(date, "mo 'minute'", {locale: locale}) + assert(result === '32. minute') + }) + + it('ordinal second', function () { + var result = format(date, "so 'second'", {locale: locale}) + assert(result === '0. second') + }) + + describe('long format', function () { + it('short date', function () { + var result = format(date, 'P', {locale: locale}) + assert(result === '1986. 04. 05.') + }) + + it('medium date', function () { + var result = format(date, 'PP', {locale: locale}) + assert(result === '1986. ápr. 5.') + }) + + it('long date', function () { + var result = format(date, 'PPP', {locale: locale}) + assert(result === '1986. április 5.') + }) + + it('full date', function () { + var result = format(date, 'PPPP', {locale: locale}) + assert(result === '1986. április 5., szombat') + }) + + 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 === '1986. 04. 05. 10:32') + }) + + it('medium date + time', function () { + var result = format(date, 'PPpp', {locale: locale}) + assert(result === '1986. ápr. 5. 10:32:00') + }) + + it('long date + time', function () { + var result = format(date, 'PPPp', {locale: locale}) + assert(result === '1986. április 5. 10:32') + }) + + it('full date + time', function () { + var result = format(date, 'PPPPp', {locale: locale}) + assert(result === '1986. április 5., szombat 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 === 'fél perce') + }) + + 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 === 'kevesebb, mint 10 másodperc múlva') + }) + + 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 === 'körülbelül egy órája ezelőtt') + }) + }) + }) + + 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 perc') + }) + + 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 === '25 másodperc múlva') + }) + + 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 === 'egy órája ezelőtt') + }) + }) + }) + + 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 === 'múlt kedden 0:00-kor') + }) + + it('yesterday', function () { + var result = formatRelative(new Date(1986, 3 /* Apr */, 3, 22, 22), baseDate, {locale: locale}) + assert(result === 'tegnap 22:22-kor') + }) + + it('today', function () { + var result = formatRelative(new Date(1986, 3 /* Apr */, 4, 16, 50), baseDate, {locale: locale}) + assert(result === 'ma 16:50-kor') + }) + + it('tomorrow', function () { + var result = formatRelative(new Date(1986, 3 /* Apr */, 5, 7, 30), baseDate, {locale: locale}) + assert(result === 'holnap 7:30-kor') + }) + + it('next week', function () { + var result = formatRelative(new Date(1986, 3 /* Apr */, 6, 12, 0), baseDate, {locale: locale}) + assert(result === 'vasárnap 12:00-kor') + }) + + it('after the next week', function () { + var result = formatRelative(new Date(1986, 3 /* Apr */, 11, 16, 50), baseDate, {locale: locale}) + assert(result === '1986. 04. 11.') + }) + }) + + 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 i. e.', 'yyyyy G', baseDate, {locale: locale}) + assert.deepEqual(result, new Date(-9999, 0 /* Jan */, 1)) + }) + + it('wide', function () { + var result = parse('2018 időszámításunk szerint', 'yyyy GGGG', baseDate, {locale: locale}) + assert.deepEqual(result, new Date(2018, 0 /* Jan */, 1)) + }) + + it('narrow', function () { + var result = parse('44 ie.', 'y GGGGG', baseDate, {locale: locale}) + assert.deepEqual(result, new Date(-43, 0 /* Jan */, 1)) + }) + + it('narrow', function () { + var result = parse('2018 isz.', 'yyyy GGGG', baseDate, {locale: locale}) + assert.deepEqual(result, new Date(2018, 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('3. n.év', 'QQQ', baseDate, {locale: locale}) + assert.deepEqual(result, new Date(1986, 6 /* Jul */, 1)) + }) + + it('wide', function () { + var result = parse('4. negyedév', '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('február', '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('48.', 'wo', baseDate, {locale: locale}) + assert.deepEqual(result, new Date(1986, 10 /* Nov */, 24)) + }) + + 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('H', 'E', baseDate, {locale: locale}) + assert.deepEqual(result, new Date(1986, 2 /* Mar */, 31)) + }) + + it('wide', function () { + var result = parse('kedd', 'EEEE', baseDate, {locale: locale}) + assert.deepEqual(result, new Date(1986, 3 /* Apr */, 1)) + }) + + it('narrow', function () { + var result = parse('Sz', 'EEEEE', baseDate, {locale: locale}) + assert.deepEqual(result, new Date(1986, 3 /* Apr */, 2)) + }) + + it('short', function () { + var result = parse('Cs', 'EEEEEE', baseDate, {locale: locale}) + assert.deepEqual(result, new Date(1986, 3 /* Apr */, 3)) + }) + }) + + it('ordinal local day of week', function () { + var result = parse('2. hét napja', "eo 'hét napja'", baseDate, {locale: locale}) + assert.deepEqual(result, new Date(1986, 3 /* Apr */, 1)) + }) + + describe('AM, PM', function () { + it('abbreviated', function () { + var result = parse('5 de.', 'h a', baseDate, {locale: locale}) + assert.deepEqual(result, new Date(1986, 3 /* Apr */, 4, 5)) + }) + + it('wide', function () { + var result = parse('5 du.', 'h aaaa', baseDate, {locale: locale}) + assert.deepEqual(result, new Date(1986, 3 /* Apr */, 4, 17)) + }) + + it('narrow', function () { + var result = parse('11 de.', '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('dél', 'b', baseDate, {locale: locale}) + assert.deepEqual(result, new Date(1986, 3 /* Apr */, 4, 12)) + }) + + it('wide', function () { + var result = parse('éjfél', 'bbbb', baseDate, {locale: locale}) + assert.deepEqual(result, new Date(1986, 3 /* Apr */, 4, 0)) + }) + + it('narrow', function () { + var result = parse('éjfél', '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('2 éjjel', 'h B', baseDate, {locale: locale}) + assert.deepEqual(result, new Date(1986, 3 /* Apr */, 4, 2)) + }) + + it('wide', function () { + var result = parse('12 délután', 'h BBBB', baseDate, {locale: locale}) + assert.deepEqual(result, new Date(1986, 3 /* Apr */, 4, 12)) + }) + + it('narrow', function () { + var result = parse('5 este', 'h BBBBB', baseDate, {locale: locale}) + assert.deepEqual(result, new Date(1986, 3 /* Apr */, 4, 17)) + }) + }) + + it('ordinal time', function () { + var dateString = '1. óra, 2. perc, 3. másodperc' + var formatString = "ho 'óra', mo 'perc', so 'másodperc'" + var result = parse(dateString, formatString, baseDate, {locale: locale}) + assert.deepEqual(result, new Date(1986, 3 /* Apr */, 4, 1, 2, 3)) + }) + }) +}) diff --git a/src/locale/index.js b/src/locale/index.js index 0fab5d2422..8dec6a780d 100644 --- a/src/locale/index.js +++ b/src/locale/index.js @@ -9,6 +9,8 @@ module.exports = { es: require('./es/index.js'), fr: require('./fr/index.js'), he: require('./he/index.js'), + hu: require('./hu/index.js'), + lt: require('./lt/index.js'), nb: require('./nb/index.js'), nl: require('./nl/index.js'), ptBR: require('./pt-BR/index.js'), diff --git a/src/locale/index.js.flow b/src/locale/index.js.flow index 7fa54b88db..56abf5ea3e 100644 --- a/src/locale/index.js.flow +++ b/src/locale/index.js.flow @@ -52,12 +52,14 @@ declare module.exports: { frCH: Locale, he: Locale, hr: Locale, + hu: Locale, id: Locale, is: Locale, it: Locale, ja: Locale, ka: Locale, ko: Locale, + lt: Locale, mk: Locale, ms: Locale, nb: Locale, diff --git a/src/locale/lt/_lib/formatDistance/index.js b/src/locale/lt/_lib/formatDistance/index.js new file mode 100644 index 0000000000..c2e1c312a3 --- /dev/null +++ b/src/locale/lt/_lib/formatDistance/index.js @@ -0,0 +1,145 @@ +var formatDistanceLocale = { + lessThanXSeconds: { + one: translateSeconds, + other: translate + }, + + xSeconds: { + one: translateSeconds, + other: translate + }, + + halfAMinute: 'pusė minutės', + + lessThanXMinutes: { + one: translateSingular, + other: translate + }, + + xMinutes: { + one: translateSingular, + other: translate + }, + + aboutXHours: { + one: translateSingular, + other: translate + }, + + xHours: { + one: translateSingular, + other: translate + }, + + xDays: { + one: translateSingular, + other: translate + }, + + aboutXMonths: { + one: translateSingular, + other: translate + }, + + xMonths: { + one: translateSingular, + other: translate + }, + + aboutXYears: { + one: translateSingular, + other: translate + }, + + xYears: { + one: translateSingular, + other: translate + }, + + overXYears: { + one: translateSingular, + other: translate + }, + + almostXYears: { + one: translateSingular, + other: translate + } +} + +var translations = { + 'xseconds_other': 'sekundė_sekundžių_sekundes', + 'xminutes_one': 'minutė_minutės_minutę', + 'xminutes_other': 'minutės_minučių_minutes', + 'xhours_one': 'valanda_valandos_valandą', + 'xhours_other': 'valandos_valandų_valandas', + 'xdays_one': 'diena_dienos_dieną', + 'xdays_other': 'dienos_dienų_dienas', + 'xmonths_one': 'mėnuo_mėnesio_mėnesį', + 'xmonths_other': 'mėnesiai_mėnesių_mėnesius', + 'xyears_one': 'metai_metų_metus', + 'xyears_other': 'metai_metų_metus', + 'about': 'apie', + 'over': 'daugiau nei', + 'almost': 'beveik', + 'lessthan': 'mažiau nei' +} +function translateSeconds (number, addSuffix, key, isFuture) { + if (!addSuffix) { + return 'kelios sekundės' + } else { + return isFuture ? 'kelių sekundžių' : 'kelias sekundes' + } +} +function translateSingular (number, addSuffix, key, isFuture) { + return !addSuffix ? forms(key)[0] : (isFuture ? forms(key)[1] : forms(key)[2]) +} +function special (number) { + return number % 10 === 0 || (number > 10 && number < 20) +} +function forms (key) { + return translations[key].split('_') +} +function translate (number, addSuffix, key, isFuture) { + var result = number + ' ' + if (number === 1) { + return result + translateSingular(number, addSuffix, key[0], isFuture) + } else if (!addSuffix) { + return result + (special(number) ? forms(key)[1] : forms(key)[0]) + } else { + if (isFuture) { + return result + forms(key)[1] + } else { + return result + (special(number) ? forms(key)[1] : forms(key)[2]) + } + } +} + +export default function formatDistance (token, count, options) { + options = options || {} + var adverb = token.match(/about|over|almost|lessthan/i) + var unit = token.replace(adverb, '') + + var result + if (typeof formatDistanceLocale[token] === 'string') { + result = formatDistanceLocale[token] + } else if (count === 1) { + result = formatDistanceLocale[token].one(count, options.addSuffix, unit.toLowerCase() + '_one') + } else { + result = formatDistanceLocale[token].other(count, options.addSuffix, unit.toLowerCase() + '_other') + } + + if (adverb) { + result = translations[adverb[0].toLowerCase()] + ' ' + result + } + + if (options.addSuffix) { + if (options.comparison > 0) { + return 'po ' + result + } else { + return 'prieš ' + result + } + } + + return result +} diff --git a/src/locale/lt/_lib/formatDistance/test.js b/src/locale/lt/_lib/formatDistance/test.js new file mode 100644 index 0000000000..bfba6b8a88 --- /dev/null +++ b/src/locale/lt/_lib/formatDistance/test.js @@ -0,0 +1,219 @@ +// @flow +/* eslint-env mocha */ + +import assert from 'power-assert' +import formatDistance from '.' + +describe('lt locale > formatDistance', function () { + describe('lessThanXSeconds', function () { + context('when the count equals 1', function () { + it('returns a proper string', function () { + assert(formatDistance('lessThanXSeconds', 1) === 'mažiau nei kelios sekundės') + }) + }) + + context('when the count is more than 1', function () { + it('returns a proper string', function () { + assert(formatDistance('lessThanXSeconds', 2) === 'mažiau nei 2 sekundė') + }) + }) + }) + + describe('xSeconds', function () { + context('when the count equals 1', function () { + it('returns a proper string', function () { + assert(formatDistance('xSeconds', 1) === 'kelios sekundės') + }) + }) + + context('when the count is more than 1', function () { + it('returns a proper string', function () { + assert(formatDistance('xSeconds', 2) === '2 sekundė') + }) + }) + }) + + describe('halfAMinute', function () { + it('returns a proper string', function () { + assert(formatDistance('halfAMinute') === 'pusė minutės') + }) + + it('ignores the second argument', function () { + assert(formatDistance('halfAMinute', 123) === 'pusė minutės') + }) + }) + + describe('lessThanXMinutes', function () { + context('when the count equals 1', function () { + it('returns a proper string', function () { + assert(formatDistance('lessThanXMinutes', 1) === 'mažiau nei minutė') + }) + }) + + context('when the count is more than 1', function () { + it('returns a proper string', function () { + assert(formatDistance('lessThanXMinutes', 2) === 'mažiau nei 2 minutės') + }) + }) + }) + + describe('xMinutes', function () { + context('when the count equals 1', function () { + it('returns a proper string', function () { + assert(formatDistance('xMinutes', 1) === 'minutė') + }) + }) + + context('when the count is more than 1', function () { + it('returns a proper string', function () { + assert(formatDistance('xMinutes', 2) === '2 minutės') + }) + }) + }) + + describe('aboutXHours', function () { + context('when the count equals 1', function () { + it('returns a proper string', function () { + assert(formatDistance('aboutXHours', 1) === 'apie valanda') + }) + }) + + context('when the count is more than 1', function () { + it('returns a proper string', function () { + assert(formatDistance('aboutXHours', 2) === 'apie 2 valandos') + }) + }) + }) + + describe('xHours', function () { + context('when the count equals 1', function () { + it('returns a proper string', function () { + assert(formatDistance('xHours', 1) === 'valanda') + }) + }) + + context('when the count is more than 1', function () { + it('returns a proper string', function () { + assert(formatDistance('xHours', 2) === '2 valandos') + }) + }) + }) + + describe('xDays', function () { + context('when the count equals 1', function () { + it('returns a proper string', function () { + assert(formatDistance('xDays', 1) === 'diena') + }) + }) + + context('when the count is more than 1', function () { + it('returns a proper string', function () { + assert(formatDistance('xDays', 2) === '2 dienos') + }) + }) + }) + + describe('aboutXMonths', function () { + context('when the count equals 1', function () { + it('returns a proper string', function () { + assert(formatDistance('aboutXMonths', 1) === 'apie mėnuo') + }) + }) + + context('when the count is more than 1', function () { + it('returns a proper string', function () { + assert(formatDistance('aboutXMonths', 2) === 'apie 2 mėnesiai') + }) + }) + }) + + describe('xMonths', function () { + context('when the count equals 1', function () { + it('returns a proper string', function () { + assert(formatDistance('xMonths', 1) === 'mėnuo') + }) + }) + + context('when the count is more than 1', function () { + it('returns a proper string', function () { + assert(formatDistance('xMonths', 2) === '2 mėnesiai') + }) + }) + }) + + describe('aboutXYears', function () { + context('when the count equals 1', function () { + it('returns a proper string', function () { + assert(formatDistance('aboutXYears', 1) === 'apie metai') + }) + }) + + context('when the count is more than 1', function () { + it('returns a proper string', function () { + assert(formatDistance('aboutXYears', 2) === 'apie 2 metai') + }) + }) + }) + + describe('xYears', function () { + context('when the count equals 1', function () { + it('returns a proper string', function () { + assert(formatDistance('xYears', 1) === 'metai') + }) + }) + + context('when the count is more than 1', function () { + it('returns a proper string', function () { + assert(formatDistance('xYears', 2) === '2 metai') + }) + }) + }) + + describe('overXYears', function () { + context('when the count equals 1', function () { + it('returns a proper string', function () { + assert(formatDistance('overXYears', 1) === 'daugiau nei metai') + }) + }) + + context('when the count is more than 1', function () { + it('returns a proper string', function () { + assert(formatDistance('overXYears', 2) === 'daugiau nei 2 metai') + }) + }) + }) + + describe('almostXYears', function () { + context('when the count equals 1', function () { + it('returns a proper string', function () { + assert(formatDistance('almostXYears', 1) === 'beveik metai') + }) + }) + + context('when the count is more than 1', function () { + it('returns a proper string', function () { + assert(formatDistance('almostXYears', 2) === 'beveik 2 metai') + }) + }) + }) + + context('with a past suffix', function () { + it('adds `prieš` to a string', function () { + var result = formatDistance('aboutXYears', 1, { + addSuffix: true, + comparison: -1 + }) + assert(result === 'prieš apie metus') + }) + }) + + context('with a future suffix', function () { + it('adds `po` to a string', function () { + var result = formatDistance('halfAMinute', null, { + addSuffix: true, + comparison: 1 + }) + assert(result === 'po pusė minutės') + }) + }) +}) diff --git a/src/locale/lt/_lib/formatLong/index.js b/src/locale/lt/_lib/formatLong/index.js new file mode 100644 index 0000000000..4a07afcf9e --- /dev/null +++ b/src/locale/lt/_lib/formatLong/index.js @@ -0,0 +1,41 @@ +import buildFormatLongFn from '../../../_lib/buildFormatLongFn/index.js' + +var dateFormats = { + full: "y 'm'. MMMM d 'd'., EEEE", + long: "y 'm'. MMMM d 'd'.", + medium: 'y-MM-dd', + short: 'y-MM-dd' +} + +var timeFormats = { + full: 'HH:mm:ss zzzz', + long: 'HH:mm:ss z', + medium: 'HH:mm:ss', + short: 'HH:mm' +} + +var dateTimeFormats = { + full: '{{date}} {{time}}', + long: '{{date}} {{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/lt/_lib/formatRelative/index.js b/src/locale/lt/_lib/formatRelative/index.js new file mode 100644 index 0000000000..f20b92276d --- /dev/null +++ b/src/locale/lt/_lib/formatRelative/index.js @@ -0,0 +1,12 @@ +var formatRelativeLocale = { + lastWeek: "'Praėjusį' eeee p", + yesterday: "'Vakar' p", + today: "'Šiandien' p", + tomorrow: "'Rytoj' p", + nextWeek: 'eeee p', + other: 'P' +} + +export default function formatRelative (token, date, baseDate, options) { + return formatRelativeLocale[token] +} diff --git a/src/locale/lt/_lib/localize/index.js b/src/locale/lt/_lib/localize/index.js new file mode 100644 index 0000000000..175be74202 --- /dev/null +++ b/src/locale/lt/_lib/localize/index.js @@ -0,0 +1,157 @@ +import buildLocalizeFn from '../../../_lib/buildLocalizeFn/index.js' + +var eraValues = { + narrow: ['pr. Kr.', 'po Kr.'], + abbreviated: ['pr. Kr.', 'po Kr.'], + wide: ['prieš Kristų', 'po Kristaus'] +} + +var quarterValues = { + narrow: ['1', '2', '3', '4'], + abbreviated: ['I ketv.', 'II ketv.', 'III ketv.', 'IV ketv.'], + wide: ['I ketvirtis', 'II ketvirtis', 'III ketvirtis', 'IV ketvirtis'] +} + +var formattingQuarterValues = { + narrow: ['1', '2', '3', '4'], + abbreviated: ['I k.', 'II k.', 'III k.', 'IV k.'], + wide: ['I ketvirtis', 'II ketvirtis', 'III ketvirtis', 'IV ketvirtis'] +} + +var monthValues = { + narrow: ['S', 'V', 'K', 'B', 'G', 'B', 'L', 'R', 'R', 'S', 'L', 'G'], + abbreviated: ['saus.', 'vas.', 'kov.', 'bal.', 'geg.', 'birž.', 'liep.', 'rugp.', 'rugs.', 'spal.', 'lapkr.', 'gruod.'], + wide: ['sausis', 'vasaris', 'kovas', 'balandis', 'gegužė', 'birželis', 'liepa', 'rugpjūtis', 'rugsėjis', 'spalis', 'lapkritis', 'gruodis'] +} + +var formattingMonthValues = { + narrow: ['S', 'V', 'K', 'B', 'G', 'B', 'L', 'R', 'R', 'S', 'L', 'G'], + abbreviated: ['saus.', 'vas.', 'kov.', 'bal.', 'geg.', 'birž.', 'liep.', 'rugp.', 'rugs.', 'spal.', 'lapkr.', 'gruod.'], + wide: ['sausio', 'vasario', 'kovo', 'balandžio', 'gegužės', 'birželio', 'liepos', 'rugpjūčio', 'rugsėjo', 'spalio', 'lapkričio', 'gruodžio'] +} + +var dayValues = { + narrow: ['S', 'P', 'A', 'T', 'K', 'P', 'Š'], + short: ['Sk', 'Pr', 'An', 'Tr', 'Kt', 'Pn', 'Št'], + abbreviated: ['sk', 'pr', 'an', 'tr', 'kt', 'pn', 'št'], + wide: ['sekmadienis', 'pirmadienis', 'antradienis', 'trečiadienis', 'ketvirtadienis', 'penktadienis', 'šeštadienis'] +} + +var formattingDayValues = { + narrow: ['S', 'P', 'A', 'T', 'K', 'P', 'Š'], + short: ['Sk', 'Pr', 'An', 'Tr', 'Kt', 'Pn', 'Št'], + abbreviated: ['sk', 'pr', 'an', 'tr', 'kt', 'pn', 'št'], + wide: ['sekmadienį', 'pirmadienį', 'antradienį', 'trečiadienį', 'ketvirtadienį', 'penktadienį', 'šeštadienį'] +} + +var dayPeriodValues = { + narrow: { + am: 'pr. p.', + pm: 'pop.', + midnight: 'vidurnaktis', + noon: 'vidurdienis', + morning: 'rytas', + afternoon: 'diena', + evening: 'vakaras', + night: 'naktis' + }, + abbreviated: { + am: 'priešpiet', + pm: 'popiet', + midnight: 'vidurnaktis', + noon: 'vidurdienis', + morning: 'rytas', + afternoon: 'diena', + evening: 'vakaras', + night: 'naktis' + }, + wide: { + am: 'priešpiet', + pm: 'popiet', + midnight: 'vidurnaktis', + noon: 'vidurdienis', + morning: 'rytas', + afternoon: 'diena', + evening: 'vakaras', + night: 'naktis' + } +} +var formattingDayPeriodValues = { + narrow: { + am: 'pr. p.', + pm: 'pop.', + midnight: 'vidurnaktis', + noon: 'perpiet', + morning: 'rytas', + afternoon: 'popietė', + evening: 'vakaras', + night: 'naktis' + }, + abbreviated: { + am: 'priešpiet', + pm: 'popiet', + midnight: 'vidurnaktis', + noon: 'perpiet', + morning: 'rytas', + afternoon: 'popietė', + evening: 'vakaras', + night: 'naktis' + }, + wide: { + am: 'priešpiet', + pm: 'popiet', + midnight: 'vidurnaktis', + noon: 'perpiet', + morning: 'rytas', + afternoon: 'popietė', + evening: 'vakaras', + night: 'naktis' + } +} + +function ordinalNumber (dirtyNumber, dirtyOptions) { + var number = Number(dirtyNumber) + return number + '-oji' +} + +var localize = { + ordinalNumber: ordinalNumber, + + era: buildLocalizeFn({ + values: eraValues, + defaultWidth: 'wide' + }), + + quarter: buildLocalizeFn({ + values: quarterValues, + defaultWidth: 'wide', + formattingValues: formattingQuarterValues, + defaulFormattingWidth: 'wide', + argumentCallback: function (quarter) { + return Number(quarter) - 1 + } + }), + + month: buildLocalizeFn({ + values: monthValues, + defaultWidth: 'wide', + formattingValues: formattingMonthValues, + defaulFormattingWidth: 'wide' + }), + + day: buildLocalizeFn({ + values: dayValues, + defaultWidth: 'wide', + formattingValues: formattingDayValues, + defaulFormattingWidth: 'wide' + }), + + dayPeriod: buildLocalizeFn({ + values: dayPeriodValues, + defaultWidth: 'wide', + formattingValues: formattingDayPeriodValues, + defaulFormattingWidth: 'wide' + }) +} + +export default localize diff --git a/src/locale/lt/_lib/match/index.js b/src/locale/lt/_lib/match/index.js new file mode 100644 index 0000000000..d636764682 --- /dev/null +++ b/src/locale/lt/_lib/match/index.js @@ -0,0 +1,125 @@ +import buildMatchPatternFn from '../../../_lib/buildMatchPatternFn/index.js' +import buildMatchFn from '../../../_lib/buildMatchFn/index.js' + +var matchOrdinalNumberPattern = /^(\d+)(-oji)?/i +var parseOrdinalNumberPattern = /\d+/i + +var matchEraPatterns = { + narrow: /^p(r|o)\.?\s?(kr\.?|me)/i, + abbreviated: /^(pr\.\s?(kr\.|m\.\s?e\.)|po\s?kr\.|mūsų eroje)/i, + wide: /^(prieš Kristų|prieš mūsų erą|po Kristaus|mūsų eroje)/i +} +var parseEraPatterns = { + wide: [/prieš/i, /(po|mūsų)/i], + any: [/^pr/i, /^(po|m)/i] +} + +var matchQuarterPatterns = { + narrow: /^([1234])/i, + abbreviated: /^(I|II|III|IV)\s?ketv?\.?/i, + wide: /^(I|II|III|IV)\s?ketvirtis/i +} +var parseQuarterPatterns = { + narrow: [/1/i, /2/i, /3/i, /4/i], + any: [/I$/i, /II$/i, /III/i, /IV/i] + +} + +var matchMonthPatterns = { + narrow: /^[svkbglr]/i, + abbreviated: /^(saus\.|vas\.|kov\.|bal\.|geg\.|birž\.|liep\.|rugp\.|rugs\.|spal\.|lapkr\.|gruod\.)/i, + wide: /^(sausi(s|o)|vasari(s|o)|kov(a|o)s|balandž?i(s|o)|gegužės?|birželi(s|o)|liep(a|os)|rugpjū(t|č)i(s|o)|rugsėj(is|o)|spali(s|o)|lapkri(t|č)i(s|o)|gruodž?i(s|o))/i +} +var parseMonthPatterns = { + narrow: [/^s/i, /^v/i, /^k/i, /^b/i, /^g/i, /^b/i, /^l/i, /^r/i, /^r/i, /^s/i, /^l/i, /^g/i], + any: [/^saus/i, /^vas/i, /^kov/i, /^bal/i, /^geg/i, /^birž/i, /^liep/i, /^rugp/i, /^rugs/i, /^spal/i, /^lapkr/i, /^gruod/i] +} + +var matchDayPatterns = { + narrow: /^[spatkš]/i, + short: /^(sk|pr|an|tr|kt|pn|št)/i, + abbreviated: /^(sk|pr|an|tr|kt|pn|št)/i, + wide: /^(sekmadien(is|į)|pirmadien(is|į)|antradien(is|į)|trečiadien(is|į)|ketvirtadien(is|į)|penktadien(is|į)|šeštadien(is|į))/i +} +var parseDayPatterns = { + narrow: [/^s/i, /^p/i, /^a/i, /^t/i, /^k/i, /^p/i, /^š/i], + wide: [/^se/i, /^pi/i, /^an/i, /^tr/i, /^ke/i, /^pe/i, /^še/i], + any: [/^sk/i, /^pr/i, /^an/i, /^tr/i, /^kt/i, /^pn/i, /^št/i] +} + +var matchDayPeriodPatterns = { + narrow: /^(pr.\s?p.|pop.|vidurnaktis|(vidurdienis|perpiet)|rytas|(diena|popietė)|vakaras|naktis)/i, + any: /^(priešpiet|popiet$|vidurnaktis|(vidurdienis|perpiet)|rytas|(diena|popietė)|vakaras|naktis)/i +} +var parseDayPeriodPatterns = { + narrow: { + am: /^pr/i, + pm: /^pop./i, + midnight: /^vidurnaktis/i, + noon: /^(vidurdienis|perp)/i, + morning: /rytas/i, + afternoon: /(die|popietė)/i, + evening: /vakaras/i, + night: /naktis/i + }, + any: { + am: /^pr/i, + pm: /^popiet$/i, + midnight: /^vidurnaktis/i, + noon: /^(vidurdienis|perp)/i, + morning: /rytas/i, + afternoon: /(die|popietė)/i, + evening: /vakaras/i, + night: /naktis/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/lt/index.d.ts b/src/locale/lt/index.d.ts new file mode 100644 index 0000000000..d5695988c0 --- /dev/null +++ b/src/locale/lt/index.d.ts @@ -0,0 +1,4 @@ +// This file is generated automatically by `scripts/build/typings.js`. Please, don't change it. + +import {lt} from 'date-fns/locale' +export = lt diff --git a/src/locale/lt/index.js b/src/locale/lt/index.js new file mode 100644 index 0000000000..016dc71639 --- /dev/null +++ b/src/locale/lt/index.js @@ -0,0 +1,31 @@ +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 Lithuanian locale. + * @language Lithuanian + * + * @iso-639-2 lit + * + * @author Pavlo Shpak [@pshpak]{@link https://github.com/pshpak} + * @author Eduardo Pardo [@eduardopsll]{@link https://github.com/eduardopsll} + */ +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/lt/index.js.flow b/src/locale/lt/index.js.flow new file mode 100644 index 0000000000..1fb5c2c1c0 --- /dev/null +++ b/src/locale/lt/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/lt/test.js b/src/locale/lt/test.js new file mode 100644 index 0000000000..231accc13f --- /dev/null +++ b/src/locale/lt/test.js @@ -0,0 +1,453 @@ +// @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('lt 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 === 'po Kr., po Kristaus, po Kr.') + }) + + describe('year', function () { + it('ordinal regular year', function () { + var result = format(date, "yo 'metai'", {locale: locale}) + assert(result === '1986-oji metai') + }) + + it('ordinal local week-numbering year', function () { + var result = format(date, "Yo 'week-numbering metai'", {locale: locale}) + assert(result === '1986-oji week-numbering metai') + }) + }) + + describe('quarter', function () { + it('formatting quarter', function () { + var result = format(date, "Qo 'ketvirtis', QQQ, QQQQ, QQQQQ", {locale: locale}) + assert(result === '2-oji ketvirtis, II k., II ketvirtis, 2') + }) + + it('stand-alone quarter', function () { + var result = format(date, "qo 'ketvirtis', qqq, qqqq, qqqqq", {locale: locale}) + assert(result === '2-oji ketvirtis, II ketv., II ketvirtis, 2') + }) + }) + + describe('month', function () { + it('formatting month', function () { + var result = format(date, 'do MMMM', {locale: locale}) + assert(result === '5-oji balandžio') + }) + + it('stand-alone month', function () { + var result = format(date, "Lo 'mėnuo', LLL, LLLL, LLLLL", {locale: locale}) + assert(result === '4-oji mėnuo, bal., balandis, B') + }) + }) + + describe('week', function () { + it('ordinal local week of year', function () { + var date = new Date(1986, 3 /* Apr */, 6) + var result = format(date, "wo 'savaite'", {locale: locale}) + assert(result === '14-oji savaite') + }) + + it('ordinal ISO week of year', function () { + var date = new Date(1986, 3 /* Apr */, 6) + var result = format(date, "Io 'ISO week'", {locale: locale}) + assert(result === '14-oji ISO week') + }) + }) + + describe('day', function () { + it('ordinal date', function () { + var result = format(date, "'Šiandien yra' do", {locale: locale}) + assert(result === 'Šiandien yra 5-oji') + }) + + it('ordinal day of year', function () { + var result = format(date, "Do 'metų diena'", {locale: locale}) + assert(result === '95-oji metų diena') + }) + }) + + describe('week day', function () { + it('day of week', function () { + var result = format(date, 'E, EEEE, EEEEE, EEEEEE', {locale: locale}) + assert(result === 'št, šeštadienį, Š, Št') + }) + + it('ordinal day of week', function () { + var result = format(date, "eo 'savaitės diena'", {locale: locale}) + assert(result === '6-oji savaitės diena') + }) + }) + + describe('day period and hour', function () { + it('ordinal hour', function () { + var result = format(date, "ho 'valanda'", {locale: locale}) + assert(result === '10-oji valanda') + }) + + it('AM, PM', function () { + var result = format(date, 'h a, h aaaa, haaaaa', {locale: locale}) + assert(result === '10 priešpiet, 10 priešpiet, 10pr. p.') + }) + + it('AM, PM, noon, midnight', function () { + var result = format(new Date(1986, 3 /* Apr */, 6, 0), 'b, bbbb, bbbbb', {locale: locale}) + assert(result === 'vidurnaktis, vidurnaktis, vidurnaktis') + }) + + it('flexible day periods', function () { + it('works as expected', function () { + var result = format(date, 'h B', {locale: locale}) + assert(result === '10 in the morning') + }) + }) + }) + + it('ordinal minute', function () { + var result = format(date, "mo 'minute'", {locale: locale}) + assert(result === '32-oji minute') + }) + + it('ordinal second', function () { + var result = format(date, "so 'sekundė'", {locale: locale}) + assert(result === '0-oji sekundė') + }) + + describe('long format', function () { + it('short date', function () { + var result = format(date, 'P', {locale: locale}) + assert(result === '1986-04-05') + }) + + it('medium date', function () { + var result = format(date, 'PP', {locale: locale}) + assert(result === '1986-04-05') + }) + + it('long date', function () { + var result = format(date, 'PPP', {locale: locale}) + assert(result === '1986 m. balandžio 5 d.') + }) + + it('full date', function () { + var result = format(date, 'PPPP', {locale: locale}) + assert(result === '1986 m. balandžio 5 d., šeštadienį') + }) + + 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 === '1986-04-05 10:32') + }) + + it('medium date + time', function () { + var result = format(date, 'PPpp', {locale: locale}) + assert(result === '1986-04-05 10:32:00') + }) + + it('long date + time', function () { + var result = format(date, 'PPPp', {locale: locale}) + assert(result === '1986 m. balandžio 5 d. 10:32') + }) + + it('full date + time', function () { + var result = format(date, 'PPPPp', {locale: locale}) + assert(result === '1986 m. balandžio 5 d., šeštadienį 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 === 'pusė minutės') + }) + + 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 === 'po mažiau nei 10 sekundžių') + }) + + 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 === 'prieš apie valandą') + }) + }) + }) + + 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 minučių') + }) + + 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 === 'po 25 sekundes') + }) + + 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 === 'prieš valandą') + }) + }) + }) + + 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 === 'Praėjusį antradienį 00:00') + }) + + it('yesterday', function () { + var result = formatRelative(new Date(1986, 3 /* Apr */, 3, 22, 22), baseDate, {locale: locale}) + assert(result === 'Vakar 22:22') + }) + + it('today', function () { + var result = formatRelative(new Date(1986, 3 /* Apr */, 4, 16, 50), baseDate, {locale: locale}) + assert(result === 'Šiandien 16:50') + }) + + it('tomorrow', function () { + var result = formatRelative(new Date(1986, 3 /* Apr */, 5, 7, 30), baseDate, {locale: locale}) + assert(result === 'Rytoj 07:30') + }) + + it('next week', function () { + var result = formatRelative(new Date(1986, 3 /* Apr */, 6, 12, 0), baseDate, {locale: locale}) + assert(result === 'sekmadienį 12:00') + }) + + it('after the next week', function () { + var result = formatRelative(new Date(1986, 3 /* Apr */, 11, 16, 50), baseDate, {locale: locale}) + assert(result === '1986-04-11') + }) + }) + + 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 pr Kr.', 'yyyyy G', baseDate, {locale: locale}) + assert.deepEqual(result, new Date(-9999, 0 /* Jan */, 1)) + }) + + it('wide', function () { + var result = parse('2018 po Kristaus', 'yyyy GGGG', baseDate, {locale: locale}) + assert.deepEqual(result, new Date(2018, 0 /* Jan */, 1)) + }) + + it('narrow', function () { + var result = parse('44 prme', 'y GGGGG', baseDate, {locale: locale}) + assert.deepEqual(result, new Date(-43, 0 /* Jan */, 1)) + }) + }) + + it('ordinal year', function () { + var result = parse('2017-oji', 'yo', baseDate, {locale: locale}) + assert.deepEqual(result, new Date(2017, 0 /* Jan */, 1)) + }) + + describe('quarter', function () { + it('ordinal', function () { + var result = parse('1-oji', 'Qo', baseDate, {locale: locale}) + assert.deepEqual(result, new Date(1986, 0 /* Jan */, 1)) + }) + + it('abbreviated', function () { + var result = parse('III ketv.', 'QQQ', baseDate, {locale: locale}) + assert.deepEqual(result, new Date(1986, 6 /* Jul */, 1)) + }) + + it('wide', function () { + var result = parse('IV ketvirtis', '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-oji', 'Mo', baseDate, {locale: locale}) + assert.deepEqual(result, new Date(1986, 5 /* Jun */, 1)) + }) + + it('abbreviated', function () { + var result = parse('lapkr.', 'MMM', baseDate, {locale: locale}) + assert.deepEqual(result, new Date(1986, 10 /* Nov */, 1)) + }) + + it('wide', function () { + var result = parse('vasaris', 'MMMM', baseDate, {locale: locale}) + assert.deepEqual(result, new Date(1986, 1 /* Feb */, 1)) + }) + + it('narrow', function () { + var result = parse('S', 'MMMMM', baseDate, {locale: locale}) + assert.deepEqual(result, new Date(1986, 0 /* Jan */, 1)) + }) + }) + + it('ordinal week of year', function () { + var result = parse('48-oji', 'wo', baseDate, {locale: locale}) + assert.deepEqual(result, new Date(1986, 10 /* Nov */, 24)) + }) + + it('ordinal day of month', function () { + var result = parse('28-oji', 'do', baseDate, {locale: locale}) + assert.deepEqual(result, new Date(1986, 3 /* Apr */, 28)) + }) + + it('ordinal day of year', function () { + var result = parse('200-oji', 'Do', baseDate, {locale: locale}) + assert.deepEqual(result, new Date(1986, 6 /* Jul */, 19)) + }) + + describe('day of week', function () { + it('abbreviated', function () { + var result = parse('pr', 'E', baseDate, {locale: locale}) + assert.deepEqual(result, new Date(1986, 2 /* Mar */, 31)) + }) + + it('wide', function () { + var result = parse('antradienis', 'EEEE', baseDate, {locale: locale}) + assert.deepEqual(result, new Date(1986, 3 /* Apr */, 1)) + }) + + it('narrow', function () { + var result = parse('T', 'EEEEE', baseDate, {locale: locale}) + assert.deepEqual(result, new Date(1986, 3 /* Apr */, 2)) + }) + + it('short', function () { + var result = parse('Kt', 'EEEEEE', baseDate, {locale: locale}) + assert.deepEqual(result, new Date(1986, 3 /* Apr */, 3)) + }) + }) + + it('ordinal local day of week', function () { + var result = parse('2-oji savaitės diena', "eo 'savaitės diena'", baseDate, {locale: locale}) + assert.deepEqual(result, new Date(1986, 3 /* Apr */, 1)) + }) + + describe('AM, PM', function () { + it('abbreviated', function () { + var result = parse('5 priešpiet', 'h a', baseDate, {locale: locale}) + assert.deepEqual(result, new Date(1986, 3 /* Apr */, 4, 5)) + }) + + it('wide', function () { + var result = parse('5 popiet', 'h aaaa', baseDate, {locale: locale}) + assert.deepEqual(result, new Date(1986, 3 /* Apr */, 4, 17)) + }) + + it('narrow', function () { + var result = parse('11 pr. p.', '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('vidurdienis', 'b', baseDate, {locale: locale}) + assert.deepEqual(result, new Date(1986, 3 /* Apr */, 4, 12)) + }) + + it('wide', function () { + var result = parse('vidurnaktis', 'bbbb', baseDate, {locale: locale}) + assert.deepEqual(result, new Date(1986, 3 /* Apr */, 4, 0)) + }) + + it('narrow', function () { + var result = parse('vidurnaktis', '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('2 rytas', 'h B', baseDate, {locale: locale}) + assert.deepEqual(result, new Date(1986, 3 /* Apr */, 4, 2)) + }) + + it('wide', function () { + var result = parse('12 popietė', 'h BBBB', baseDate, {locale: locale}) + assert.deepEqual(result, new Date(1986, 3 /* Apr */, 4, 12)) + }) + + it('narrow', function () { + var result = parse('5 vakaras', 'h BBBBB', baseDate, {locale: locale}) + assert.deepEqual(result, new Date(1986, 3 /* Apr */, 4, 17)) + }) + + it('narrow', function () { + var result = parse('5 pop.', 'h BBBBB', baseDate, {locale: locale}) + assert.deepEqual(result, new Date(1986, 3 /* Apr */, 4, 17)) + }) + }) + + it('ordinal time', function () { + var dateString = '1-oji valanda, 2-oji minutė, 3-oji kelios sekundės' + var formatString = "ho 'valanda', mo 'minutė', so 'kelios sekundės'" + 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 a5763240a3..2cf6db60ea 100644 --- a/typings.d.ts +++ b/typings.d.ts @@ -16611,6 +16611,9 @@ declare module 'date-fns/locale' { const hr: Locale namespace hr {} + const hu: Locale + namespace hu {} + const id: Locale namespace id {} @@ -16629,6 +16632,9 @@ declare module 'date-fns/locale' { const ko: Locale namespace ko {} + const lt: Locale + namespace lt {} + const mk: Locale namespace mk {} @@ -16792,6 +16798,11 @@ declare module 'date-fns/locale/hr' { export = hr } +declare module 'date-fns/locale/hu' { + import {hu} from 'date-fns/locale' + export = hu +} + declare module 'date-fns/locale/id' { import {id} from 'date-fns/locale' export = id @@ -16822,6 +16833,11 @@ declare module 'date-fns/locale/ko' { export = ko } +declare module 'date-fns/locale/lt' { + import {lt} from 'date-fns/locale' + export = lt +} + declare module 'date-fns/locale/mk' { import {mk} from 'date-fns/locale' export = mk @@ -17022,6 +17038,11 @@ declare module 'date-fns/locale/hr/index' { export = hr } +declare module 'date-fns/locale/hu/index' { + import {hu} from 'date-fns/locale' + export = hu +} + declare module 'date-fns/locale/id/index' { import {id} from 'date-fns/locale' export = id @@ -17052,6 +17073,11 @@ declare module 'date-fns/locale/ko/index' { export = ko } +declare module 'date-fns/locale/lt/index' { + import {lt} from 'date-fns/locale' + export = lt +} + declare module 'date-fns/locale/mk/index' { import {mk} from 'date-fns/locale' export = mk @@ -17252,6 +17278,11 @@ declare module 'date-fns/locale/hr/index.js' { export = hr } +declare module 'date-fns/locale/hu/index.js' { + import {hu} from 'date-fns/locale' + export = hu +} + declare module 'date-fns/locale/id/index.js' { import {id} from 'date-fns/locale' export = id @@ -17282,6 +17313,11 @@ declare module 'date-fns/locale/ko/index.js' { export = ko } +declare module 'date-fns/locale/lt/index.js' { + import {lt} from 'date-fns/locale' + export = lt +} + declare module 'date-fns/locale/mk/index.js' { import {mk} from 'date-fns/locale' export = mk @@ -17443,6 +17479,9 @@ declare module 'date-fns/esm/locale' { const hr: Locale namespace hr {} + const hu: Locale + namespace hu {} + const id: Locale namespace id {} @@ -17461,6 +17500,9 @@ declare module 'date-fns/esm/locale' { const ko: Locale namespace ko {} + const lt: Locale + namespace lt {} + const mk: Locale namespace mk {} @@ -17624,6 +17666,11 @@ declare module 'date-fns/esm/locale/hr' { export default hr } +declare module 'date-fns/esm/locale/hu' { + import {hu} from 'date-fns/esm/locale' + export default hu +} + declare module 'date-fns/esm/locale/id' { import {id} from 'date-fns/esm/locale' export default id @@ -17654,6 +17701,11 @@ declare module 'date-fns/esm/locale/ko' { export default ko } +declare module 'date-fns/esm/locale/lt' { + import {lt} from 'date-fns/esm/locale' + export default lt +} + declare module 'date-fns/esm/locale/mk' { import {mk} from 'date-fns/esm/locale' export default mk @@ -17854,6 +17906,11 @@ declare module 'date-fns/esm/locale/hr/index' { export default hr } +declare module 'date-fns/esm/locale/hu/index' { + import {hu} from 'date-fns/esm/locale' + export default hu +} + declare module 'date-fns/esm/locale/id/index' { import {id} from 'date-fns/esm/locale' export default id @@ -17884,6 +17941,11 @@ declare module 'date-fns/esm/locale/ko/index' { export default ko } +declare module 'date-fns/esm/locale/lt/index' { + import {lt} from 'date-fns/esm/locale' + export default lt +} + declare module 'date-fns/esm/locale/mk/index' { import {mk} from 'date-fns/esm/locale' export default mk @@ -18084,6 +18146,11 @@ declare module 'date-fns/esm/locale/hr/index.js' { export default hr } +declare module 'date-fns/esm/locale/hu/index.js' { + import {hu} from 'date-fns/esm/locale' + export default hu +} + declare module 'date-fns/esm/locale/id/index.js' { import {id} from 'date-fns/esm/locale' export default id @@ -18114,6 +18181,11 @@ declare module 'date-fns/esm/locale/ko/index.js' { export default ko } +declare module 'date-fns/esm/locale/lt/index.js' { + import {lt} from 'date-fns/esm/locale' + export default lt +} + declare module 'date-fns/esm/locale/mk/index.js' { import {mk} from 'date-fns/esm/locale' export default mk