-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
914 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
var formatDistanceLocale = { | ||
lessThanXSeconds: { | ||
one: 'menos de um segundo', | ||
other: 'menos de {{count}} segundos' | ||
}, | ||
|
||
xSeconds: { | ||
one: '1 segundo', | ||
other: '{{count}} segundos' | ||
}, | ||
|
||
halfAMinute: 'meio minuto', | ||
|
||
lessThanXMinutes: { | ||
one: 'menos de um minuto', | ||
other: 'menos de {{count}} minutos' | ||
}, | ||
|
||
xMinutes: { | ||
one: '1 minuto', | ||
other: '{{count}} minutos' | ||
}, | ||
|
||
aboutXHours: { | ||
one: 'cerca de 1 hora', | ||
other: 'cerca de {{count}} horas' | ||
}, | ||
|
||
xHours: { | ||
one: '1 hora', | ||
other: '{{count}} horas' | ||
}, | ||
|
||
xDays: { | ||
one: '1 dia', | ||
other: '{{count}} dias' | ||
}, | ||
|
||
aboutXMonths: { | ||
one: 'cerca de 1 mês', | ||
other: 'cerca de {{count}} meses' | ||
}, | ||
|
||
xMonths: { | ||
one: '1 mês', | ||
other: '{{count}} meses' | ||
}, | ||
|
||
aboutXYears: { | ||
one: 'cerca de 1 ano', | ||
other: 'cerca de {{count}} anos' | ||
}, | ||
|
||
xYears: { | ||
one: '1 ano', | ||
other: '{{count}} anos' | ||
}, | ||
|
||
overXYears: { | ||
one: 'mais de 1 ano', | ||
other: 'mais de {{count}} anos' | ||
}, | ||
|
||
almostXYears: { | ||
one: 'quase 1 ano', | ||
other: 'quase {{count}} anos' | ||
} | ||
} | ||
|
||
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 'em ' + result | ||
} else { | ||
return 'há ' + 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('pt-BR locale > formatDistance', function () { | ||
describe('lessThanXSeconds', function () { | ||
context('when the count equals 1', function () { | ||
it('returns a proper string', function () { | ||
assert(formatDistance('lessThanXSeconds', 1) === 'menos de um segundo') | ||
}) | ||
}) | ||
|
||
context('when the count is more than 1', function () { | ||
it('returns a proper string', function () { | ||
assert(formatDistance('lessThanXSeconds', 2) === 'menos de 2 segundos') | ||
}) | ||
}) | ||
}) | ||
|
||
describe('xSeconds', function () { | ||
context('when the count equals 1', function () { | ||
it('returns a proper string', function () { | ||
assert(formatDistance('xSeconds', 1) === '1 segundo') | ||
}) | ||
}) | ||
|
||
context('when the count is more than 1', function () { | ||
it('returns a proper string', function () { | ||
assert(formatDistance('xSeconds', 2) === '2 segundos') | ||
}) | ||
}) | ||
}) | ||
|
||
describe('halfAMinute', function () { | ||
it('returns a proper string', function () { | ||
assert(formatDistance('halfAMinute') === 'meio minuto') | ||
}) | ||
|
||
it('ignores the second argument', function () { | ||
assert(formatDistance('halfAMinute', 123) === 'meio minuto') | ||
}) | ||
}) | ||
|
||
describe('lessThanXMinutes', function () { | ||
context('when the count equals 1', function () { | ||
it('returns a proper string', function () { | ||
assert(formatDistance('lessThanXMinutes', 1) === 'menos de um minuto') | ||
}) | ||
}) | ||
|
||
context('when the count is more than 1', function () { | ||
it('returns a proper string', function () { | ||
assert(formatDistance('lessThanXMinutes', 2) === 'menos de 2 minutos') | ||
}) | ||
}) | ||
}) | ||
|
||
describe('xMinutes', function () { | ||
context('when the count equals 1', function () { | ||
it('returns a proper string', function () { | ||
assert(formatDistance('xMinutes', 1) === '1 minuto') | ||
}) | ||
}) | ||
|
||
context('when the count is more than 1', function () { | ||
it('returns a proper string', function () { | ||
assert(formatDistance('xMinutes', 2) === '2 minutos') | ||
}) | ||
}) | ||
}) | ||
|
||
describe('aboutXHours', function () { | ||
context('when the count equals 1', function () { | ||
it('returns a proper string', function () { | ||
assert(formatDistance('aboutXHours', 1) === 'cerca de 1 hora') | ||
}) | ||
}) | ||
|
||
context('when the count is more than 1', function () { | ||
it('returns a proper string', function () { | ||
assert(formatDistance('aboutXHours', 2) === 'cerca de 2 horas') | ||
}) | ||
}) | ||
}) | ||
|
||
describe('xHours', function () { | ||
context('when the count equals 1', function () { | ||
it('returns a proper string', function () { | ||
assert(formatDistance('xHours', 1) === '1 hora') | ||
}) | ||
}) | ||
|
||
context('when the count is more than 1', function () { | ||
it('returns a proper string', function () { | ||
assert(formatDistance('xHours', 2) === '2 horas') | ||
}) | ||
}) | ||
}) | ||
|
||
describe('xDays', function () { | ||
context('when the count equals 1', function () { | ||
it('returns a proper string', function () { | ||
assert(formatDistance('xDays', 1) === '1 dia') | ||
}) | ||
}) | ||
|
||
context('when the count is more than 1', function () { | ||
it('returns a proper string', function () { | ||
assert(formatDistance('xDays', 2) === '2 dias') | ||
}) | ||
}) | ||
}) | ||
|
||
describe('aboutXMonths', function () { | ||
context('when the count equals 1', function () { | ||
it('returns a proper string', function () { | ||
assert(formatDistance('aboutXMonths', 1) === 'cerca de 1 mês') | ||
}) | ||
}) | ||
|
||
context('when the count is more than 1', function () { | ||
it('returns a proper string', function () { | ||
assert(formatDistance('aboutXMonths', 2) === 'cerca de 2 meses') | ||
}) | ||
}) | ||
}) | ||
|
||
describe('xMonths', function () { | ||
context('when the count equals 1', function () { | ||
it('returns a proper string', function () { | ||
assert(formatDistance('xMonths', 1) === '1 mês') | ||
}) | ||
}) | ||
|
||
context('when the count is more than 1', function () { | ||
it('returns a proper string', function () { | ||
assert(formatDistance('xMonths', 2) === '2 meses') | ||
}) | ||
}) | ||
}) | ||
|
||
describe('aboutXYears', function () { | ||
context('when the count equals 1', function () { | ||
it('returns a proper string', function () { | ||
assert(formatDistance('aboutXYears', 1) === 'cerca de 1 ano') | ||
}) | ||
}) | ||
|
||
context('when the count is more than 1', function () { | ||
it('returns a proper string', function () { | ||
assert(formatDistance('aboutXYears', 2) === 'cerca de 2 anos') | ||
}) | ||
}) | ||
}) | ||
|
||
describe('xYears', function () { | ||
context('when the count equals 1', function () { | ||
it('returns a proper string', function () { | ||
assert(formatDistance('xYears', 1) === '1 ano') | ||
}) | ||
}) | ||
|
||
context('when the count is more than 1', function () { | ||
it('returns a proper string', function () { | ||
assert(formatDistance('xYears', 2) === '2 anos') | ||
}) | ||
}) | ||
}) | ||
|
||
describe('overXYears', function () { | ||
context('when the count equals 1', function () { | ||
it('returns a proper string', function () { | ||
assert(formatDistance('overXYears', 1) === 'mais de 1 ano') | ||
}) | ||
}) | ||
|
||
context('when the count is more than 1', function () { | ||
it('returns a proper string', function () { | ||
assert(formatDistance('overXYears', 2) === 'mais de 2 anos') | ||
}) | ||
}) | ||
}) | ||
|
||
describe('almostXYears', function () { | ||
context('when the count equals 1', function () { | ||
it('returns a proper string', function () { | ||
assert(formatDistance('almostXYears', 1) === 'quase 1 ano') | ||
}) | ||
}) | ||
|
||
context('when the count is more than 1', function () { | ||
it('returns a proper string', function () { | ||
assert(formatDistance('almostXYears', 2) === 'quase 2 anos') | ||
}) | ||
}) | ||
}) | ||
|
||
context('with a past suffix', function () { | ||
it('adds `ago` to a string', function () { | ||
var result = formatDistance('aboutXYears', 1, { | ||
addSuffix: true, | ||
comparison: -1 | ||
}) | ||
assert(result === 'há cerca de 1 ano') | ||
}) | ||
}) | ||
|
||
context('with a future suffix', function () { | ||
it('adds `in` to a string', function () { | ||
var result = formatDistance('halfAMinute', null, { | ||
addSuffix: true, | ||
comparison: 1 | ||
}) | ||
assert(result === 'em meio minuto') | ||
}) | ||
}) | ||
}) |
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 @@ | ||
import buildFormatLongFn from '../../../_lib/buildFormatLongFn/index.js' | ||
|
||
var formatLong = buildFormatLongFn({ | ||
LT: 'h:mm aa', | ||
LTS: 'h:mm:ss aa', | ||
L: 'DD/MM/YYYY', | ||
LL: 'D [de] MMMM [de] YYYY', | ||
LLL: 'D [de] MMMM [de] YYYY [às] h:mm aa', | ||
LLLL: 'dddd, D [de] MMMM [de] YYYY [às] h:mm aa' | ||
}) | ||
|
||
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,22 @@ | ||
var formatRelativeLocale = { | ||
lastWeek: function (date, baseDate, options) { | ||
var weekday = date.getUTCDay() | ||
var last = weekday === 0 || weekday === 6 ? 'último' : 'última' | ||
return '[' + last + '] dddd [às] LT' | ||
}, | ||
yesterday: '[ontem às] LT', | ||
today: '[hoje às] LT', | ||
tomorrow: '[amanhã às] LT', | ||
nextWeek: 'dddd [às] LT', | ||
other: 'L' | ||
} | ||
|
||
export default function formatRelative (token, date, baseDate, options) { | ||
var format = formatRelativeLocale[token] | ||
|
||
if (typeof format === 'function') { | ||
return format(date, baseDate, options) | ||
} | ||
|
||
return format | ||
} |
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,44 @@ | ||
import buildLocalizeFn from '../../../_lib/buildLocalizeFn/index.js' | ||
import buildLocalizeArrayFn from '../../../_lib/buildLocalizeArrayFn/index.js' | ||
|
||
var weekdayValues = { | ||
narrow: ['do', 'sg', 'te', 'qa', 'qi', 'sx', 'sa'], | ||
short: ['dom', 'seg', 'ter', 'qua', 'qui', 'sex', 'sáb'], | ||
long: ['domingo', 'segunda', 'terça', 'quarta', 'quinta', 'sexta', 'sábado'] | ||
} | ||
|
||
var monthValues = { | ||
short: ['jan', 'fev', 'mar', 'abr', 'mai', 'jun', 'jul', 'ago', 'set', 'out', 'nov', 'dez'], | ||
long: ['janeiro', 'fevereiro', 'março', 'abril', 'maio', 'junho', 'julho', 'agosto', 'setembro', 'outubro', 'novembro', 'dezembro'] | ||
} | ||
|
||
var timeOfDayValues = { | ||
uppercase: ['AM', 'PM'], | ||
lowercase: ['am', 'pm'], | ||
long: ['a.m.', 'p.m.'] | ||
} | ||
|
||
function ordinalNumber (dirtyNumber, dirtyOptions) { | ||
var number = Number(dirtyNumber) | ||
var options = dirtyOptions || {} | ||
var unit = String(options.unit) | ||
|
||
if (unit === 'week' || unit === 'isoWeek') { | ||
return number + 'ª' | ||
} | ||
return number + 'º' | ||
} | ||
|
||
var localize = { | ||
ordinalNumber: ordinalNumber, | ||
weekday: buildLocalizeFn(weekdayValues, 'long'), | ||
weekdays: buildLocalizeArrayFn(weekdayValues, 'long'), | ||
month: buildLocalizeFn(monthValues, 'long'), | ||
months: buildLocalizeArrayFn(monthValues, 'long'), | ||
timeOfDay: buildLocalizeFn(timeOfDayValues, 'long', function (hours) { | ||
return (hours / 12) >= 1 ? 1 : 0 | ||
}), | ||
timesOfDay: buildLocalizeArrayFn(timeOfDayValues, 'long') | ||
} | ||
|
||
export default localize |
Oops, something went wrong.