Skip to content

Commit 7035414

Browse files
authored
Merge pull request #2449 from iamkun/dev
D2M
2 parents 04a23ce + 9e15db1 commit 7035414

17 files changed

+248
-41
lines changed

README.md

+4-3
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ English | [简体中文](./docs/zh-cn/README.zh-CN.md) | [日本語](./docs/ja/R
22

33
<p align="center"><a href="https://day.js.org/" target="_blank" rel="noopener noreferrer"><img width="550"
44
src="https://user-images.githubusercontent.com/17680888/39081119-3057bbe2-456e-11e8-862c-646133ad4b43.png"
5-
alt="Day.js"></a></p>
5+
alt="Day.js" /></a></p>
66
<p align="center">Fast <b>2kB</b> alternative to Moment.js with the same modern API</p>
77
<p align="center">
88
<a href="https://unpkg.com/dayjs/dayjs.min.js"><img
@@ -41,7 +41,7 @@ dayjs().startOf('month').add(1, 'day').set('year', 2018).format('YYYY-MM-DD HH:m
4141

4242
### Documentation
4343

44-
You can find for more details, API, and other docs on [day.js.org](https://day.js.org/) website.
44+
You can find more details, API, and other docs on [day.js.org](https://day.js.org/) website.
4545

4646
### Installation
4747

@@ -82,6 +82,7 @@ dayjs.locale('es') // use Spanish locale globally
8282

8383
dayjs('2018-05-05').locale('zh-cn').format() // use Chinese Simplified locale in a specific instance
8484
```
85+
8586
📚[Internationalization](https://day.js.org/docs/en/i18n/i18n)
8687

8788
### Plugin
@@ -100,7 +101,7 @@ dayjs().format('Q Do k kk X x') // more available formats
100101

101102
## Sponsors
102103

103-
Support this project by becoming a sponsor. Your logo will show up here with a link to your website.
104+
Support this project by becoming a sponsor. Your logo will show up here with a link to your website.
104105

105106
[[Become a sponsor via Github](https://github.com/sponsors/iamkun/)] [[Become a sponsor via OpenCollective](https://opencollective.com/dayjs#sponsor)]
106107

docs/ja/README-ja.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
日本語 | [English](../../README.md) | [简体中文](../zh-cn/README.zh-CN.md) | [Português Brasileiro](../pt-br/README-pt-br.md) | [한국어](../ko/README-ko.md) | [Español (España)](../es-es/README-es-es.md) | [Русский](../ru/README-ru.md)| [עברית](./docs/he/README-he.md)
1+
日本語 | [English](../../README.md) | [简体中文](../zh-cn/README.zh-CN.md) | [Português Brasileiro](../pt-br/README-pt-br.md) | [한국어](../ko/README-ko.md) | [Español (España)](../es-es/README-es-es.md) | [Русский](../ru/README-ru.md)| [עברית](../he/README-he.md)
22

33
<p align="center"><a href="https://day.js.org/" target="_blank" rel="noopener noreferrer"><img width="550"
44
src="https://user-images.githubusercontent.com/17680888/39081119-3057bbe2-456e-11e8-862c-646133ad4b43.png"
@@ -44,9 +44,9 @@ dayjs()
4444

4545
## はじめに
4646

47-
### Documentation
47+
### ドキュメント
4848

49-
You can find for more details, API, and other docs on [day.js.org](https://day.js.org/) website.
49+
詳細、API、その他のドキュメントについては、[day.js.org](https://day.js.org/) のウェブサイトを参照してください。
5050

5151
### インストール
5252

docs/ko/README-ko.md

+6-6
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
</a>
2424
</p>
2525

26-
> Day.js는 Moment.js와 호환되는 대부분의 API를 사용하며, 최신 브라우저에서 날짜와 시간에 대한 구문 분석, 유효성 검사, 조작, 출력하는 경량 JavaScript 라이브러리입니다. Moment.js를 사용하고 있다면, Day.js는 껌입니다.
26+
> Day.js는 대부분의 API가 Moment.js와 호환되며 최신 브라우저에서 날짜와 시간에 대한 구문 분석, 유효성 검사, 조작, 출력을 간편하게 처리하는 경량 JavaScript 라이브러리 입니다. Moment.js를 사용해본 경험이 있다면, Day.js도 쉽게 사용하실 수 있습니다.
2727
2828
```js
2929
dayjs()
@@ -46,7 +46,7 @@ dayjs()
4646

4747
### 문서
4848

49-
더 많은 세부 사항과 API, 그리고 다른 문서를 [day.js.org](https://day.js.org/) 웹사이트에서 수 있습니다.
49+
더 많은 세부 사항과 API 다른 문서는 [day.js.org](https://day.js.org/) 웹사이트에서 확인하실 수 있습니다.
5050

5151
### 설치
5252

@@ -58,7 +58,7 @@ npm install dayjs --save
5858

5959
### API
6060

61-
Day.js API를 사용해서 날짜와 시간에 대한 구문 분석, 유효성 검사, 조작, 출력을 쉽게 할 수 있습니다.
61+
Day.js API를 사용하여 날짜와 시간의 구문 분석, 검증, 조작, 출력을 간편하게 처리할 수 있습니다.
6262

6363
```javascript
6464
dayjs('2018-08-08') // parse
@@ -78,9 +78,9 @@ dayjs().isBefore(dayjs()) // query
7878

7979
### I18n
8080

81-
Day.js는 국제화에 대해 많은 지원을 합니다.
81+
Day.js는 국제화에 대한 많은 지원을 제공하고 있습니다.
8282

83-
그러나 그것을 사용하지 않는다면, 그 누구도 당신의 빌드에 포함되지 않습니다.
83+
하지만 이 기능을 사용하지 않는 경우, 빌드에 포함되지 않습니다.
8484

8585
```javascript
8686
import 'dayjs/locale/es' // load on demand
@@ -96,7 +96,7 @@ dayjs('2018-05-05')
9696

9797
### Plugin
9898

99-
플러그인은 기능을 확장하거나 새로운 기능을 추가하기 위해 Day.js에 추가할 수 있는 독립적인 모듈입니다.
99+
플러그인은 Day.js의 기능을 확장하거나 새로운 기능을 도입하기 위한 독립적인 모듈입니다.
100100

101101
```javascript
102102
import advancedFormat from 'dayjs/plugin/advancedFormat' // load on demand

src/index.js

+7-3
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,10 @@ let L = 'en' // global locale
66
const Ls = {} // global loaded locale
77
Ls[L] = en
88

9-
const isDayjs = d => d instanceof Dayjs // eslint-disable-line no-use-before-define
9+
const IS_DAYJS = '$isDayjsObject'
10+
11+
// eslint-disable-next-line no-use-before-define
12+
const isDayjs = d => d instanceof Dayjs || !!(d && d[IS_DAYJS])
1013

1114
const parseLocale = (preset, object, isLocal) => {
1215
let l
@@ -72,7 +75,7 @@ const parseDate = (cfg) => {
7275
|| 1, d[4] || 0, d[5] || 0, d[6] || 0, ms))
7376
}
7477
return new Date(d[1], m, d[3]
75-
|| 1, d[4] || 0, d[5] || 0, d[6] || 0, ms)
78+
|| 1, d[4] || 0, d[5] || 0, d[6] || 0, ms)
7679
}
7780
}
7881

@@ -83,11 +86,12 @@ class Dayjs {
8386
constructor(cfg) {
8487
this.$L = parseLocale(cfg.locale, null, true)
8588
this.parse(cfg) // for plugin
89+
this.$x = this.$x || cfg.x || {}
90+
this[IS_DAYJS] = true
8691
}
8792

8893
parse(cfg) {
8994
this.$d = parseDate(cfg)
90-
this.$x = cfg.x || {}
9195
this.init()
9296
}
9397

src/locale/ar.js

+2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import dayjs from 'dayjs'
33

44
const months = 'يناير_فبراير_مارس_أبريل_مايو_يونيو_يوليو_أغسطس_سبتمبر_أكتوبر_نوفمبر_ديسمبر'.split('_')
5+
56
const symbolMap = {
67
1: '١',
78
2: '٢',
@@ -36,6 +37,7 @@ const locale = {
3637
months,
3738
monthsShort: months,
3839
weekStart: 6,
40+
meridiem: hour => (hour > 12 ? 'م' : 'ص'),
3941
relativeTime: {
4042
future: 'بعد %s',
4143
past: 'منذ %s',

src/locale/fa.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@ import dayjs from 'dayjs'
44
const locale = {
55
name: 'fa',
66
weekdays: 'یک‌شنبه_دوشنبه_سه‌شنبه_چهارشنبه_پنج‌شنبه_جمعه_شنبه'.split('_'),
7-
weekdaysShort: 'یک‌_دو_سه‌_چه_پن_جم_شن'.split('_'),
7+
weekdaysShort: 'یک\u200cشنبه_دوشنبه_سه\u200cشنبه_چهارشنبه_پنج\u200cشنبه_جمعه_شنبه'.split('_'),
88
weekdaysMin: 'ی_د_س_چ_پ_ج_ش'.split('_'),
99
weekStart: 6,
10-
months: 'فروردین_اردیبهشت_خرداد_تیر_مرداد_شهریور_مهر_آبان_آذر_دی_بهمن_اسفند'.split('_'),
11-
monthsShort: 'فرو_ارد_خرد_تیر_مرد_شهر_مهر_آبا_آذر_دی_بهم_اسف'.split('_'),
10+
months: 'ژانویه_فوریه_مارس_آوریل_مه_ژوئن_ژوئیه_اوت_سپتامبر_اکتبر_نوامبر_دسامبر'.split('_'),
11+
monthsShort: 'ژانویه_فوریه_مارس_آوریل_مه_ژوئن_ژوئیه_اوت_سپتامبر_اکتبر_نوامبر_دسامبر'.split('_'),
1212
ordinal: n => n,
1313
formats: {
1414
LT: 'HH:mm',
@@ -20,7 +20,7 @@ const locale = {
2020
},
2121
relativeTime: {
2222
future: 'در %s',
23-
past: '%s قبل',
23+
past: '%s پیش',
2424
s: 'چند ثانیه',
2525
m: 'یک دقیقه',
2626
mm: '%d دقیقه',

src/locale/ko.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ const locale = {
88
weekdaysMin: '일_월_화_수_목_금_토'.split('_'),
99
months: '1월_2월_3월_4월_5월_6월_7월_8월_9월_10월_11월_12월'.split('_'),
1010
monthsShort: '1월_2월_3월_4월_5월_6월_7월_8월_9월_10월_11월_12월'.split('_'),
11-
ordinal: n => n,
11+
ordinal: n => `${n}일`,
1212
formats: {
1313
LT: 'A h:mm',
1414
LTS: 'A h:mm:ss',

src/locale/sl.js

+78-13
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,71 @@
11
// Slovenian [sl]
22
import dayjs from 'dayjs'
33

4+
function dual(n) {
5+
return (n % 100) == 2 // eslint-disable-line
6+
}
7+
8+
function threeFour(n) {
9+
return (n % 100) == 3 || (n % 100) == 4 // eslint-disable-line
10+
}
11+
12+
/* eslint-disable */
13+
function translate(number, withoutSuffix, key, isFuture) {
14+
const result = `${number} `
15+
switch (key) {
16+
case 's': // a few seconds / in a few seconds / a few seconds ago
17+
return (withoutSuffix || isFuture) ? 'nekaj sekund' : 'nekaj sekundami'
18+
case 'm': // a minute / in a minute / a minute ago
19+
return withoutSuffix ? 'ena minuta' : 'eno minuto'
20+
case 'mm': // 9 minutes / in 9 minutes / 9 minutes ago
21+
if (dual(number)) {
22+
return result + ((withoutSuffix || isFuture) ? 'minuti' : 'minutama')
23+
}
24+
if (threeFour(number)) {
25+
return result + ((withoutSuffix || isFuture) ? 'minute' : 'minutami')
26+
}
27+
return result + ((withoutSuffix || isFuture) ? 'minut' : 'minutami')
28+
case 'h': // an hour / in an hour / an hour ago
29+
return withoutSuffix ? 'ena ura' : (isFuture ? 'eno uro' : 'eno uro')
30+
case 'hh': // 9 hours / in 9 hours / 9 hours ago
31+
if (dual(number)) {
32+
return result + ((withoutSuffix || isFuture) ? 'uri' : 'urama')
33+
}
34+
if (threeFour(number)) {
35+
return result + ((withoutSuffix || isFuture) ? 'ure' : 'urami')
36+
}
37+
return result + ((withoutSuffix || isFuture) ? 'ur' : 'urami')
38+
case 'd': // a day / in a day / a day ago
39+
return (withoutSuffix || isFuture) ? 'en dan' : 'enim dnem'
40+
case 'dd': // 9 days / in 9 days / 9 days ago
41+
if (dual(number)) {
42+
return result + ((withoutSuffix || isFuture) ? 'dneva' : 'dnevoma')
43+
}
44+
return result + ((withoutSuffix || isFuture) ? 'dni' : 'dnevi')
45+
case 'M': // a month / in a month / a month ago
46+
return (withoutSuffix || isFuture) ? 'en mesec' : 'enim mesecem'
47+
case 'MM': // 9 months / in 9 months / 9 months ago
48+
if (dual(number)) { // 2 minutes / in 2 minutes
49+
return result + ((withoutSuffix || isFuture) ? 'meseca' : 'mesecema')
50+
}
51+
if (threeFour(number)) {
52+
return result + ((withoutSuffix || isFuture) ? 'mesece' : 'meseci')
53+
}
54+
return result + ((withoutSuffix || isFuture) ? 'mesecev' : 'meseci')
55+
case 'y': // a year / in a year / a year ago
56+
return (withoutSuffix || isFuture) ? 'eno leto' : 'enim letom'
57+
case 'yy': // 9 years / in 9 years / 9 years ago
58+
if (dual(number)) { // 2 minutes / in 2 minutes
59+
return result + ((withoutSuffix || isFuture) ? 'leti' : 'letoma')
60+
}
61+
if (threeFour(number)) {
62+
return result + ((withoutSuffix || isFuture) ? 'leta' : 'leti')
63+
}
64+
return result + ((withoutSuffix || isFuture) ? 'let' : 'leti')
65+
}
66+
}
67+
68+
/* eslint-enable */
469
const locale = {
570
name: 'sl',
671
weekdays: 'nedelja_ponedeljek_torek_sreda_četrtek_petek_sobota'.split('_'),
@@ -16,26 +81,26 @@ const locale = {
1681
L: 'DD.MM.YYYY',
1782
LL: 'D. MMMM YYYY',
1883
LLL: 'D. MMMM YYYY H:mm',
19-
LLLL: 'dddd, D. MMMM YYYY H:mm'
84+
LLLL: 'dddd, D. MMMM YYYY H:mm',
85+
l: 'D. M. YYYY'
2086
},
2187
relativeTime: {
2288
future: 'čez %s',
2389
past: 'pred %s',
24-
s: 'nekaj sekund',
25-
m: 'minuta',
26-
mm: '%d minut',
27-
h: 'ura',
28-
hh: '%d ur',
29-
d: 'dan',
30-
dd: '%d dni',
31-
M: 'mesec',
32-
MM: '%d mesecev',
33-
y: 'leto',
34-
yy: '%d let'
90+
s: translate,
91+
m: translate,
92+
mm: translate,
93+
h: translate,
94+
hh: translate,
95+
d: translate,
96+
dd: translate,
97+
M: translate,
98+
MM: translate,
99+
y: translate,
100+
yy: translate
35101
}
36102
}
37103

38104
dayjs.locale(locale, null, true)
39105

40106
export default locale
41-

src/locale/uz-latn.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ const locale = {
2020
},
2121
relativeTime: {
2222
future: 'Yaqin %s ichida',
23-
past: 'Bir necha %s oldin',
23+
past: '%s oldin',
2424
s: 'soniya',
2525
m: 'bir daqiqa',
2626
mm: '%d daqiqa',

src/locale/uz.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ const locale = {
2020
},
2121
relativeTime: {
2222
future: 'Якин %s ичида',
23-
past: 'Бир неча %s олдин',
23+
past: '%s олдин',
2424
s: 'фурсат',
2525
m: 'бир дакика',
2626
mm: '%d дакика',

src/plugin/duration/index.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import {
88
} from '../../constant'
99

1010
const MILLISECONDS_A_YEAR = MILLISECONDS_A_DAY * 365
11-
const MILLISECONDS_A_MONTH = MILLISECONDS_A_DAY * 30
11+
const MILLISECONDS_A_MONTH = MILLISECONDS_A_YEAR / 12
1212

1313
const durationRegex = /^(-|\+)?P(?:([-+]?[0-9,.]*)Y)?(?:([-+]?[0-9,.]*)M)?(?:([-+]?[0-9,.]*)W)?(?:([-+]?[0-9,.]*)D)?(?:T(?:([-+]?[0-9,.]*)H)?(?:([-+]?[0-9,.]*)M)?(?:([-+]?[0-9,.]*)S)?)?$/
1414

@@ -140,6 +140,7 @@ class Duration {
140140
let seconds = this.$d.seconds || 0
141141
if (this.$d.milliseconds) {
142142
seconds += this.$d.milliseconds / 1000
143+
seconds = Math.round(seconds * 1000) / 1000
143144
}
144145

145146
const S = getNumberUnitFormat(seconds, 'S')
@@ -198,7 +199,7 @@ class Duration {
198199
} else {
199200
base = this.$d[pUnit]
200201
}
201-
return base === 0 ? 0 : base // a === 0 will be true on both 0 and -0
202+
return base || 0 // a === 0 will be true on both 0 and -0
202203
}
203204

204205
add(input, unit, isSubtract) {

src/plugin/timezone/index.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ export default (o, c, d) => {
9797
const date = this.toDate()
9898
const target = date.toLocaleString('en-US', { timeZone: timezone })
9999
const diff = Math.round((date - new Date(target)) / 1000 / 60)
100-
let ins = d(target).$set(MS, this.$ms)
100+
let ins = d(target, { locale: this.$L }).$set(MS, this.$ms)
101101
.utcOffset((-Math.round(date.getTimezoneOffset() / 15) * 15) - diff, true)
102102
if (keepLocalTime) {
103103
const newOffset = ins.utcOffset()
@@ -120,7 +120,7 @@ export default (o, c, d) => {
120120
return oldStartOf.call(this, units, startOf)
121121
}
122122

123-
const withoutTz = d(this.format('YYYY-MM-DD HH:mm:ss:SSS'))
123+
const withoutTz = d(this.format('YYYY-MM-DD HH:mm:ss:SSS'), { locale: this.$L })
124124
const startOfWithoutTz = oldStartOf.call(withoutTz, units, startOf)
125125
return startOfWithoutTz.tz(this.$x.$timezone, true)
126126
}

test/constructor.test.js

+8
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,14 @@ it('supports instanceof dayjs', () => {
1313
expect(dayjs() instanceof dayjs).toBeTruthy()
1414
})
1515

16+
it('$isDayjsObject', () => {
17+
const mockOtherVersionDayjsObj = {
18+
$isDayjsObject: true
19+
}
20+
expect(dayjs.isDayjs(mockOtherVersionDayjsObj)).toBeTruthy()
21+
})
22+
1623
it('does not break isDayjs', () => {
1724
expect(dayjs.isDayjs(dayjs())).toBeTruthy()
25+
expect(dayjs.isDayjs(new Date())).toBeFalsy()
1826
})

test/locale/ar.test.js

+10
Original file line numberDiff line numberDiff line change
@@ -50,3 +50,13 @@ it('RelativeTime: Time from X gets formatted', () => {
5050
.toBe(t[2])
5151
})
5252
})
53+
54+
it('Format meridiem with locale function', () => {
55+
for (let i = 0; i <= 23; i += 1) {
56+
const hour = dayjs()
57+
.startOf('day')
58+
.add(i, 'hour')
59+
const meridiem = i > 12 ? 'م' : 'ص'
60+
expect(hour.locale('ar').format('A')).toBe(`${meridiem}`)
61+
}
62+
})

0 commit comments

Comments
 (0)