Repository: iamkun/dayjs
Pull request #2383 (2023-07-21 11:47:46)

fix: fix isDayjs check logic
ref: https://github.com/moment/moment/blob/develop/src/lib/moment/constructor.js#L78

`isDayjs` should return `true` in different versions of dayjs.

codecov[bot]: ## [Codecov](https://app.codecov.io/gh/iamkun/dayjs/pull/2383?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=None) Report
> Merging [#2383](https://app.codecov.io/gh/iamkun/dayjs/pull/2383?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=None) (0759d6d) into [dev](https://app.codecov.io/gh/iamkun/dayjs/commit/061aa7ed6c31696974665fc9b11a74d30841ebed?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=None) (061aa7e) will **not change** coverage.
> The diff coverage is `100.00%`.

```diff
@@            Coverage Diff            @@
##               dev     #2383   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files          183       183           
  Lines         2198      2200    +2     
  Branches       593       594    +1     
=========================================
+ Hits          2198      2200    +2     
```


| [Impacted Files](https://app.codecov.io/gh/iamkun/dayjs/pull/2383?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=None) | Coverage Δ | |
|---|---|---|
| [src/index.js](https://app.codecov.io/gh/iamkun/dayjs/pull/2383?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=None#diff-c3JjL2luZGV4Lmpz) | `100.00% <100.00%> (ø)` | |



Patch:
diff --git a/docs/ja/README-ja.md b/docs/ja/README-ja.md
index a708a03..32f4663 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)| [עברית](./docs/he/README-he.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)| [עברית](../he/README-he.md)
 
 <p align="center"><a href="https://day.js.org/" target="_blank" rel="noopener noreferrer"><img width="550"
                                                                              src="https://user-images.githubusercontent.com/17680888/39081119-3057bbe2-456e-11e8-862c-646133ad4b43.png"
@@ -44,9 +44,9 @@ dayjs()
 
 ## はじめに
 
-### Documentation
+### ドキュメント
 
-You can find for more details, API, and other docs on [day.js.org](https://day.js.org/) website.
+詳細、API、その他のドキュメントについては、[day.js.org](https://day.js.org/) のウェブサイトを参照してください。
 
 ### インストール
 
diff --git a/src/index.js b/src/index.js
index 16c2e35..d26a401 100644
--- a/src/index.js
+++ b/src/index.js
@@ -6,7 +6,10 @@ let L = 'en' // global locale
 const Ls = {} // global loaded locale
 Ls[L] = en
 
-const isDayjs = d => d instanceof Dayjs // eslint-disable-line no-use-before-define
+const IS_DAYJS = '$isDayjsObject'
+
+// eslint-disable-next-line no-use-before-define
+const isDayjs = d => d instanceof Dayjs || !!(d && d[IS_DAYJS])
 
 const parseLocale = (preset, object, isLocal) => {
   let l
@@ -72,7 +75,7 @@ const parseDate = (cfg) => {
           || 1, d[4] || 0, d[5] || 0, d[6] || 0, ms))
       }
       return new Date(d[1], m, d[3]
-          || 1, d[4] || 0, d[5] || 0, d[6] || 0, ms)
+        || 1, d[4] || 0, d[5] || 0, d[6] || 0, ms)
     }
   }
 
@@ -83,6 +86,7 @@ class Dayjs {
   constructor(cfg) {
     this.$L = parseLocale(cfg.locale, null, true)
     this.parse(cfg) // for plugin
+    this[IS_DAYJS] = true
   }
 
   parse(cfg) {


Test patch:
diff --git a/test/constructor.test.js b/test/constructor.test.js
index b14b2fe..66cdbfc 100644
--- a/test/constructor.test.js
+++ b/test/constructor.test.js
@@ -13,6 +13,14 @@ it('supports instanceof dayjs', () => {
   expect(dayjs() instanceof dayjs).toBeTruthy()
 })
 
+it('$isDayjsObject', () => {
+  const mockOtherVersionDayjsObj = {
+    $isDayjsObject: true
+  }
+  expect(dayjs.isDayjs(mockOtherVersionDayjsObj)).toBeTruthy()
+})
+
 it('does not break isDayjs', () => {
   expect(dayjs.isDayjs(dayjs())).toBeTruthy()
+  expect(dayjs.isDayjs(new Date())).toBeFalsy()
 })