Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: iamkun/dayjs
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v1.8.22
Choose a base ref
...
head repository: iamkun/dayjs
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v1.8.23
Choose a head ref
  • 8 commits
  • 10 files changed
  • 6 contributors

Commits on Mar 9, 2020

  1. Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    63b7c03 View commit details
  2. Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    30aab0c View commit details

Commits on Mar 10, 2020

  1. chore: add zh locale (#822)

    ZYinMD authored Mar 10, 2020

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    9dd69ed View commit details
  2. fix: Add Chinese (zh) locale

    iamkun committed Mar 10, 2020
    Copy the full SHA
    f9b8945 View commit details

Commits on Mar 14, 2020

  1. Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    f0d451f View commit details

Commits on Mar 16, 2020

  1. Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    14044c6 View commit details
  2. Merge pull request #838 from iamkun/dev

    D2M
    iamkun authored Mar 16, 2020

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    2bfdf84 View commit details
  3. chore(release): 1.8.23 [skip ci]

    ## [1.8.23](v1.8.22...v1.8.23) (2020-03-16)
    
    ### Bug Fixes
    
    * Add Chinese (zh) locale ([f9b8945](f9b8945))
    * Fix IsoWeek plugin typescript definition ([#828](#828)) ([30aab0c](30aab0c))
    * Update Arabic (ar) locale relative time ([#836](#836)) ([14044c6](14044c6))
    * Update Slovak (sk) locale,  Czech (cs) locale ([#833](#833)) ([f0d451f](f0d451f))
    * Update Thai (th) locale relativeTime ([#826](#826)) ([63b7c03](63b7c03)), closes [#816](#816)
    semantic-release-bot committed Mar 16, 2020
    Copy the full SHA
    90eae15 View commit details
Showing with 234 additions and 33 deletions.
  1. +11 −0 CHANGELOG.md
  2. +5 −5 src/locale/ar.js
  3. +1 −0 src/locale/cs.js
  4. +69 −19 src/locale/sk.js
  5. +7 −7 src/locale/th.js
  6. +67 −0 src/locale/zh.js
  7. +1 −1 test/locale/cs.test.js
  8. +52 −0 test/locale/sk.test.js
  9. +20 −0 test/locale/zh.test.js
  10. +1 −1 types/plugin/isoWeek.d.ts
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
## [1.8.23](https://github.com/iamkun/dayjs/compare/v1.8.22...v1.8.23) (2020-03-16)


### Bug Fixes

* Add Chinese (zh) locale ([f9b8945](https://github.com/iamkun/dayjs/commit/f9b89453166d8b53d33b1d7eefd9942022552e6e))
* Fix IsoWeek plugin typescript definition ([#828](https://github.com/iamkun/dayjs/issues/828)) ([30aab0c](https://github.com/iamkun/dayjs/commit/30aab0c7bce85dfac0ae208a891def30f88b5cb4))
* Update Arabic (ar) locale relative time ([#836](https://github.com/iamkun/dayjs/issues/836)) ([14044c6](https://github.com/iamkun/dayjs/commit/14044c6fda1229e3f0e5473d3f886bd79589b15f))
* Update Slovak (sk) locale, Czech (cs) locale ([#833](https://github.com/iamkun/dayjs/issues/833)) ([f0d451f](https://github.com/iamkun/dayjs/commit/f0d451f795e9ebf752cd854d51b25b11de2343a3))
* Update Thai (th) locale relativeTime ([#826](https://github.com/iamkun/dayjs/issues/826)) ([63b7c03](https://github.com/iamkun/dayjs/commit/63b7c03a6dbb0507d60776e8bad6cccde3828b88)), closes [#816](https://github.com/iamkun/dayjs/issues/816)

## [1.8.22](https://github.com/iamkun/dayjs/compare/v1.8.21...v1.8.22) (2020-03-08)


10 changes: 5 additions & 5 deletions src/locale/ar.js
Original file line number Diff line number Diff line change
@@ -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: {
1 change: 1 addition & 0 deletions src/locale/cs.js
Original file line number Diff line number Diff line change
@@ -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',
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
}
}

14 changes: 7 additions & 7 deletions src/locale/th.js
Original file line number Diff line number Diff line change
@@ -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}.`
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
@@ -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
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