From 89bf31ce0a36dcfc892029dc019d85d3654cf5fb Mon Sep 17 00:00:00 2001 From: titanism <101466223+titanism@users.noreply.github.com> Date: Thu, 22 Jun 2023 03:56:09 -0500 Subject: [PATCH 1/5] fix: objectSupport plugin causes an error when null is passed to dayjs function (closes #2277) (#2342) --- src/plugin/objectSupport/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/plugin/objectSupport/index.js b/src/plugin/objectSupport/index.js index 650166606..4800b6873 100644 --- a/src/plugin/objectSupport/index.js +++ b/src/plugin/objectSupport/index.js @@ -1,7 +1,7 @@ export default (o, c, dayjs) => { const proto = c.prototype const isObject = obj => !(obj instanceof Date) && !(obj instanceof Array) - && !proto.$utils().u(obj) && (obj.constructor.name === 'Object') + && !proto.$utils().u(obj) && obj !== null && (obj.constructor.name === 'Object') const prettyUnit = (u) => { const unit = proto.$utils().p(u) return unit === 'date' ? 'day' : unit From 1a199d3764fcf5ee8bd0d2b1aa044bb23809755f Mon Sep 17 00:00:00 2001 From: iamkun Date: Thu, 22 Jun 2023 17:00:50 +0800 Subject: [PATCH 2/5] test: update test case --- test/display.test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/display.test.js b/test/display.test.js index 86a978dfc..a1d87be29 100644 --- a/test/display.test.js +++ b/test/display.test.js @@ -264,7 +264,7 @@ it('As ISO 8601 String -> toISOString e.g. 2013-02-04T22:44:30.652Z', () => { it('Year 1 formatted with YYYY should pad with zeroes', () => { const date = new Date(1, 0, 1) date.setUTCFullYear(1) // Required because 0-99 are parsed as 19xx in JS: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/Date#year - expect(dayjs(date).format('YYYY')).toBe('0001') + expect(dayjs(date).format('YYYY')).toBe('0002') }) it('Year 1 formatting matches moment format', () => { From 548b217c5916862fe02504c7b0687c51ef14e237 Mon Sep 17 00:00:00 2001 From: iamkun Date: Thu, 22 Jun 2023 17:04:48 +0800 Subject: [PATCH 3/5] test: update test case --- test/display.test.js | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/test/display.test.js b/test/display.test.js index a1d87be29..ce1f47893 100644 --- a/test/display.test.js +++ b/test/display.test.js @@ -264,11 +264,7 @@ it('As ISO 8601 String -> toISOString e.g. 2013-02-04T22:44:30.652Z', () => { it('Year 1 formatted with YYYY should pad with zeroes', () => { const date = new Date(1, 0, 1) date.setUTCFullYear(1) // Required because 0-99 are parsed as 19xx in JS: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/Date#year - expect(dayjs(date).format('YYYY')).toBe('0002') -}) - -it('Year 1 formatting matches moment format', () => { - const date = new Date(1, 0, 1) - date.setUTCFullYear(1) - expect(dayjs(date).format('YYYY')).toBe(moment(date).format('YYYY')) + const res = dayjs(date).format('YYYY') + expect(res.slice(0, 3)).toBe('000') // because of timezone, the result might be 0000 0001 or 0002 + expect(res).toBe(moment(date).format('YYYY')) }) From 33c80e14cf14f70ceb4f54639e266cd70a3c3996 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E6=9D=83=E5=A8=81?= Date: Thu, 22 Jun 2023 17:06:49 +0800 Subject: [PATCH 4/5] fix: dayjs.diff improve performance (#2244) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * improve: diff performance * refactor: switch refactor --------- Co-authored-by: 李权威 --- .editorconfig | 1 + src/index.js | 44 ++++++++++++++++++++++++++++++++------------ 2 files changed, 33 insertions(+), 12 deletions(-) diff --git a/.editorconfig b/.editorconfig index 14c1d8c19..d4d73cf57 100644 --- a/.editorconfig +++ b/.editorconfig @@ -4,3 +4,4 @@ root = true charset = utf-8 end_of_line = lf insert_final_newline = true +indent_size = 2 diff --git a/src/index.js b/src/index.js index ba74b8b66..5b4c464db 100644 --- a/src/index.js +++ b/src/index.js @@ -319,18 +319,38 @@ class Dayjs { const that = dayjs(input) const zoneDelta = (that.utcOffset() - this.utcOffset()) * C.MILLISECONDS_A_MINUTE const diff = this - that - let result = Utils.m(this, that) - - result = { - [C.Y]: result / 12, - [C.M]: result, - [C.Q]: result / 3, - [C.W]: (diff - zoneDelta) / C.MILLISECONDS_A_WEEK, - [C.D]: (diff - zoneDelta) / C.MILLISECONDS_A_DAY, - [C.H]: diff / C.MILLISECONDS_A_HOUR, - [C.MIN]: diff / C.MILLISECONDS_A_MINUTE, - [C.S]: diff / C.MILLISECONDS_A_SECOND - }[unit] || diff // milliseconds + const getMonth = () => Utils.m(this, that) + + let result + switch (unit) { + case C.Y: + result = getMonth() / 12 + break + case C.M: + result = getMonth() + break + case C.Q: + result = getMonth() / 3 + break + case C.W: + result = (diff - zoneDelta) / C.MILLISECONDS_A_WEEK + break + case C.D: + result = (diff - zoneDelta) / C.MILLISECONDS_A_DAY + break + case C.H: + result = diff / C.MILLISECONDS_A_HOUR + break + case C.MIN: + result = diff / C.MILLISECONDS_A_MINUTE + break + case C.S: + result = diff / C.MILLISECONDS_A_SECOND + break + default: + result = diff // milliseconds + break + } return float ? result : Utils.a(result) } From 24e303871b8bba08afe85a121f2873ae5b282192 Mon Sep 17 00:00:00 2001 From: Binyamin Yawitz Date: Thu, 22 Jun 2023 05:14:24 -0400 Subject: [PATCH 5/5] chore: Added Hebrew version of Readme (#2340) * [Hebrew] - Added readme for Hebrew * [Hebrew] - Typo --- README.md | 2 +- docs/es-es/README-es-es.md | 2 +- docs/he/README-he.md | 171 +++++++++++++++++++++++++++++++++++++ docs/ja/README-ja.md | 2 +- docs/ko/README-ko.md | 2 +- docs/pt-br/README-pt-br.md | 2 +- docs/ru/README-ru.md | 2 +- docs/si/README-si.md | 2 +- docs/tr/README-tr.md | 4 +- 9 files changed, 180 insertions(+), 9 deletions(-) create mode 100644 docs/he/README-he.md diff --git a/README.md b/README.md index ca0443f1e..3a855a9c3 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -English | [简体中文](./docs/zh-cn/README.zh-CN.md) | [日本語](./docs/ja/README-ja.md) | [Português Brasileiro](./docs/pt-br/README-pt-br.md) | [한국어](./docs/ko/README-ko.md) | [Español (España)](./docs/es-es/README-es-es.md) | [Русский](./docs/ru/README-ru.md) | [Türkçe](./docs/tr/README-tr.md) | [සිංහල](./docs/si/README-si.md) +English | [简体中文](./docs/zh-cn/README.zh-CN.md) | [日本語](./docs/ja/README-ja.md) | [Português Brasileiro](./docs/pt-br/README-pt-br.md) | [한국어](./docs/ko/README-ko.md) | [Español (España)](./docs/es-es/README-es-es.md) | [Русский](./docs/ru/README-ru.md) | [Türkçe](./docs/tr/README-tr.md) | [සිංහල](./docs/si/README-si.md) | [עברית](./docs/he/README-he.md)

+ +עברית | [English](../../README.md) | [简体中文](./docs/zh-cn/README.zh-CN.md) | [日本語](./docs/ja/README-ja.md) | [Português Brasileiro](./docs/pt-br/README-pt-br.md) | [한국어](./docs/ko/README-ko.md) | [Español (España)](./docs/es-es/README-es-es.md) | [Русский](./docs/ru/README-ru.md) | [Türkçe](./docs/tr/README-tr.md) | [සිංහල](./docs/si/README-si.md) + +

Day.js

+

אלטרנטיבה מהירה ל-Moment.js ששוקלת רק 2kB עם אותן יכולות מודרניות

+

+ Gzip Size + NPM Version + Build Status + Codecov + License +
+ + Sauce Test Status + +

+ +> Day.js היא ספרייה מינימלסטית לפענוח, אימות, מניפולציה והצגה של תאריכים ושעות לדפדפנים מודרנים עם תאימות גבוהה ל-API של Moment.js. אם השתמשתם ב-Moment.js, אתם כבר יודעים את Day.js + +
+ +```js +dayjs().startOf('month').add(1, 'day').set('year', 2018).format('YYYY-MM-DD HH:mm:ss'); +``` + +
+ +* 🕒 תבניות ו-API זהים ל-Moment.js +* 💪 אינו ניתן לשינוי +* 🔥 ניתן לשרשור +* 🌐 תמיכה ב-I18n +* 📦 ספרייה קטנטנה 2kb +* 👫 נתמכת בכל הדפדפנים + +--- + +## צעדים ראשונים + +### דוקומנטצייה +באתר [day.js.org](https://day.js.org/) ניתן למצוא פרטים נוספים, API, ותיעודים נוספים. + + +### התקנה + +```console +npm install dayjs --save +``` + +📚[מדריך התקנה](https://day.js.org/docs/en/installation/installation) + +### API +מאוד קל להשתמש ב-Day.js לפענוח, אימות, מניפולציה והצגה של תאריכים ושעות. + +
+ + +```javascript +dayjs('2018-08-08') // פענוח + +dayjs().format('{YYYY} MM-DDTHH:mm:ss SSS [Z] A') // הצגה + +dayjs().set('month', 3).month() // קבלה והגדרה + +dayjs().add(1, 'year') // מניפולציה + +dayjs().isBefore(dayjs()) // שאילתה +``` + +
+ +📚[תיעודי API](https://day.js.org/docs/en/parse/parse) + +### I18n +ל-Day.js יש תמיכה מצוינית בבינלאומיות. + +אבל אף אחד מהם לא יכלל בקובץ הסופי אלא אם כן יתבצע בהם שימוש. + +
+ + +```javascript +import 'dayjs/locale/es' // טעינה לפי הצורך + +dayjs.locale('es') // הגדרה לשימוש בספרדית באופן גלובלאלי + +dayjs('2018-05-05').locale('zh-cn').format() // הגדרה לשימוש בסינית פשוטה למופע ספיציפי בלבד +``` + +
+ + +📚[בינלאומיות](https://day.js.org/docs/en/i18n/i18n) + +### תוסף + +תוסף הוא מודל בלתי-תלוי הניתן להוספה ל-Day.js להרחבה או להוספה של פונקציות. + + +
+ + +```javascript +import advancedFormat from 'dayjs/plugin/advancedFormat' // טעינה לפי הצורך + +dayjs.extend(advancedFormat) // שימוש בתוסף + +dayjs().format('Q Do k kk X x') // כעת יותר אפשרויות זמינות +``` + +
+ +📚[רשימת תוספים](https://day.js.org/docs/en/plugin/plugin) + +## ספונסרים +תמכו בפרויקט זה כדי להיות ספונסר. קבלו לוגו עם קישור לאתר שלכם שיופיע כאן. + + +[[תמיכה דרך Github](https://github.com/sponsors/iamkun/)] [[תמיכה דרך OpenCollective](https://opencollective.com/dayjs#sponsor)] + + + + +         + + + +         + + + +         + + + +         + +         + +         + +         + + +## תורמים + +פרויקט זה קיים הודות לכל האנשים שתמכו בו. + +תנו לנו 💖 כוכב 💖 כדי לתמוך בנו. תודה רבה. + +ותודה רבה לכל התומכים שלנו! 🙏 + + + + + +
+ + +## רישיון + +Day.js מורשה לשימוש עם [רישיון MIT](./LICENSE). + diff --git a/docs/ja/README-ja.md b/docs/ja/README-ja.md index b40ceeb4b..a708a03bb 100644 --- a/docs/ja/README-ja.md +++ b/docs/ja/README-ja.md @@ -1,4 +1,4 @@ -日本語 | [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) +日本語 | [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)