Skip to content

Commit

Permalink
Merge pull request #838 from iamkun/dev
Browse files Browse the repository at this point in the history
D2M
  • Loading branch information
iamkun authored Mar 16, 2020
2 parents 193cf4b + 14044c6 commit 2bfdf84
Show file tree
Hide file tree
Showing 9 changed files with 223 additions and 33 deletions.
10 changes: 5 additions & 5 deletions src/locale/ar.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@ const locale = {
past: 'منذ %s',
s: 'ثانية واحدة',
m: 'دقيقة واحدة',
mm: 'دقائق %d',
mm: '%d دقائق',
h: 'ساعة واحدة',
hh: 'ساعات %d',
hh: '%d ساعات',
d: 'يوم واحد',
dd: 'أيام %d',
dd: '%d أيام',
M: 'شهر واحد',
MM: 'شهرا %d',
MM: '%d أشهر',
y: 'عام واحد',
yy: 'أعوام %d'
yy: '%d أعوام'
},
ordinal: n => n,
formats: {
Expand Down
1 change: 1 addition & 0 deletions src/locale/cs.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ const locale = {
months: 'leden_únor_březen_duben_květen_červen_červenec_srpen_září_říjen_listopad_prosinec'.split('_'),
monthsShort: 'led_úno_bře_dub_kvě_čvn_čvc_srp_zář_říj_lis_pro'.split('_'),
weekStart: 1,
yearStart: 4,
ordinal: n => `${n}.`,
formats: {
LT: 'H:mm',
Expand Down
88 changes: 69 additions & 19 deletions src/locale/sk.js
Original file line number Diff line number Diff line change
@@ -1,37 +1,87 @@
// Slovak [sk]
import dayjs from 'dayjs'

function plural(n) {
return (n > 1) && (n < 5) && (~~(n / 10) !== 1) // eslint-disable-line
}

/* eslint-disable */
function translate(number, withoutSuffix, key, isFuture) {
const result = `${number} `
switch (key) {
case 's': // a few seconds / in a few seconds / a few seconds ago
return (withoutSuffix || isFuture) ? 'pár sekúnd' : 'pár sekundami'
case 'm': // a minute / in a minute / a minute ago
return withoutSuffix ? 'minúta' : (isFuture ? 'minútu' : 'minútou')
case 'mm': // 9 minutes / in 9 minutes / 9 minutes ago
if (withoutSuffix || isFuture) {
return result + (plural(number) ? 'minúty' : 'minút')
}
return `${result}minútami`
case 'h': // an hour / in an hour / an hour ago
return withoutSuffix ? 'hodina' : (isFuture ? 'hodinu' : 'hodinou')
case 'hh': // 9 hours / in 9 hours / 9 hours ago
if (withoutSuffix || isFuture) {
return result + (plural(number) ? 'hodiny' : 'hodín')
}
return `${result}hodinami`
case 'd': // a day / in a day / a day ago
return (withoutSuffix || isFuture) ? 'deň' : 'dňom'
case 'dd': // 9 days / in 9 days / 9 days ago
if (withoutSuffix || isFuture) {
return result + (plural(number) ? 'dni' : 'dní')
}
return `${result}dňami`
case 'M': // a month / in a month / a month ago
return (withoutSuffix || isFuture) ? 'mesiac' : 'mesiacom'
case 'MM': // 9 months / in 9 months / 9 months ago
if (withoutSuffix || isFuture) {
return result + (plural(number) ? 'mesiace' : 'mesiacov')
}
return `${result}mesiacmi`
case 'y': // a year / in a year / a year ago
return (withoutSuffix || isFuture) ? 'rok' : 'rokom'
case 'yy': // 9 years / in 9 years / 9 years ago
if (withoutSuffix || isFuture) {
return result + (plural(number) ? 'roky' : 'rokov')
}
return `${result}rokmi`
}
}
/* eslint-enable */
const locale = {
name: 'sk',
weekdays: 'Nedeľa_Pondelok_Utorok_Streda_Štvrtok_Piatok_Sobota'.split('_'),
weekdaysShort: 'Ne_Po_Ut_St_Št_Pi_So'.split('_'),
weekdays: 'nedeľa_pondelok_utorok_streda_štvrtok_piatok_sobota'.split('_'),
weekdaysShort: 'ne_po_ut_st_št_pi_so'.split('_'),
weekdaysMin: 'ne_po_ut_st_št_pi_so'.split('_'),
months: 'január_február_marec_apríl_máj_jún_júl_august_september_október_november_december'.split('_'),
monthsShort: 'jan_feb_mar_apr_máj_jún_júl_aug_sep_okt_nov_dec'.split('_'),
weekStart: 1,
relativeTime: {
future: 'o %s',
past: 'pred %s',
s: 'niekoľko sekúnd',
m: 'minúta',
mm: '%d minút',
h: 'hodina',
hh: '%d hodín',
d: 'deň',
dd: '%d dní',
M: 'mesiac',
MM: '%d mesiacov',
y: 'rok',
yy: '%d rokov'
},
ordinal: n => `${n}º`,
yearStart: 4,
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'
LLLL: 'dddd D. MMMM YYYY H:mm',
l: 'D. M. YYYY'
},
relativeTime: {
future: 'za %s', // Should be `o %s` (change when moment/moment#5408 is fixed)
past: 'pred %s',
s: translate,
m: translate,
mm: translate,
h: translate,
hh: translate,
d: translate,
dd: translate,
M: translate,
MM: translate,
y: translate,
yy: translate
}
}

Expand Down
14 changes: 7 additions & 7 deletions src/locale/th.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,17 @@ const locale = {
},
relativeTime: {
future: 'อีก %s',
past: '%s ที่ผ่านมา',
s: 'ไม่กี่วิ',
m: 'นาที',
past: '%sที่แล้ว',
s: 'ไม่กี่วินาที',
m: '1 นาที',
mm: '%d นาที',
h: 'ชั่วโมง',
h: '1 ชั่วโมง',
hh: '%d ชั่วโมง',
d: 'วัน',
d: '1 วัน',
dd: '%d วัน',
M: 'เดือน',
M: '1 เดือน',
MM: '%d เดือน',
y: 'ปี',
y: '1 ปี',
yy: '%d ปี'
},
ordinal: n => `${n}.`
Expand Down
67 changes: 67 additions & 0 deletions src/locale/zh.js
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
2 changes: 1 addition & 1 deletion test/locale/cs.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ it('RelativeTime: Time from X', () => {
[44.4, 'second'], // a few seconds
[89.5, 'second'], // a minute
[2, 'minute'], // 2 minutes
[43, 'minute'], // 44 minutes
[43, 'minute'], // 43 minutes
[45, 'minute'], // an hour
[3, 'hour'], // 3 hours
[21, 'hour'], // 21 hours
Expand Down
52 changes: 52 additions & 0 deletions test/locale/sk.test.js
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))
})
})
20 changes: 20 additions & 0 deletions test/locale/zh.test.js
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'))
}
})
2 changes: 1 addition & 1 deletion types/plugin/isoWeek.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { PluginFunc, QUnitType, ConfigType } from 'dayjs'
import { PluginFunc, UnitType, ConfigType } from 'dayjs'

declare const plugin: PluginFunc
export = plugin
Expand Down

0 comments on commit 2bfdf84

Please sign in to comment.