-
-
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 #838 from iamkun/dev
D2M
- Loading branch information
Showing
9 changed files
with
223 additions
and
33 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
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,67 @@ | ||
// Chinese [zh] | ||
import dayjs from 'dayjs' | ||
|
||
const locale = { | ||
name: 'zh', | ||
weekdays: '星期日_星期一_星期二_星期三_星期四_星期五_星期六'.split('_'), | ||
weekdaysShort: '周日_周一_周二_周三_周四_周五_周六'.split('_'), | ||
weekdaysMin: '日_一_二_三_四_五_六'.split('_'), | ||
months: '一月_二月_三月_四月_五月_六月_七月_八月_九月_十月_十一月_十二月'.split('_'), | ||
monthsShort: '1月_2月_3月_4月_5月_6月_7月_8月_9月_10月_11月_12月'.split('_'), | ||
ordinal: (number, period) => { | ||
switch (period) { | ||
case 'W': | ||
return `${number}周` | ||
default: | ||
return `${number}日` | ||
} | ||
}, | ||
weekStart: 1, | ||
yearStart: 4, | ||
formats: { | ||
LT: 'HH:mm', | ||
LTS: 'HH:mm:ss', | ||
L: 'YYYY/MM/DD', | ||
LL: 'YYYY年M月D日', | ||
LLL: 'YYYY年M月D日Ah点mm分', | ||
LLLL: 'YYYY年M月D日ddddAh点mm分', | ||
l: 'YYYY/M/D', | ||
ll: 'YYYY年M月D日', | ||
lll: 'YYYY年M月D日 HH:mm', | ||
llll: 'YYYY年M月D日dddd HH:mm' | ||
}, | ||
relativeTime: { | ||
future: '%s后', | ||
past: '%s前', | ||
s: '几秒', | ||
m: '1 分钟', | ||
mm: '%d 分钟', | ||
h: '1 小时', | ||
hh: '%d 小时', | ||
d: '1 天', | ||
dd: '%d 天', | ||
M: '1 个月', | ||
MM: '%d 个月', | ||
y: '1 年', | ||
yy: '%d 年' | ||
}, | ||
meridiem: (hour, minute) => { | ||
const hm = (hour * 100) + minute | ||
if (hm < 600) { | ||
return '凌晨' | ||
} else if (hm < 900) { | ||
return '早上' | ||
} else if (hm < 1130) { | ||
return '上午' | ||
} else if (hm < 1230) { | ||
return '中午' | ||
} else if (hm < 1800) { | ||
return '下午' | ||
} | ||
return '晚上' | ||
} | ||
} | ||
|
||
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 |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import moment from 'moment' | ||
import MockDate from 'mockdate' | ||
import dayjs from '../../src' | ||
import relativeTime from '../../src/plugin/relativeTime' | ||
import '../../src/locale/sk' | ||
|
||
dayjs.extend(relativeTime) | ||
|
||
beforeEach(() => { | ||
MockDate.set(new Date()) | ||
}) | ||
|
||
afterEach(() => { | ||
MockDate.reset() | ||
}) | ||
|
||
it('RelativeTime: Time from X', () => { | ||
const T = [ | ||
[44.4, 'second'], // a few seconds | ||
[89.5, 'second'], // a minute | ||
[2, 'minute'], // 2 minutes | ||
[43, 'minute'], // 43 minutes | ||
[45, 'minute'], // an hour | ||
[3, 'hour'], // 3 hours | ||
[21, 'hour'], // 21 hours | ||
[1, 'day'], // a day | ||
[3, 'day'], // 3 day | ||
[25, 'day'], // 25 days | ||
[1, 'month'], // a month | ||
[2, 'month'], // 2 month | ||
[10, 'month'], // 10 month | ||
[1, 'year'], // a year | ||
[2, 'year'], // 2 year | ||
[5, 'year'], // 5 year | ||
[18, 'month'] // 2 years | ||
] | ||
|
||
T.forEach((t) => { | ||
dayjs.locale('sk') | ||
moment.locale('sk') | ||
const dayjsDay = dayjs() | ||
const momentDay = moment() | ||
const dayjsCompare = dayjs().add(t[0], t[1]) | ||
const momentCompare = moment().add(t[0], t[1]) | ||
expect(dayjsDay.from(dayjsCompare)) | ||
.toBe(momentDay.from(momentCompare)) | ||
expect(dayjsDay.to(dayjsCompare)) | ||
.toBe(momentDay.to(momentCompare)) | ||
expect(dayjsDay.from(dayjsCompare, true)) | ||
.toBe(momentDay.from(momentCompare, true)) | ||
}) | ||
}) |
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,20 @@ | ||
import dayjs from '../../src' | ||
import advancedFormat from '../../src/plugin/advancedFormat' | ||
import weekOfYear from '../../src/plugin/weekOfYear' | ||
import '../../src/locale/zh.js' | ||
import '../../src/locale/zh-cn.js' | ||
|
||
dayjs.extend(advancedFormat).extend(weekOfYear) | ||
|
||
const zh = dayjs().locale('zh') | ||
const zhCN = dayjs().locale('zh-cn') | ||
|
||
test('ordinal', () => { | ||
expect(zh.format('wo')).toEqual(`${zh.format('w')}周`) | ||
}) | ||
|
||
test('Meridiem', () => { | ||
for (let i = 0; i <= 24; i += 1) { | ||
expect(zh.add(i, 'hour').format('A')).toBe(zhCN.add(i, 'hour').format('A')) | ||
} | ||
}) |
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