Skip to content

Commit

Permalink
Merge pull request #1131 from iamkun/dev
Browse files Browse the repository at this point in the history
D2M
  • Loading branch information
splashwizard authored Oct 13, 2020
2 parents 4aaa931 + d146ac2 commit 57cf454
Show file tree
Hide file tree
Showing 22 changed files with 625 additions and 92 deletions.
4 changes: 2 additions & 2 deletions src/locale/ar-kw.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ import dayjs from 'dayjs'

const locale = {
name: 'ar-kw',
weekdays: 'الأحد_الإتنين_الثلاثاء_الأربعاء_الخميس_الجمعة_السبت'.split('_'),
weekdays: 'الأحد_الإثنين_الثلاثاء_الأربعاء_الخميس_الجمعة_السبت'.split('_'),
months: 'يناير_فبراير_مارس_أبريل_ماي_يونيو_يوليوز_غشت_شتنبر_أكتوبر_نونبر_دجنبر'.split('_'),
weekdaysShort: 'احد_اتنين_ثلاثاء_اربعاء_خميس_جمعة_سبت'.split('_'),
weekdaysShort: 'احد_اثنين_ثلاثاء_اربعاء_خميس_جمعة_سبت'.split('_'),
monthsShort: 'يناير_فبراير_مارس_أبريل_ماي_يونيو_يوليوز_غشت_شتنبر_أكتوبر_نونبر_دجنبر'.split('_'),
weekdaysMin: 'ح_ن_ث_ر_خ_ج_س'.split('_'),
ordinal: n => n,
Expand Down
4 changes: 2 additions & 2 deletions src/locale/ar-ma.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ import dayjs from 'dayjs'

const locale = {
name: 'ar-ma',
weekdays: 'الأحد_الإتنين_الثلاثاء_الأربعاء_الخميس_الجمعة_السبت'.split('_'),
weekdays: 'الأحد_الإثنين_الثلاثاء_الأربعاء_الخميس_الجمعة_السبت'.split('_'),
months: 'يناير_فبراير_مارس_أبريل_ماي_يونيو_يوليوز_غشت_شتنبر_أكتوبر_نونبر_دجنبر'.split('_'),
weekStart: 6,
weekdaysShort: 'احد_اتنين_ثلاثاء_اربعاء_خميس_جمعة_سبت'.split('_'),
weekdaysShort: 'احد_إثنين_ثلاثاء_اربعاء_خميس_جمعة_سبت'.split('_'),
monthsShort: 'يناير_فبراير_مارس_أبريل_ماي_يونيو_يوليوز_غشت_شتنبر_أكتوبر_نونبر_دجنبر'.split('_'),
weekdaysMin: 'ح_ن_ث_ر_خ_ج_س'.split('_'),
ordinal: n => n,
Expand Down
56 changes: 56 additions & 0 deletions src/locale/br.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,47 @@
// Breton [br]
import dayjs from 'dayjs'

function lastNumber(number) {
if (number > 9) {
return lastNumber(number % 10)
}
return number
}
function softMutation(text) {
const mutationTable = {
m: 'v',
b: 'v',
d: 'z'
}
return mutationTable[text.charAt(0)] + text.substring(1)
}
function mutation(text, number) {
if (number === 2) {
return softMutation(text)
}
return text
}
function relativeTimeWithMutation(number, withoutSuffix, key) {
const format = {
mm: 'munutenn',
MM: 'miz',
dd: 'devezh'
}
return `${number} ${mutation(format[key], number)}`
}
function specialMutationForYears(number) {
switch (lastNumber(number)) {
case 1:
case 3:
case 4:
case 5:
case 9:
return `${number} bloaz`
default:
return `${number} vloaz`
}
}

const locale = {
name: 'br',
weekdays: 'Sul_Lun_Meurzh_Mercʼher_Yaou_Gwener_Sadorn'.split('_'),
Expand All @@ -18,6 +59,21 @@ const locale = {
LLL: 'D [a viz] MMMM YYYY h[e]mm A',
LLLL: 'dddd, D [a viz] MMMM YYYY h[e]mm A'
},
relativeTime: {
future: 'a-benn %s',
past: '%s ʼzo',
s: 'un nebeud segondennoù',
m: 'ur vunutenn',
mm: relativeTimeWithMutation,
h: 'un eur',
hh: '%d eur',
d: 'un devezh',
dd: relativeTimeWithMutation,
M: 'ur miz',
MM: relativeTimeWithMutation,
y: 'ur bloaz',
yy: specialMutationForYears
},
meridiem: hour => (hour < 12 ? 'a.m.' : 'g.m.') // a-raok merenn | goude merenn
}

Expand Down
11 changes: 10 additions & 1 deletion src/locale/ca.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,16 @@ const locale = {
y: 'un any',
yy: '%d anys'
},
ordinal: n => `${n}º`
ordinal: (n) => {
let ord

if (n === 1 || n === 3) ord = 'r'
else if (n === 2) ord = 'n'
else if (n === 4) ord = 't'
else ord = 'è'

return `${n}${ord}`
}
}

dayjs.locale(locale, null, true)
Expand Down
44 changes: 33 additions & 11 deletions src/locale/de.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,28 @@
// German [de]
import dayjs from 'dayjs'

const texts = {
s: 'ein paar Sekunden',
m: ['eine Minute', 'einer Minute'],
mm: '%d Minuten',
h: ['eine Stunde', 'einer Stunde'],
hh: '%d Stunden',
d: ['ein Tag', 'einem Tag'],
dd: ['%d Tage', '%d Tagen'],
M: ['ein Monat', 'einem Monat'],
MM: ['%d Monate', '%d Monaten'],
y: ['ein Jahr', 'einem Jahr'],
yy: ['%d Jahre', '%d Jahren']
}

function relativeTimeFormatter(number, withoutSuffix, key) {
let l = texts[key]
if (Array.isArray(l)) {
l = l[withoutSuffix ? 0 : 1]
}
return l.replace('%d', number)
}

const locale = {
name: 'de',
weekdays: 'Sonntag_Montag_Dienstag_Mittwoch_Donnerstag_Freitag_Samstag'.split('_'),
Expand All @@ -21,17 +43,17 @@ const locale = {
relativeTime: {
future: 'in %s',
past: 'vor %s',
s: 'wenigen Sekunden',
m: 'einer Minute',
mm: '%d Minuten',
h: 'einer Stunde',
hh: '%d Stunden',
d: 'einem Tag',
dd: '%d Tagen',
M: 'einem Monat',
MM: '%d Monaten',
y: 'einem Jahr',
yy: '%d Jahren'
s: relativeTimeFormatter,
m: relativeTimeFormatter,
mm: relativeTimeFormatter,
h: relativeTimeFormatter,
hh: relativeTimeFormatter,
d: relativeTimeFormatter,
dd: relativeTimeFormatter,
M: relativeTimeFormatter,
MM: relativeTimeFormatter,
y: relativeTimeFormatter,
yy: relativeTimeFormatter
}
}

Expand Down
66 changes: 51 additions & 15 deletions src/locale/sr-cyrl.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,42 @@
// Serbian Cyrillic [sr-cyrl]
import dayjs from 'dayjs'

const translator = {
words: {
m: ['један минут', 'једног минута'],
mm: ['%d минут', '%d минута', '%d минута'],
h: ['један сат', 'једног сата'],
hh: ['%d сат', '%d сата', '%d сати'],
d: ['један дан', 'једног дана'],
dd: ['%d дан', '%d дана', '%d дана'],
M: ['један месец', 'једног месеца'],
MM: ['%d месец', '%d месеца', '%d месеци'],
y: ['једну годину', 'једне године'],
yy: ['%d годину', '%d године', '%d година']
},
correctGrammarCase(number, wordKey) {
if (number % 10 >= 1 && number % 10 <= 4 && (number % 100 < 10 || number % 100 >= 20)) {
return number % 10 === 1 ? wordKey[0] : wordKey[1]
}
return wordKey[2]
},
relativeTimeFormatter(number, withoutSuffix, key, isFuture) {
const wordKey = translator.words[key]

if (key.length === 1) {
// Nominativ
if (key === 'y' && withoutSuffix) return 'једна година'
return isFuture || withoutSuffix ? wordKey[0] : wordKey[1]
}

const word = translator.correctGrammarCase(number, wordKey)
// Nominativ
if (key === 'yy' && withoutSuffix && word === '%d годину') return `${number} година`

return word.replace('%d', number)
}
}

const locale = {
name: 'sr-cyrl',
weekdays: 'Недеља_Понедељак_Уторак_Среда_Четвртак_Петак_Субота'.split('_'),
Expand All @@ -12,26 +48,26 @@ const locale = {
relativeTime: {
future: 'за %s',
past: 'пре %s',
s: 'секунда',
m: 'минут',
mm: '%d минута',
h: 'сат',
hh: '%d сати',
d: 'дан',
dd: '%d дана',
M: 'месец',
MM: '%d месеци',
y: 'година',
yy: '%d године'
s: 'неколико секунди',
m: translator.relativeTimeFormatter,
mm: translator.relativeTimeFormatter,
h: translator.relativeTimeFormatter,
hh: translator.relativeTimeFormatter,
d: translator.relativeTimeFormatter,
dd: translator.relativeTimeFormatter,
M: translator.relativeTimeFormatter,
MM: translator.relativeTimeFormatter,
y: translator.relativeTimeFormatter,
yy: translator.relativeTimeFormatter
},
ordinal: n => `${n}.`,
formats: {
LT: 'H:mm',
LTS: 'H:mm:ss',
L: 'DD.MM.YYYY',
LL: 'D. MMMM YYYY',
LLL: 'D. MMMM YYYY H:mm',
LLLL: 'dddd, D. MMMM YYYY H:mm'
L: 'D. M. YYYY.',
LL: 'D. MMMM YYYY.',
LLL: 'D. MMMM YYYY. H:mm',
LLLL: 'dddd, D. MMMM YYYY. H:mm'
}
}

Expand Down
66 changes: 51 additions & 15 deletions src/locale/sr.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,42 @@
// Serbian [sr]
import dayjs from 'dayjs'

const translator = {
words: {
m: ['jedan minut', 'jednog minuta'],
mm: ['%d minut', '%d minuta', '%d minuta'],
h: ['jedan sat', 'jednog sata'],
hh: ['%d sat', '%d sata', '%d sati'],
d: ['jedan dan', 'jednog dana'],
dd: ['%d dan', '%d dana', '%d dana'],
M: ['jedan mesec', 'jednog meseca'],
MM: ['%d mesec', '%d meseca', '%d meseci'],
y: ['jednu godinu', 'jedne godine'],
yy: ['%d godinu', '%d godine', '%d godina']
},
correctGrammarCase(number, wordKey) {
if (number % 10 >= 1 && number % 10 <= 4 && (number % 100 < 10 || number % 100 >= 20)) {
return number % 10 === 1 ? wordKey[0] : wordKey[1]
}
return wordKey[2]
},
relativeTimeFormatter(number, withoutSuffix, key, isFuture) {
const wordKey = translator.words[key]

if (key.length === 1) {
// Nominativ
if (key === 'y' && withoutSuffix) return 'jedna godina'
return isFuture || withoutSuffix ? wordKey[0] : wordKey[1]
}

const word = translator.correctGrammarCase(number, wordKey)
// Nominativ
if (key === 'yy' && withoutSuffix && word === '%d godinu') return `${number} godina`

return word.replace('%d', number)
}
}

const locale = {
name: 'sr',
weekdays: 'Nedelja_Ponedeljak_Utorak_Sreda_Četvrtak_Petak_Subota'.split('_'),
Expand All @@ -12,26 +48,26 @@ const locale = {
relativeTime: {
future: 'za %s',
past: 'pre %s',
s: 'sekunda',
m: 'minut',
mm: '%d minuta',
h: 'sat',
hh: '%d sati',
d: 'dan',
dd: '%d dana',
M: 'mesec',
MM: '%d meseci',
y: 'godina',
yy: '%d godine'
s: 'nekoliko sekundi',
m: translator.relativeTimeFormatter,
mm: translator.relativeTimeFormatter,
h: translator.relativeTimeFormatter,
hh: translator.relativeTimeFormatter,
d: translator.relativeTimeFormatter,
dd: translator.relativeTimeFormatter,
M: translator.relativeTimeFormatter,
MM: translator.relativeTimeFormatter,
y: translator.relativeTimeFormatter,
yy: translator.relativeTimeFormatter
},
ordinal: n => `${n}.`,
formats: {
LT: 'H:mm',
LTS: 'H:mm:ss',
L: 'DD.MM.YYYY',
LL: 'D. MMMM YYYY',
LLL: 'D. MMMM YYYY H:mm',
LLLL: 'dddd, D. MMMM YYYY H:mm'
L: 'D. M. YYYY.',
LL: 'D. MMMM YYYY.',
LLL: 'D. MMMM YYYY. H:mm',
LLLL: 'dddd, D. MMMM YYYY. H:mm'
}
}

Expand Down
25 changes: 25 additions & 0 deletions src/plugin/arraySupport/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
export default (o, c, dayjs) => {
const proto = c.prototype
const parseDate = (cfg) => {
const { date, utc } = cfg
if (Array.isArray(date)) {
if (utc) {
if (!date.length) {
return new Date()
}
return new Date(Date.UTC.apply(null, date))
}
if (date.length === 1) {
return dayjs(String(date[0])).toDate()
}
return new (Function.prototype.bind.apply(Date, [null].concat(date)))()
}
return date
}

const oldParse = proto.parse
proto.parse = function (cfg) {
cfg.date = parseDate.bind(this)(cfg)
oldParse.bind(this)(cfg)
}
}
9 changes: 9 additions & 0 deletions src/plugin/duration/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -177,4 +177,13 @@ export default (option, Dayjs, dayjs) => {
return wrapper(input, { $l }, unit)
}
dayjs.isDuration = isDuration

const oldAdd = Dayjs.prototype.add
Dayjs.prototype.add = function (addition, units) {
if (isDuration(addition)) {
addition = addition.asMilliseconds()
units = 'ms'
}
return oldAdd.bind(this)(addition, units)
}
}
Loading

0 comments on commit 57cf454

Please sign in to comment.