diff --git a/.gitignore b/.gitignore index 60607e380b..cecd757f0a 100644 --- a/.gitignore +++ b/.gitignore @@ -7,3 +7,4 @@ dist docs.json .idea .vscode +.DS_Store diff --git a/src/.DS_Store b/src/.DS_Store new file mode 100644 index 0000000000..c9f2bdb791 Binary files /dev/null and b/src/.DS_Store differ diff --git a/src/locale/fa-IR/_lib/formatDistance/index.js b/src/locale/fa-IR/_lib/formatDistance/index.js new file mode 100644 index 0000000000..5206ecf974 --- /dev/null +++ b/src/locale/fa-IR/_lib/formatDistance/index.js @@ -0,0 +1,51 @@ +import utils from '../utils.js' + +var formatDistanceLocale = { + lessThanXSeconds: 'کمتر از {{count}} ثانیه', + + xSeconds: '{{count}} ثانیه', + + halfAMinute: 'نیم دقیقه', + + lessThanXMinutes: 'کمتر از {{count}} دقیقه', + + xMinutes: '{{count}} دقیقه', + + aboutXHours: 'نزدیک به {{count}} ساعت', + + xHours: '{{count}} ساعت', + + xDays: '{{count}} روز', + + aboutXMonths: 'نزدیک به {{count}} ماه', + + xMonths: '{{count}} ماه', + + aboutXYears: 'نزدیک به {{count}} سال', + + xYears: '{{count}} سال', + + overXYears: 'بیش از {{count}} سال', + + almostXYears: 'نزدیک به {{count}} سال' +} + +export default function formatDistance(token, count, options) { + options = options || {} + + var result + result = formatDistanceLocale[token].replace( + '{{count}}', + Number.isInteger(count) ? utils.eng2per(count) : '' + ) + + if (options.addSuffix) { + if (options.comparison > 0) { + return 'در ' + result + } else { + return result + ' پیش' + } + } + + return result +} diff --git a/src/locale/fa-IR/_lib/formatDistance/test.js b/src/locale/fa-IR/_lib/formatDistance/test.js new file mode 100644 index 0000000000..90ba71e219 --- /dev/null +++ b/src/locale/fa-IR/_lib/formatDistance/test.js @@ -0,0 +1,219 @@ +// @flow +/* eslint-env mocha */ + +import assert from 'power-assert' +import formatDistance from '.' + +describe('fa-IR locale > formatDistance', function() { + describe('lessThanXSeconds', function() { + context('when the count equals 1', function() { + it('returns a proper string', function() { + assert(formatDistance('lessThanXSeconds', 1) === 'کمتر از ۱ ثانیه') + }) + }) + + context('when the count is more than 1', function() { + it('returns a proper string', function() { + assert(formatDistance('lessThanXSeconds', 2) === 'کمتر از ۲ ثانیه') + }) + }) + }) + + describe('xSeconds', function() { + context('when the count equals 1', function() { + it('returns a proper string', function() { + assert(formatDistance('xSeconds', 1) === '۱ ثانیه') + }) + }) + + context('when the count is more than 1', function() { + it('returns a proper string', function() { + assert(formatDistance('xSeconds', 2) === '۲ ثانیه') + }) + }) + }) + + describe('halfAMinute', function() { + it('returns a proper string', function() { + assert(formatDistance('halfAMinute') === 'نیم دقیقه') + }) + + it('ignores the second argument', function() { + assert(formatDistance('halfAMinute', 123) === 'نیم دقیقه') + }) + }) + + describe('lessThanXMinutes', function() { + context('when the count equals 1', function() { + it('returns a proper string', function() { + assert(formatDistance('lessThanXMinutes', 1) === 'کمتر از ۱ دقیقه') + }) + }) + + context('when the count is more than 1', function() { + it('returns a proper string', function() { + assert(formatDistance('lessThanXMinutes', 2) === 'کمتر از ۲ دقیقه') + }) + }) + }) + + describe('xMinutes', function() { + context('when the count equals 1', function() { + it('returns a proper string', function() { + assert(formatDistance('xMinutes', 1) === '۱ دقیقه') + }) + }) + + context('when the count is more than 1', function() { + it('returns a proper string', function() { + assert(formatDistance('xMinutes', 2) === '۲ دقیقه') + }) + }) + }) + + describe('aboutXHours', function() { + context('when the count equals 1', function() { + it('returns a proper string', function() { + assert(formatDistance('aboutXHours', 1) === 'نزدیک به ۱ ساعت') + }) + }) + + context('when the count is more than 1', function() { + it('returns a proper string', function() { + assert(formatDistance('aboutXHours', 2) === 'نزدیک به ۲ ساعت') + }) + }) + }) + + describe('xHours', function() { + context('when the count equals 1', function() { + it('returns a proper string', function() { + assert(formatDistance('xHours', 1) === '۱ ساعت') + }) + }) + + context('when the count is more than 1', function() { + it('returns a proper string', function() { + assert(formatDistance('xHours', 2) === '۲ ساعت') + }) + }) + }) + + describe('xDays', function() { + context('when the count equals 1', function() { + it('returns a proper string', function() { + assert(formatDistance('xDays', 1) === '۱ روز') + }) + }) + + context('when the count is more than 1', function() { + it('returns a proper string', function() { + assert(formatDistance('xDays', 2) === '۲ روز') + }) + }) + }) + + describe('aboutXMonths', function() { + context('when the count equals 1', function() { + it('returns a proper string', function() { + assert(formatDistance('aboutXMonths', 1) === 'نزدیک به ۱ ماه') + }) + }) + + context('when the count is more than 1', function() { + it('returns a proper string', function() { + assert(formatDistance('aboutXMonths', 2) === 'نزدیک به ۲ ماه') + }) + }) + }) + + describe('xMonths', function() { + context('when the count equals 1', function() { + it('returns a proper string', function() { + assert(formatDistance('xMonths', 1) === '۱ ماه') + }) + }) + + context('when the count is more than 1', function() { + it('returns a proper string', function() { + assert(formatDistance('xMonths', 2) === '۲ ماه') + }) + }) + }) + + describe('aboutXYears', function() { + context('when the count equals 1', function() { + it('returns a proper string', function() { + assert(formatDistance('aboutXYears', 1) === 'نزدیک به ۱ سال') + }) + }) + + context('when the count is more than 1', function() { + it('returns a proper string', function() { + assert(formatDistance('aboutXYears', 2) === 'نزدیک به ۲ سال') + }) + }) + }) + + describe('xYears', function() { + context('when the count equals 1', function() { + it('returns a proper string', function() { + assert(formatDistance('xYears', 1) === '۱ سال') + }) + }) + + context('when the count is more than 1', function() { + it('returns a proper string', function() { + assert(formatDistance('xYears', 2) === '۲ سال') + }) + }) + }) + + describe('overXYears', function() { + context('when the count equals 1', function() { + it('returns a proper string', function() { + assert(formatDistance('overXYears', 1) === 'بیش از ۱ سال') + }) + }) + + context('when the count is more than 1', function() { + it('returns a proper string', function() { + assert(formatDistance('overXYears', 2) === 'بیش از ۲ سال') + }) + }) + }) + + describe('almostXYears', function() { + context('when the count equals 1', function() { + it('returns a proper string', function() { + assert(formatDistance('almostXYears', 1) === 'نزدیک به ۱ سال') + }) + }) + + context('when the count is more than 1', function() { + it('returns a proper string', function() { + assert(formatDistance('almostXYears', 2) === 'نزدیک به ۲ سال') + }) + }) + }) + + context('with a past suffix', function() { + it('adds `ago` to a string', function() { + var result = formatDistance('aboutXYears', 1, { + addSuffix: true, + comparison: -1 + }) + assert(result === 'نزدیک به ۱ سال پیش') + }) + }) + + context('with a future suffix', function() { + it('adds `in` to a string', function() { + var result = formatDistance('halfAMinute', null, { + addSuffix: true, + comparison: 1 + }) + assert(result === 'در نیم دقیقه') + }) + }) +}) diff --git a/src/locale/fa-IR/_lib/formatLong/index.js b/src/locale/fa-IR/_lib/formatLong/index.js new file mode 100644 index 0000000000..799a51000d --- /dev/null +++ b/src/locale/fa-IR/_lib/formatLong/index.js @@ -0,0 +1,41 @@ +import buildFormatLongFn from '../../../_lib/buildFormatLongFn/index.js' + +var dateFormats = { + full: 'EEEE, MMMM do, y', + long: 'MMMM do, y', + medium: 'MMM d, y', + short: 'MM/dd/yyyy' +} + +var timeFormats = { + full: 'h:mm:ss a zzzz', + long: 'h:mm:ss a z', + medium: 'h:mm:ss a', + short: 'h:mm a' +} + +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/fa-IR/_lib/formatRelative/index.js b/src/locale/fa-IR/_lib/formatRelative/index.js new file mode 100644 index 0000000000..f9b81789b6 --- /dev/null +++ b/src/locale/fa-IR/_lib/formatRelative/index.js @@ -0,0 +1,12 @@ +var formatRelativeLocale = { + lastWeek: "eeee 'گذشته،' 'ساعت' p", + yesterday: "'دیروز، ساعت' p", + today: "'امروز، ساعت' p", + tomorrow: "'فردا، ساعت' p", + nextWeek: "eeee'، ساعت' p", + other: 'P' +} + +export default function formatRelative(token, date, baseDate, options) { + return formatRelativeLocale[token] +} diff --git a/src/locale/fa-IR/_lib/localize/index.js b/src/locale/fa-IR/_lib/localize/index.js new file mode 100644 index 0000000000..412ffbe33c --- /dev/null +++ b/src/locale/fa-IR/_lib/localize/index.js @@ -0,0 +1,164 @@ +import buildLocalizeFn from '../../../_lib/buildLocalizeFn/index.js' +import utils from '../utils.js' +var eraValues = { + narrow: ['B', 'A'], + abbreviated: ['BC', 'AD'], + wide: ['پیش از مسیح', 'پس از مسیح'] +} + +var quarterValues = { + narrow: ['۱', '۲', '۳', '۴'], + abbreviated: ['چهارک ۱', 'چهارک ۲', 'چهارک ۳', 'چهارک ۴'], + wide: ['یک چهارم نخست', 'یک چهارم دوم', 'یک چهارم سوم', 'یک چهارم نهایی'] +} + + +var monthValues = { + narrow: ['J', 'F', 'M', 'A', 'M', 'J', 'J', 'A', 'S', 'O', 'N', 'D'], + abbreviated: [ + 'ژان', + 'فور', + 'مار', + 'آور', + 'مه', + 'ژو‌ئ', + 'ژوئ', + 'اوت', + 'سپت', + 'اکت', + 'نوا', + 'دسا' + ], + wide: [ + 'ژانویه', + 'فوریه', + 'مارس', + 'آوریل', + 'مه', + 'ژو‌ئن', + 'ژوئیه', + 'اوت', + 'سپتامبر', + 'اکتبر', + 'نوامبر', + 'دسامبر' + ] +} + +var dayValues = { + narrow: ['ی', 'د', 'س', 'چ', 'پ', 'آ', 'ش'], + short: ['۱ش', '۲ش', '۳ش', '۴ش', '۵ش', 'آ', 'ش'], + abbreviated: ['یک ش', 'دو ش', 'سه ش', 'چهار ش', 'پنج ش', 'آدینه', 'شنبه'], + wide: ['یکشنبه', 'دوشنبه', 'سه شنبه', 'چهارشنبه', 'پنجشنبه', 'آدینه', 'شنبه'] +} + +var dayPeriodValues = { + narrow: { + am: 'ق', + pm: 'ب', + midnight: 'نیمه شب', + noon: 'نیم روز', + morning: 'بامداد', + afternoon: 'عصر', + evening: 'غروب', + night: 'شب' + }, + abbreviated: { + am: 'ق.ظ.', + pm: 'ب.ظ.', + midnight: 'نیمه شب', + noon: 'نیم روز', + morning: 'بامداد', + afternoon: 'عصر', + evening: 'غروب', + night: 'شب' + }, + wide: { + am: 'ق.ظ.', + pm: 'ب.ظ.', + midnight: 'نیمه شب', + noon: 'نیم روز', + morning: 'بامداد', + afternoon: 'عصر', + evening: 'غروب', + night: 'شب' + } +} +var formattingDayPeriodValues = { + narrow: { + am: 'ق.ظ.', + pm: 'ب.ظ.', + midnight: 'نیمه شب', + noon: 'نیم روز', + morning: 'بامداد', + afternoon: 'عصر', + evening: 'غروب', + night: 'شب' + }, + abbreviated: { + am: 'ق.ظ.', + pm: 'ب.ظ.', + midnight: 'نیمه شب', + noon: 'نیم روز', + morning: 'بامداد', + afternoon: 'عصر', + evening: 'غروب', + night: 'شب' + }, + wide: { + am: 'ق.ظ.', + pm: 'ب.ظ.', + midnight: 'نیمه شب', + noon: 'نیم روز', + morning: 'بامداد', + afternoon: 'عصر', + evening: 'غروب', + night: 'شب' + } +} + +function ordinalNumber(dirtyNumber, dirtyOptions) { + var number = Number(dirtyNumber) + + if (dirtyOptions.unit === 'date') { + return utils.eng2per(number) + 'م' + } + + return utils.eng2per(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', + formattingValues: formattingDayPeriodValues, + defaulFormattingWidth: 'wide' + }) +} + +export default localize diff --git a/src/locale/fa-IR/_lib/match/index.js b/src/locale/fa-IR/_lib/match/index.js new file mode 100644 index 0000000000..bf3f56425f --- /dev/null +++ b/src/locale/fa-IR/_lib/match/index.js @@ -0,0 +1,137 @@ +import buildMatchPatternFn from '../../../_lib/buildMatchPatternFn/index.js' +import buildMatchFn from '../../../_lib/buildMatchFn/index.js' + +var matchOrdinalNumberPattern = /^(\d+)(th|st|nd|rd)?/i +var parseOrdinalNumberPattern = /\d+/i + +var matchEraPatterns = { + narrow: /^(b|a)/i, + abbreviated: /^(b\.?\s?c\.?|b\.?\s?c\.?\s?e\.?|a\.?\s?d\.?|c\.?\s?e\.?)/i, + wide: /^(before christ|before common era|anno domini|common era)/i +} +var parseEraPatterns = { + any: [/^b/i, /^(a|c)/i] +} + +var matchQuarterPatterns = { + narrow: /^[1234]/i, + abbreviated: /^q[1234]/i, + wide: /^[1234](th|st|nd|rd)? quarter/i +} +var parseQuarterPatterns = { + any: [/1/i, /2/i, /3/i, /4/i] +} + +var matchMonthPatterns = { + narrow: /^[jfmasond]/i, + abbreviated: /^(jan|feb|mar|apr|may|jun|jul|aug|sep|oct|nov|dec)/i, + wide: /^(january|february|march|april|may|june|july|august|september|october|november|december)/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, + /^may/i, + /^jun/i, + /^jul/i, + /^au/i, + /^s/i, + /^o/i, + /^n/i, + /^d/i + ] +} + +var matchDayPatterns = { + narrow: /^[smtwf]/i, + short: /^(su|mo|tu|we|th|fr|sa)/i, + abbreviated: /^(sun|mon|tue|wed|thu|fri|sat)/i, + wide: /^(sunday|monday|tuesday|wednesday|thursday|friday|saturday)/i +} +var parseDayPatterns = { + narrow: [/^s/i, /^m/i, /^t/i, /^w/i, /^t/i, /^f/i, /^s/i], + any: [/^su/i, /^m/i, /^tu/i, /^w/i, /^th/i, /^f/i, /^sa/i] +} + +var matchDayPeriodPatterns = { + narrow: /^(a|p|mi|n|(in the|at) (morning|afternoon|evening|night))/i, + any: /^([ap]\.?\s?m\.?|midnight|noon|(in the|at) (morning|afternoon|evening|night))/i +} +var parseDayPeriodPatterns = { + any: { + am: /^a/i, + pm: /^p/i, + midnight: /^mi/i, + noon: /^no/i, + morning: /morning/i, + afternoon: /afternoon/i, + evening: /evening/i, + night: /night/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/fa-IR/_lib/utils.js b/src/locale/fa-IR/_lib/utils.js new file mode 100644 index 0000000000..59a14d0797 --- /dev/null +++ b/src/locale/fa-IR/_lib/utils.js @@ -0,0 +1,27 @@ +var utils = { + /** + * Converts English numbers to Persian counterparts + * + * @api private + * @method _englishNumber + * @param {String} value + * @return {Object} PersianJs Object + */ + eng2per: value => { + if (!value.toString().length) { + return + } + value = value.toString() + var englishNumbers = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '0'], + persianNumbers = ['۱', '۲', '۳', '۴', '۵', '۶', '۷', '۸', '۹', '۰'] + + for (var i = 0, numbersLen = englishNumbers.length; i < numbersLen; i++) { + value = value.replace( + new RegExp(englishNumbers[i], 'g'), + persianNumbers[i] + ) + } + return value + } +} +export default utils diff --git a/src/locale/fa-IR/index.d.ts b/src/locale/fa-IR/index.d.ts new file mode 100644 index 0000000000..d2318cf564 --- /dev/null +++ b/src/locale/fa-IR/index.d.ts @@ -0,0 +1,4 @@ +// This file is generated automatically by `scripts/build/typings.js`. Please, don't change it. + +import { enUS } from 'date-fns/locale' +export = enUS diff --git a/src/locale/fa-IR/index.js b/src/locale/fa-IR/index.js new file mode 100644 index 0000000000..f272188cd8 --- /dev/null +++ b/src/locale/fa-IR/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 Persian locale (Iran). + * @language Persian + * @iso-639-2 per + * @author Pierre Veissi [@pkhodaveissi]{@link https://github.com/pkhodaveissi} + */ +var locale = { + formatDistance: formatDistance, + formatLong: formatLong, + formatRelative: formatRelative, + localize: localize, + match: match, + options: { + weekStartsOn: 6 /* Saturday */, + firstWeekContainsDate: 1 + } +} + +export default locale diff --git a/src/locale/fa-IR/index.js.flow b/src/locale/fa-IR/index.js.flow new file mode 100644 index 0000000000..1fb5c2c1c0 --- /dev/null +++ b/src/locale/fa-IR/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/fa-IR/test.js b/src/locale/fa-IR/test.js new file mode 100644 index 0000000000..ea5ef317d2 --- /dev/null +++ b/src/locale/fa-IR/test.js @@ -0,0 +1,459 @@ +// @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('fa-IR 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 === "AD, پس از مسیح, A" ) + // }) + + // describe('year', function () { + // it('ordinal regular year', function () { + // var result = format(date, "yo 'سال'", {locale: locale}) + // assert(result === '۱۹۸۶مین سال') + // }) + + // it('ordinal local week-numbering year', function () { + // var result = format(date, "Yo 'هفته سال'", {locale: locale}) + // assert(result === '۱۹۸۶مین هفته سال') + // }) + // }) + + // describe('quarter', function () { + // it('formatting quarter', function () { + // var result = format(date, "Qo 'چهارک', QQQ, QQQQ, QQQQQ", {locale: locale}) + // assert(result === '۲مین چهارک, چهارک ۲, یک چهارم دوم, ۲') + // }) + + // it('stand-alone quarter', function () { + // var result = format(date, "qo 'چهارک', qqq, qqqq, qqqqq", {locale: locale}) + // assert(result === '۲مین چهارک, چهارک ۲, یک چهارم دوم, ۲') + // }) + // }) + + // describe('month', function () { + // it('formatting month', function () { + // var result = format(date, "'روز' do 'از' MMMM", {locale: locale}) + // assert(result === 'روز ۵م از آوریل') + // }) + + // it('stand-alone month', function () { + // var result = format(date, "Lo 'ماه', LLL, LLLL, LLLLL", {locale: locale}) + // assert(result === '۴مین ماه, آور, آوریل, A') + // }) + // }) + + // describe('week', function () { + // it('ordinal local week of year', function () { + // var date = new Date(1986, 3 /* Apr */, 6) + // var result = format(date, "wo 'هفته'", {locale: locale}) + // assert(result === '۱۵مین هفته') + // }) + + // it('ordinal ISO week of year', function () { + // var date = new Date(1986, 3 /* Apr */, 6) + // var result = format(date, "Io 'ISO هفته'", {locale: locale}) + // assert(result === '۱۴مین ISO هفته') + // }) + // }) + + // describe('day', function () { + // it('ordinal date', function () { + // var result = format(date, "'امروز' do است", {locale: locale}) + // assert(result === 'امروز ۵م است') + // }) + + // it('ordinal day of year', function () { + // var result = format(date, "Do 'روز از سال است'", {locale: locale}) + // assert(result === '۹۵مین روز از سال است') + // }) + // }) + + // describe('week day', function () { + // it('day of week', function () { + // var result = format(date, 'E, EEEE, EEEEE, EEEEEE', {locale: locale}) + // assert(result === 'شنبه, شنبه, ش, ش') + // }) + + // it('ordinal day of week', function () { + // var result = format(date, "eo 'روز از هفته'", {locale: locale}) + // assert(result === '۱مین روز از هفته') + // }) + // }) + + // describe('day period and hour', function () { + // it('ordinal hour', function () { + // var result = format(date, "ho 'ساعت'", {locale: locale}) + // assert(result === '۱۰مین ساعت') + // }) + + // it('AM, PM', function () { + // var result = format(date, 'h a, h aaaa, haaaaa', {locale: locale}) + // assert(result === '10 ق.ظ., 10 ق.ظ., 10ق.ظ.') + // }) + + // it('AM, PM, noon, midnight', function () { + // var result = format(new Date(1986, 3 /* Apr */, 6, 0), 'b, bbbb, bbbbb', {locale: locale}) + // assert(result === 'نیمه شب, نیمه شب, نیمه شب') + // }) + + // 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 'دقیقه'", {locale: locale}) + // assert(result === '۳۲مین دقیقه') + // }) + + // it('ordinal second', function () { + // var result = format(date, "so 'ثانیه'", {locale: locale}) + // assert(result === '۰مین ثانیه') + // }) + + // describe('long format', function () { + // it('short date', function () { + // var result = format(date, 'P', {locale: locale}) + // assert(result === '04/05/1986') + // }) + + // it('medium date', function () { + // var result = format(date, 'PP', {locale: locale}) + // assert(result === 'آور 5, 1986') + // }) + + // it('long date', function () { + // var result = format(date, 'PPP', {locale: locale}) + // assert(result === 'آوریل ۵م, 1986') + // }) + + // it('full date', function () { + // var result = format(date, 'PPPP', {locale: locale}) + // assert(result === 'شنبه, آوریل ۵م, 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 === '04/05/1986, 10:32 ق.ظ.') + // }) + + // it('medium date + time', function () { + // var result = format(date, 'PPpp', {locale: locale}) + // assert(result === 'آور 5, 1986, 10:32:00 ق.ظ.') + // }) + + // it('long date + time', function () { + // var result = format(date, 'PPPp', {locale: locale}) + // assert(result === 'آوریل ۵م, 1986 در ساعت 10:32 ق.ظ.') + // }) + + // it('full date + time', function () { + // var result = format(date, 'PPPPp', {locale: locale}) + // assert(result === 'شنبه, آوریل ۵م, 1986 در ساعت 10:32 ق.ظ.') + // }) + // }) + // }) + + // context('with `formatDistance`', function () { + // it('works as expected', function () { + // var result = formatDistance( + // new Date(1986, 3, 4, 10, 32, 25), + // new Date(1986, 3, 4, 10, 32, 0), + // {locale: locale, includeSeconds: true} + // ) + // assert(result === 'نیم دقیقه') + // }) + + // 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 === 'در کمتر از ۱۰ ثانیه') + // }) + + // 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 === 'نزدیک به ۱ ساعت پیش') + // }) + // }) + // }) + + // 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 === '۱۲۰ دقیقه') + // }) + + // 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 === 'در ۲۵ ثانیه') + // }) + + // 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 === '۱ ساعت پیش') + // }) + // }) + // }) + + // 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 === 'سه شنبه گذشته، ساعت 12:00 ق.ظ.') + // }) + + // it('yesterday', function () { + // var result = formatRelative(new Date(1986, 3 /* Apr */, 3, 22, 22), baseDate, {locale: locale}) + // assert(result === 'دیروز، ساعت 10:22 ب.ظ.') + // }) + + // it('today', function () { + // var result = formatRelative(new Date(1986, 3 /* Apr */, 4, 16, 50), baseDate, {locale: locale}) + // assert(result === 'امروز، ساعت 4:50 ب.ظ.') + // }) + + // it('tomorrow', function () { + // var result = formatRelative(new Date(1986, 3 /* Apr */, 5, 7, 30), baseDate, {locale: locale}) + // assert(result === 'فردا، ساعت 7:30 ق.ظ.') + // }) + + // it('next week', function () { + // var result = formatRelative(new Date(1986, 3 /* Apr */, 6, 12, 0), baseDate, {locale: locale}) + // assert(result === 'یکشنبه، ساعت 12:00 ب.ظ.') + // }) + + // it('after the next week', function () { + // var result = formatRelative(new Date(1986, 3 /* Apr */, 11, 16, 50), baseDate, {locale: locale}) + // assert(result === '04/11/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 BC', 'yyyyy G', baseDate, { locale: locale }) + assert.deepEqual(result, new Date(-9999, 0 /* Jan */, 1)) + }) + + it('wide', function() { + var result = parse('2018 Anno Domini', 'yyyy GGGG', baseDate, { + locale: locale + }) + assert.deepEqual(result, new Date(2018, 0 /* Jan */, 1)) + }) + + it('narrow', function() { + var result = parse('44 B', 'y GGGGG', baseDate, { locale: locale }) + assert.deepEqual(result, new Date(-43, 0 /* Jan */, 1)) + }) + }) + + it('ordinal year', function() { + var result = parse('2017th', 'yo', baseDate, { locale: locale }) + assert.deepEqual(result, new Date(2017, 0 /* Jan */, 1)) + }) + + describe('quarter', function() { + it('ordinal', function() { + var result = parse('1st', '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('4st quarter', '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('6th', '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('February', '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('49th', 'wo', baseDate, { locale: locale }) + assert.deepEqual(result, new Date(1986, 10 /* Nov */, 29)) + }) + + it('ordinal day of month', function() { + var result = parse('28th', 'do', baseDate, { locale: locale }) + assert.deepEqual(result, new Date(1986, 3 /* Apr */, 28)) + }) + + it('ordinal day of year', function() { + var result = parse('200th', 'Do', baseDate, { locale: locale }) + assert.deepEqual(result, new Date(1986, 6 /* Jul */, 19)) + }) + + describe('day of week', function() { + it('abbreviated', function() { + var result = parse('Mon', 'E', baseDate, { locale: locale }) + assert.deepEqual(result, new Date(1986, 3 /* Mar */, 7)) + }) + + it('wide', function() { + var result = parse('Tuesday', 'EEEE', baseDate, { locale: locale }) + assert.deepEqual(result, new Date(1986, 3 /* Apr */, 8)) + }) + + it('narrow', function() { + var result = parse('W', 'EEEEE', baseDate, { locale: locale }) + assert.deepEqual(result, new Date(1986, 3 /* Apr */, 9)) + }) + + it('short', function() { + var result = parse('Th', 'EEEEEE', baseDate, { locale: locale }) + assert.deepEqual(result, new Date(1986, 3 /* Apr */, 10)) + }) + }) + + it('ordinal local day of week', function() { + var result = parse( + '2nd day of the week', + "eo 'day of the week'", + baseDate, + { locale: locale } + ) + assert.deepEqual(result, new Date(1986, 3 /* Apr */, 6)) + }) + + 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('noon', 'b', baseDate, { locale: locale }) + assert.deepEqual(result, new Date(1986, 3 /* Apr */, 4, 12)) + }) + + it('wide', function() { + var result = parse('midnight', 'bbbb', baseDate, { locale: locale }) + assert.deepEqual(result, new Date(1986, 3 /* Apr */, 4, 0)) + }) + + it('narrow', function() { + var result = parse('mi', '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 at night', 'h B', baseDate, { locale: locale }) + assert.deepEqual(result, new Date(1986, 3 /* Apr */, 4, 2)) + }) + + it('wide', function() { + var result = parse('12 in the afternoon', 'h BBBB', baseDate, { + locale: locale + }) + assert.deepEqual(result, new Date(1986, 3 /* Apr */, 4, 12)) + }) + + it('narrow', function() { + var result = parse('5 in the evening', 'h BBBBB', baseDate, { + locale: locale + }) + assert.deepEqual(result, new Date(1986, 3 /* Apr */, 4, 17)) + }) + }) + + it('ordinal time', function() { + var dateString = '1st hour, 2nd minute, 3rd second' + var formatString = "ho 'hour', mo 'minute', so 'second'" + 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/gl/_lib/formatRelative/index.js b/src/locale/gl/_lib/formatRelative/index.js index c36329edf7..aca2723a65 100644 --- a/src/locale/gl/_lib/formatRelative/index.js +++ b/src/locale/gl/_lib/formatRelative/index.js @@ -16,8 +16,8 @@ var formatRelativeLocalePlural = { other: 'P' } -export default function formatRelative (token, date, baseDate, options) { - if (date.getHours() !== 1) { +export default function formatRelative(token, date, baseDate, options) { + if (date.getUTCHours() !== 1) { return formatRelativeLocalePlural[token] } return formatRelativeLocale[token]