Skip to content

Commit

Permalink
Merge pull request iamkun#245 from iamkun/feature/iamkun
Browse files Browse the repository at this point in the history
add isDayjs API
  • Loading branch information
iamkun authored Jun 14, 2018
2 parents c2a487c + 182701f commit a29cbb4
Show file tree
Hide file tree
Showing 7 changed files with 61 additions and 6 deletions.
12 changes: 11 additions & 1 deletion docs/en/API-reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,10 @@ The `Dayjs` object is immutable, that is, all API operations that change the `Da
- [Is Before `.isBefore(compared: Dayjs)`](#is-before-isbeforecompared-dayjs)
- [Is Same `.isSame(compared: Dayjs)`](#is-same-issamecompared-dayjs)
- [Is After `.isAfter(compared: Dayjs)`](#is-after-isaftercompared-dayjs)
- [Is Leap Year `.isLeapYear()`](#is-leap-year-isleapyear)
- [Is a Dayjs `.isDayjs()`](#is-a-dayjs-isdayjscompared-any)
- [Plugin APIs](#plugin-apis)
- [RelativeTime](#relativetime)
- [IsLeapYear](#isleapyear)

## Parsing

Expand Down Expand Up @@ -378,6 +379,15 @@ Returns a `boolean` indicating whether the `Dayjs`'s date is after the other sup
dayjs().isAfter(dayjs()); // false
```

### Is a Dayjs `.isDayjs(compared: any)`

Returns a `boolean` indicating whether a variable is a dayjs object or not.

```js
dayjs.isDayjs(dayjs()); // true
dayjs.isDayjs(new Date()); // false
```

### Is Leap Year `.isLeapYear()`

**[DEPRECATED] in 1.7.0, use [`IsLeapYear plugin`](./Plugin.md#isleapyear) instead**
Expand Down
12 changes: 11 additions & 1 deletion docs/ja/API-reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,10 @@ Day.js は組み込みの `Date.prototype` を変更する代わりに `Dayjs`
* [Is Before](#is-before)
* [Is Same](#is-same)
* [Is After](#is-after)
* [Is Leap Year](#is-leap-year)
* [Is a Dayjs `.isDayjs()`](#is-a-dayjs-isdayjscompared-any)
* [Plugin APIs](#plugin-apis)
* [RelativeTime](#relativetime)
* [IsLeapYear](#isleapyear)

---

Expand Down Expand Up @@ -448,6 +449,15 @@ dayjs().isAfter(Dayjs);
dayjs().isAfter(dayjs()); // false
```

### Is a Dayjs `.isDayjs(compared: any)`

Returns a `boolean` indicating whether a variable is a dayjs object or not.

```js
dayjs.isDayjs(dayjs()); // true
dayjs.isDayjs(new Date()); // false
```

#### Is Leap Year

**[DEPRECATED] in 1.7.0, use [`IsLeapYear plugin`](./Plugin.md#isleapyear) instead**
Expand Down
12 changes: 11 additions & 1 deletion docs/ko/API-reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,10 @@ Day.js는 네이티브 `Date.prototype`을 수정하는 대신 `Dayjs` 오브젝
- [Is Before `.isBefore(compared: Dayjs)`](#is-before-isbeforecompared--dayjs)
- [Is Same `.isSame(compared: Dayjs)`](#is-same-issamecompared--dayjs)
- [Is After `.isAfter(compared: Dayjs)`](#is-after-isaftercompared--dayjs)
- [Is Leap Year `.isLeapYear()`](#is-leap-year-isleapyear)
- [Is a Dayjs `.isDayjs()`](#is-a-dayjs-isdayjscompared-any)
- [Plugin APIs](#plugin-apis)
- [RelativeTime](#relativetime)
- [IsLeapYear](#isleapyear)

## Parsing

Expand Down Expand Up @@ -378,6 +379,15 @@ dayjs().isSame(dayjs()); // true
dayjs().isAfter(dayjs()); // false
```

### Is a Dayjs `.isDayjs(compared: any)`

Returns a `boolean` indicating whether a variable is a dayjs object or not.

```js
dayjs.isDayjs(dayjs()); // true
dayjs.isDayjs(new Date()); // false
```

### Is Leap Year `.isLeapYear()`

**[DEPRECATED] in 1.7.0, use [`IsLeapYear plugin`](./Plugin.md#isleapyear) instead**
Expand Down
12 changes: 11 additions & 1 deletion docs/pt-br/API-reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,10 @@ Este objeto `Dayjs` é imutável, ou seja, todas as operações desta API irão
* [Antes](#antes)
* [Igual](#igual)
* [Depois](#depois)
* [Ano Bissexto](#ano-bissexto)
* [Is a Dayjs `.isDayjs()`](#is-a-dayjs-isdayjscompared-any)
* [Plugin APIs](#plugin-apis)
* [RelativeTime](#relativetime)
* [IsLeapYear](#isleapyear)

---
O Day.js sempre irá retornar um novo objeto `Dayjs` se nada for especificado.
Expand Down Expand Up @@ -426,6 +427,15 @@ dayjs().isAfter(Dayjs);
dayjs().isAfter(dayjs()); // false
```

### Is a Dayjs `.isDayjs(compared: any)`

Returns a `boolean` indicating whether a variable is a dayjs object or not.

```js
dayjs.isDayjs(dayjs()); // true
dayjs.isDayjs(new Date()); // false
```

#### Ano Bissexto

**[DEPRECATED] in 1.7.0, use [`IsLeapYear plugin`](./Plugin.md#isleapyear) instead**
Expand Down
15 changes: 13 additions & 2 deletions docs/zh-cn/API-reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,10 @@
* [是否之前](#是否之前)
* [是否相同](#是否相同)
* [是否之后](#是否之后)
* [是否闰年](#是否闰年)
* [是否是 Dayjs `.isDayjs()`](#是否是-dayjs-isdayjscompared-any)
* [插件 APIs](#plugin-apis)
* [相对时间](#relativetime)
* [是否是闰年](#是否是闰年)

---
如果没有特别说明,Day.js 的返回值都是新的 `Dayjs` 对象。
Expand Down Expand Up @@ -325,6 +326,16 @@ dayjs().isSame(dayjs()); // true
dayjs().isAfter(Dayjs);
dayjs().isAfter(dayjs()); // false
```

### 是否是 Dayjs `.isDayjs(compared: any)`

返回一个 `boolean` 验证传入值是否是一个 Dayjs 对象.

```js
dayjs.isDayjs(dayjs()); // true
dayjs.isDayjs(new Date()); // false
```

#### 是否闰年

**[已废弃] 将在 1.7.0 废弃, 使用 [`IsLeapYear 插件`](./Plugin.md#isleapyear) 代替**
Expand All @@ -345,7 +356,7 @@ dayjs('2000-01-01').isLeapYear(); // true

插件 [`RelativeTime`](./Plugin.md#relativetime)

### IsLeapYear
### 是否是闰年

`.isLeapYear` 获得是否闰年

Expand Down
2 changes: 2 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,4 +90,6 @@ declare namespace dayjs {
export function extend(plugin: PluginFunc, option?: ConfigType): Dayjs

export function locale(arg1: any, arg2?: any): void

export function isDayjs(d: any): d is Dayjs
}
2 changes: 2 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -445,6 +445,8 @@ dayjs.extend = (plugin, option) => {

dayjs.locale = parseLocale

dayjs.isDayjs = isDayjs

dayjs.en = Ls[L]

export default dayjs

0 comments on commit a29cbb4

Please sign in to comment.