forked from date-fns/date-fns
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Persian locale (fa-IR) (date-fns#1113)
- Loading branch information
Showing
14 changed files
with
1,280 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
var formatDistanceLocale = { | ||
lessThanXSeconds: { | ||
one: 'کمتر از یک ثانیه', | ||
other: 'کمتر از {{count}} ثانیه' | ||
}, | ||
|
||
xSeconds: { | ||
one: '1 ثانیه', | ||
other: '{{count}} ثانیه' | ||
}, | ||
|
||
halfAMinute: 'نیم دقیقه', | ||
|
||
lessThanXMinutes: { | ||
one: 'کمتر از یک دقیقه', | ||
other: 'کمتر از {{count}} دقیقه' | ||
}, | ||
|
||
xMinutes: { | ||
one: '1 دقیقه', | ||
other: '{{count}} دقیقه' | ||
}, | ||
|
||
aboutXHours: { | ||
one: 'حدود 1 ساعت', | ||
other: 'حدود {{count}} ساعت' | ||
}, | ||
|
||
xHours: { | ||
one: '1 ساعت', | ||
other: '{{count}} ساعت' | ||
}, | ||
|
||
xDays: { | ||
one: '1 روز', | ||
other: '{{count}} روز' | ||
}, | ||
|
||
aboutXMonths: { | ||
one: 'حدود 1 ماه', | ||
other: 'حدود {{count}} ماه' | ||
}, | ||
|
||
xMonths: { | ||
one: '1 ماه', | ||
other: '{{count}} ماه' | ||
}, | ||
|
||
aboutXYears: { | ||
one: 'حدود 1 سال', | ||
other: 'حدود {{count}} سال' | ||
}, | ||
|
||
xYears: { | ||
one: '1 سال', | ||
other: '{{count}} سال' | ||
}, | ||
|
||
overXYears: { | ||
one: 'بیشتر از 1 سال', | ||
other: 'بیشتر از {{count}} سال' | ||
}, | ||
|
||
almostXYears: { | ||
one: 'نزدیک 1 سال', | ||
other: 'نزدیک {{count}} سال' | ||
} | ||
} | ||
|
||
export default function formatDistance(token, count, options) { | ||
options = options || {} | ||
|
||
var result | ||
if (typeof formatDistanceLocale[token] === 'string') { | ||
result = formatDistanceLocale[token] | ||
} else if (count === 1) { | ||
result = formatDistanceLocale[token].one | ||
} else { | ||
result = formatDistanceLocale[token].other.replace('{{count}}', count) | ||
} | ||
|
||
if (options.addSuffix) { | ||
if (options.comparison > 0) { | ||
return 'در ' + result | ||
} else { | ||
return result + ' قبل' | ||
} | ||
} | ||
|
||
return result | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,219 @@ | ||
// @flow | ||
/* eslint-env mocha */ | ||
|
||
import assert from 'power-assert' | ||
import formatDistance from '.' | ||
|
||
describe('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) === 'کمتر از 2 ثانیه') | ||
}) | ||
}) | ||
}) | ||
|
||
describe('xSeconds', function() { | ||
context('when the count equals 1', function() { | ||
it('returns a proper string', function() { | ||
assert(formatDistance('xSeconds', 1) === '1 ثانیه') | ||
}) | ||
}) | ||
|
||
context('when the count is more than 1', function() { | ||
it('returns a proper string', function() { | ||
assert(formatDistance('xSeconds', 2) === '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) === 'کمتر از 2 دقیقه') | ||
}) | ||
}) | ||
}) | ||
|
||
describe('xMinutes', function() { | ||
context('when the count equals 1', function() { | ||
it('returns a proper string', function() { | ||
assert(formatDistance('xMinutes', 1) === '1 دقیقه') | ||
}) | ||
}) | ||
|
||
context('when the count is more than 1', function() { | ||
it('returns a proper string', function() { | ||
assert(formatDistance('xMinutes', 2) === '2 دقیقه') | ||
}) | ||
}) | ||
}) | ||
|
||
describe('aboutXHours', function() { | ||
context('when the count equals 1', function() { | ||
it('returns a proper string', function() { | ||
assert(formatDistance('aboutXHours', 1) === 'حدود 1 ساعت') | ||
}) | ||
}) | ||
|
||
context('when the count is more than 1', function() { | ||
it('returns a proper string', function() { | ||
assert(formatDistance('aboutXHours', 2) === 'حدود 2 ساعت') | ||
}) | ||
}) | ||
}) | ||
|
||
describe('xHours', function() { | ||
context('when the count equals 1', function() { | ||
it('returns a proper string', function() { | ||
assert(formatDistance('xHours', 1) === '1 ساعت') | ||
}) | ||
}) | ||
|
||
context('when the count is more than 1', function() { | ||
it('returns a proper string', function() { | ||
assert(formatDistance('xHours', 2) === '2 ساعت') | ||
}) | ||
}) | ||
}) | ||
|
||
describe('xDays', function() { | ||
context('when the count equals 1', function() { | ||
it('returns a proper string', function() { | ||
assert(formatDistance('xDays', 1) === '1 روز') | ||
}) | ||
}) | ||
|
||
context('when the count is more than 1', function() { | ||
it('returns a proper string', function() { | ||
assert(formatDistance('xDays', 2) === '2 روز') | ||
}) | ||
}) | ||
}) | ||
|
||
describe('aboutXMonths', function() { | ||
context('when the count equals 1', function() { | ||
it('returns a proper string', function() { | ||
assert(formatDistance('aboutXMonths', 1) === 'حدود 1 ماه') | ||
}) | ||
}) | ||
|
||
context('when the count is more than 1', function() { | ||
it('returns a proper string', function() { | ||
assert(formatDistance('aboutXMonths', 2) === 'حدود 2 ماه') | ||
}) | ||
}) | ||
}) | ||
|
||
describe('xMonths', function() { | ||
context('when the count equals 1', function() { | ||
it('returns a proper string', function() { | ||
assert(formatDistance('xMonths', 1) === '1 ماه') | ||
}) | ||
}) | ||
|
||
context('when the count is more than 1', function() { | ||
it('returns a proper string', function() { | ||
assert(formatDistance('xMonths', 2) === '2 ماه') | ||
}) | ||
}) | ||
}) | ||
|
||
describe('aboutXYears', function() { | ||
context('when the count equals 1', function() { | ||
it('returns a proper string', function() { | ||
assert(formatDistance('aboutXYears', 1) === 'حدود 1 سال') | ||
}) | ||
}) | ||
|
||
context('when the count is more than 1', function() { | ||
it('returns a proper string', function() { | ||
assert(formatDistance('aboutXYears', 2) === 'حدود 2 سال') | ||
}) | ||
}) | ||
}) | ||
|
||
describe('xYears', function() { | ||
context('when the count equals 1', function() { | ||
it('returns a proper string', function() { | ||
assert(formatDistance('xYears', 1) === '1 سال') | ||
}) | ||
}) | ||
|
||
context('when the count is more than 1', function() { | ||
it('returns a proper string', function() { | ||
assert(formatDistance('xYears', 2) === '2 سال') | ||
}) | ||
}) | ||
}) | ||
|
||
describe('overXYears', function() { | ||
context('when the count equals 1', function() { | ||
it('returns a proper string', function() { | ||
assert(formatDistance('overXYears', 1) === 'بیشتر از 1 سال') | ||
}) | ||
}) | ||
|
||
context('when the count is more than 1', function() { | ||
it('returns a proper string', function() { | ||
assert(formatDistance('overXYears', 2) === 'بیشتر از 2 سال') | ||
}) | ||
}) | ||
}) | ||
|
||
describe('almostXYears', function() { | ||
context('when the count equals 1', function() { | ||
it('returns a proper string', function() { | ||
assert(formatDistance('almostXYears', 1) === 'نزدیک 1 سال') | ||
}) | ||
}) | ||
|
||
context('when the count is more than 1', function() { | ||
it('returns a proper string', function() { | ||
assert(formatDistance('almostXYears', 2) === 'نزدیک 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 === 'حدود 1 سال قبل') | ||
}) | ||
}) | ||
|
||
context('with a future suffix', function() { | ||
it('adds `in` to a string', function() { | ||
var result = formatDistance('halfAMinute', null, { | ||
addSuffix: true, | ||
comparison: 1 | ||
}) | ||
assert(result === 'در نیم دقیقه') | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import buildFormatLongFn from '../../../_lib/buildFormatLongFn/index.js' | ||
|
||
var dateFormats = { | ||
full: 'EEEE do MMMM y', | ||
long: 'do MMMM y', | ||
medium: 'd MMM y', | ||
short: 'yyyy/MM/dd' | ||
} | ||
|
||
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
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] | ||
} |
Oops, something went wrong.