-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1568 from iamkun/dev
D2M
- Loading branch information
Showing
19 changed files
with
287 additions
and
28 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,19 @@ | ||
Лицензия MIT | ||
|
||
Авторское право (c) с 2018 года по настоящее время, iamkun | ||
|
||
Данная лицензия разрешает лицам, получившим копию | ||
данного программного обеспечения и сопутствующей документации (в дальнейшем именуемыми «Программное обеспечение»), безвозмездно | ||
использовать Программное обеспечение без ограничений, включая неограниченное право | ||
на использование, копирование, изменение, слияние, публикацию, распространение, сублицензирование и/или продажу | ||
копий Программного обеспечения, а также лицам, которым предоставляется данное Программное обеспечение, | ||
при соблюдении следующих условий: | ||
|
||
Указанное выше уведомление об авторском праве и данные условия должны быть включены во все | ||
копии или значимые части данного Программного обеспечения. | ||
|
||
ДАННОЕ ПРОГРАММНОЕ ОБЕСПЕЧЕНИЕ ПРЕДОСТАВЛЯЕТСЯ «КАК ЕСТЬ», БЕЗ КАКИХ-ЛИБО ГАРАНТИЙ, ЯВНО ВЫРАЖЕННЫХ ИЛИ | ||
ПОДРАЗУМЕВАЕМЫХ, ВКЛЮЧАЯ ГАРАНТИИ ТОВАРНОЙ ПРИГОДНОСТИ, СООТВЕТСТВИЯ ПО ЕГО КОНКРЕТНОМУ НАЗНАЧЕНИЮ | ||
И ОТСУТСТВИЯ НАРУШЕНИЙ, НО НЕ ОГРАНИЧИВАЯСЬ ИМИ. НИ В КАКОМ СЛУЧАЕ АВТОРЫ ИЛИ ПРАВООБЛАДАТЕЛИ НЕ НЕСУТ ОТВЕТСТВЕННОСТИ | ||
ПО КАКИМ-ЛИБО ИСКАМ, ЗА УЩЕРБ ИЛИ ПО ИНЫМ ТРЕБОВАНИЯМ, В ТОМ ЧИСЛЕ, ПРИ ДЕЙСТВИИ КОНТРАКТА, ДЕЛИКТЕ ИЛИ ИНОЙ СИТУАЦИИ, | ||
ВОЗНИКШИМ ИЗ-ЗА ИСПОЛЬЗОВАНИЯ ПРОГРАММНОГО ОБЕСПЕЧЕНИЯ ИЛИ ИНЫХ ДЕЙСТВИЙ С ПРОГРАММНЫМ ОБЕСПЕЧЕНИЕМ. |
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
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
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,50 @@ | ||
// Finland Swedish [sv-fi] | ||
import dayjs from 'dayjs' | ||
|
||
const locale = { | ||
name: 'sv-fi', | ||
weekdays: 'söndag_måndag_tisdag_onsdag_torsdag_fredag_lördag'.split('_'), | ||
weekdaysShort: 'sön_mån_tis_ons_tor_fre_lör'.split('_'), | ||
weekdaysMin: 'sö_må_ti_on_to_fr_lö'.split('_'), | ||
months: 'januari_februari_mars_april_maj_juni_juli_augusti_september_oktober_november_december'.split('_'), | ||
monthsShort: 'jan_feb_mar_apr_maj_jun_jul_aug_sep_okt_nov_dec'.split('_'), | ||
weekStart: 1, | ||
yearStart: 4, | ||
ordinal: (n) => { | ||
const b = n % 10 | ||
const o = (b === 1) || (b === 2) ? 'a' : 'e' | ||
return `[${n}${o}]` | ||
}, | ||
formats: { | ||
LT: 'HH.mm', | ||
LTS: 'HH.mm.ss', | ||
L: 'DD.MM.YYYY', | ||
LL: 'D. MMMM YYYY', | ||
LLL: 'D. MMMM YYYY, [kl.] HH.mm', | ||
LLLL: 'dddd, D. MMMM YYYY, [kl.] HH.mm', | ||
l: 'D.M.YYYY', | ||
ll: 'D. MMM YYYY', | ||
lll: 'D. MMM YYYY, [kl.] HH.mm', | ||
llll: 'ddd, D. MMM YYYY, [kl.] HH.mm' | ||
}, | ||
relativeTime: { | ||
future: 'om %s', | ||
past: 'för %s sedan', | ||
s: 'några sekunder', | ||
m: 'en minut', | ||
mm: '%d minuter', | ||
h: 'en timme', | ||
hh: '%d timmar', | ||
d: 'en dag', | ||
dd: '%d dagar', | ||
M: 'en månad', | ||
MM: '%d månader', | ||
y: 'ett år', | ||
yy: '%d år' | ||
} | ||
} | ||
|
||
dayjs.locale(locale, null, true) | ||
|
||
export default locale | ||
|
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 |
---|---|---|
@@ -1,7 +1,8 @@ | ||
export default (o, c) => { | ||
export default (o, c, d) => { | ||
const proto = c.prototype | ||
proto.dayOfYear = function (input) { | ||
const dayOfYear = Math.round((this.startOf('day') - this.startOf('year')) / 864e5) + 1 | ||
// d(this) is for badMutable | ||
const dayOfYear = Math.round((d(this).startOf('day') - d(this).startOf('year')) / 864e5) + 1 | ||
return input == null ? dayOfYear : this.add(input - dayOfYear, 'day') | ||
} | ||
} |
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,67 @@ | ||
import moment from 'moment' | ||
import MockDate from 'mockdate' | ||
import dayjs from '../../src' | ||
import relativeTime from '../../src/plugin/relativeTime' | ||
import advancedFormat from '../../src/plugin/advancedFormat' | ||
import '../../src/locale/bg' | ||
|
||
dayjs.extend(relativeTime) | ||
dayjs.extend(advancedFormat) | ||
|
||
beforeEach(() => { | ||
MockDate.set(new Date()) | ||
}) | ||
|
||
afterEach(() => { | ||
MockDate.reset() | ||
}) | ||
|
||
it('Format Month with locale function', () => { | ||
for (let i = 0; i <= 7; i += 1) { | ||
const dayjsBG = dayjs().locale('bg').add(i, 'day') | ||
const momentBG = moment().locale('bg').add(i, 'day') | ||
const testFormat1 = 'DD MMMM YYYY MMM' | ||
const testFormat2 = 'MMMM' | ||
const testFormat3 = 'MMM' | ||
expect(dayjsBG.format(testFormat1)).toEqual(momentBG.format(testFormat1)) | ||
expect(dayjsBG.format(testFormat2)).toEqual(momentBG.format(testFormat2)) | ||
expect(dayjsBG.format(testFormat3)).toEqual(momentBG.format(testFormat3)) | ||
} | ||
}) | ||
|
||
it('RelativeTime: Time from X', () => { | ||
const T = [ | ||
[44.4, 'second'], // a few seconds | ||
[89.5, 'second'], // a minute | ||
[130, 'second'], // two minutes | ||
[43, 'minute'], // 44 minutes | ||
[1, 'hour'], // 1 hour | ||
[21, 'hour'], // 21 hours | ||
[2, 'day'], // 2 days | ||
[25, 'day'], // 25 days | ||
[2, 'month'], // 2 months | ||
[10, 'month'], // 10 months | ||
[18, 'month'], // 2 years | ||
[15, 'year'] // 15 years | ||
] | ||
|
||
T.forEach((t) => { | ||
dayjs.locale('bg') | ||
moment.locale('bg') | ||
expect(dayjs().from(dayjs().add(t[0], t[1]))) | ||
.toBe(moment().from(moment().add(t[0], t[1]))) | ||
expect(dayjs().from(dayjs().add(t[0], t[1]), true)) | ||
.toBe(moment().from(moment().add(t[0], t[1]), true)) | ||
}) | ||
}) | ||
|
||
it('Ordinal', () => { | ||
dayjs.locale('bg') | ||
moment.locale('bg') | ||
|
||
for (let d = 1; d <= 31; d += 1) { | ||
const day = d < 10 ? `0${d}` : d | ||
const date = `2021-01-${day}` | ||
expect(dayjs(date).format('Do')).toBe(moment(date).format('Do')) | ||
} | ||
}) |
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,35 @@ | ||
import dayjs from '../../src' | ||
import localizedFormat from '../../src/plugin/localizedFormat' | ||
import '../../src/locale/sv-fi' | ||
|
||
dayjs.extend(localizedFormat) | ||
|
||
it('Finland Swedish locale', () => { | ||
// time | ||
expect(dayjs('2019-02-01 12:34:56').locale('sv-fi').format('LT')) | ||
.toBe('12.34') | ||
expect(dayjs('2019-02-01 23:45:56').locale('sv-fi').format('LTS')) | ||
.toBe('23.45.56') | ||
|
||
// date | ||
expect(dayjs('2019-02-01').locale('sv-fi').format('L')) | ||
.toBe('01.02.2019') | ||
expect(dayjs('2019-12-15').locale('sv-fi').format('LL')) | ||
.toBe('15. december 2019') | ||
// short | ||
expect(dayjs('2019-02-01').locale('sv-fi').format('l')) | ||
.toBe('1.2.2019') | ||
expect(dayjs('2019-12-15').locale('sv-fi').format('ll')) | ||
.toBe('15. dec 2019') | ||
|
||
// date and time | ||
expect(dayjs('2019-03-01 12:30').locale('sv-fi').format('LLL')) | ||
.toBe('1. mars 2019, kl. 12.30') | ||
expect(dayjs('2021-06-12 17:30').locale('sv-fi').format('LLLL')) | ||
.toBe('lördag, 12. juni 2021, kl. 17.30') | ||
// short | ||
expect(dayjs('2019-03-01 12:30').locale('sv-fi').format('lll')) | ||
.toBe('1. mar 2019, kl. 12.30') | ||
expect(dayjs('2021-06-01 17:30').locale('sv-fi').format('llll')) | ||
.toBe('tis, 1. jun 2021, kl. 17.30') | ||
}) |
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
Oops, something went wrong.