Skip to content

Commit

Permalink
docs: prettier docs
Browse files Browse the repository at this point in the history
  • Loading branch information
iamkun committed Feb 14, 2019
1 parent 0477f8c commit 8ede9b7
Show file tree
Hide file tree
Showing 29 changed files with 1,368 additions and 1,097 deletions.
112 changes: 56 additions & 56 deletions docs/en/API-reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,38 +65,38 @@ The `Dayjs` object is immutable, that is, all API operations that change the `Da
Calling it without parameters returns a fresh `Dayjs` object with the current date and time.

```js
dayjs();
dayjs()
```

Day.js also parses other date formats.

#### [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) string

```js
dayjs("2018-04-04T16:00:00.000Z");
dayjs('2018-04-04T16:00:00.000Z')
```

#### Native Javascript Date object

```js
dayjs(new Date(2018, 8, 18));
dayjs(new Date(2018, 8, 18))
```

#### Unix Timestamp (milliseconds)

Returns a `Dayjs` from a Unix timestamp (milliseconds since the Unix Epoch)

```js
dayjs(1318781876406);
dayjs(1318781876406)
```

### Unix Timestamp (seconds) `.unix(value: number)`

Returns a `Dayjs` from a Unix timestamp (seconds since the Unix Epoch)

```js
dayjs.unix(1318781876);
dayjs.unix(1318781876.721);
dayjs.unix(1318781876)
dayjs.unix(1318781876.721)
```

### Custom Parse Format
Expand All @@ -108,16 +108,16 @@ dayjs.unix(1318781876.721);
Returns a cloned `Dayjs`.

```js
dayjs().clone();
dayjs(dayjs("2019-01-25")); // passing a Dayjs object to a constructor will also clone it
dayjs().clone()
dayjs(dayjs('2019-01-25')) // passing a Dayjs object to a constructor will also clone it
```

### Validation `.isValid()`

Returns a `boolean` indicating whether the `Dayjs`'s date is valid.

```js
dayjs().isValid();
dayjs().isValid()
```

## Get and Set
Expand All @@ -127,73 +127,73 @@ dayjs().isValid();
Returns a `number` representing the `Dayjs`'s year.

```js
dayjs().year();
dayjs().year()
```

### Month `.month()`

Returns a `number` representing the `Dayjs`'s month. Starts at 0

```js
dayjs().month();
dayjs().month()
```

### Day of the Month `.date()`

Returns a `number` representing the `Dayjs`'s day of the month. Starts at 1

```js
dayjs().date();
dayjs().date()
```

### Day of the Week `.day()`

Returns a `number` representing the `Dayjs`'s day of the week. Starts on Sunday with 0

```js
dayjs().day();
dayjs().day()
```

### Hour `.hour()`

Returns a `number` representing the `Dayjs`'s hour.

```js
dayjs().hour();
dayjs().hour()
```

### Minute `.minute()`

Returns a `number` representing the `Dayjs`'s minute.

```js
dayjs().minute();
dayjs().minute()
```

### Second `.second()`

Returns a `number` representing the `Dayjs`'s second.

```js
dayjs().second();
dayjs().second()
```

### Millisecond `.millisecond()`

Returns a `number` representing the `Dayjs`'s millisecond.

```js
dayjs().millisecond();
dayjs().millisecond()
```

### Set `.set(unit: string, value: number)`

Returns a `Dayjs` with the applied changes.

```js
dayjs().set("date", 1);
dayjs().set("month", 3); // April
dayjs().set("second", 30);
dayjs().set('date', 1)
dayjs().set('month', 3) // April
dayjs().set('second', 30)
```

#### List of all available units
Expand All @@ -214,42 +214,42 @@ dayjs().set("second", 30);
`Dayjs` objects can be manipulated in many ways.

```js
dayjs("2019-01-25")
.add(1, "day")
.subtract(1, "year")
.toString(); // Fri, 26 Jan 2018 00:00:00 GMT
dayjs('2019-01-25')
.add(1, 'day')
.subtract(1, 'year')
.toString() // Fri, 26 Jan 2018 00:00:00 GMT
```

### Add `.add(value: number, unit: string)`

Returns a cloned `Dayjs` with a specified amount of time added.

```js
dayjs().add(7, "day");
dayjs().add(7, 'day')
```

### Subtract `.subtract(value: number, unit: string)`

Returns a cloned `Dayjs` with a specified amount of time subtracted.

```js
dayjs().subtract(7, "year");
dayjs().subtract(7, 'year')
```

### Start of Time `.startOf(unit: string)`

Returns a cloned `Dayjs` set to the start of the specified unit of time.

```js
dayjs().startOf("week"); // Depends on `weekStart` in locale
dayjs().startOf('week') // Depends on `weekStart` in locale
```

### End of Time `.endOf(unit: string)`

Returns a cloned `Dayjs` set to the end of the specified unit of time.

```js
dayjs().endOf("month");
dayjs().endOf('month')
```

## Displaying
Expand All @@ -260,11 +260,11 @@ Returns a `string` with the `Dayjs`'s formatted date.
To escape characters, wrap them in square or curly brackets (e.g. `[G] {um}`).

```js
dayjs().format(); // current date in ISO6801, without fraction seconds e.g. '2020-04-02T08:02:17-05:00'
dayjs().format() // current date in ISO6801, without fraction seconds e.g. '2020-04-02T08:02:17-05:00'

dayjs("2019-01-25").format("{YYYY} MM-DDTHH:mm:ssZ[Z]"); // '{2019} 01-25T00:00:00-02:00Z'
dayjs('2019-01-25').format('{YYYY} MM-DDTHH:mm:ssZ[Z]') // '{2019} 01-25T00:00:00-02:00Z'

dayjs("2019-01-25").format("DD/MM/YYYY"); // '25/01/2019'
dayjs('2019-01-25').format('DD/MM/YYYY') // '25/01/2019'
```

#### List of all available formats
Expand Down Expand Up @@ -305,84 +305,84 @@ dayjs("2019-01-25").format("DD/MM/YYYY"); // '25/01/2019'
Returns a `number` indicating the difference of two `Dayjs`s in the specified unit.

```js
const date1 = dayjs("2019-01-25");
const date2 = dayjs("2018-06-05");
date1.diff(date2); // 20214000000
date1.diff(date2, "month"); // 7
date1.diff(date2, "month", true); // 7.645161290322581
date1.diff(date2, "day"); // 233
const date1 = dayjs('2019-01-25')
const date2 = dayjs('2018-06-05')
date1.diff(date2) // 20214000000
date1.diff(date2, 'month') // 7
date1.diff(date2, 'month', true) // 7.645161290322581
date1.diff(date2, 'day') // 233
```

### Unix Timestamp (milliseconds) `.valueOf()`

Returns the `number` of milliseconds since the Unix Epoch for the `Dayjs`.

```js
dayjs("2019-01-25").valueOf(); // 1548381600000
dayjs('2019-01-25').valueOf() // 1548381600000
```

### Unix Timestamp (seconds) `.unix()`

Returns the `number` of seconds since the Unix Epoch for the `Dayjs`.

```js
dayjs("2019-01-25").unix(); // 1548381600
dayjs('2019-01-25').unix() // 1548381600
```

### UTC Offset (minutes) `.utcOffset()`

Returns the UTC offset in minutes for the `Dayjs`.

```js
dayjs().utcOffset();
dayjs().utcOffset()
```

### Days in the Month `.daysInMonth()`

Returns the `number` of days in the `Dayjs`'s month.

```js
dayjs("2019-01-25").daysInMonth(); // 31
dayjs('2019-01-25').daysInMonth() // 31
```

### As Javascript Date `.toDate()`

Returns a copy of the native `Date` object parsed from the `Dayjs` object.

```js
dayjs("2019-01-25").toDate();
dayjs('2019-01-25').toDate()
```

### As Array `.toArray()`

Returns an `array` that mirrors the parameters from new Date().

```js
dayjs("2019-01-25").toArray(); // [ 2019, 0, 25, 0, 0, 0, 0 ]
dayjs('2019-01-25').toArray() // [ 2019, 0, 25, 0, 0, 0, 0 ]
```

### As JSON `.toJSON()`

Returns the `Dayjs` formatted in an ISO8601 `string`.

```js
dayjs("2019-01-25").toJSON(); // '2019-01-25T02:00:00.000Z'
dayjs('2019-01-25').toJSON() // '2019-01-25T02:00:00.000Z'
```

### As ISO 8601 String `.toISOString()`

Returns the `Dayjs` formatted in an ISO8601 `string`.

```js
dayjs("2019-01-25").toISOString(); // '2019-01-25T02:00:00.000Z'
dayjs('2019-01-25').toISOString() // '2019-01-25T02:00:00.000Z'
```

### As Object `.toObject()`

Returns an `object` with the date's properties.

```js
dayjs("2019-01-25").toObject();
dayjs('2019-01-25').toObject()
/* { years: 2019,
months: 0,
date: 25,
Expand All @@ -397,7 +397,7 @@ dayjs("2019-01-25").toObject();
Returns a `string` representation of the date.

```js
dayjs("2019-01-25").toString(); // 'Fri, 25 Jan 2019 02:00:00 GMT'
dayjs('2019-01-25').toString() // 'Fri, 25 Jan 2019 02:00:00 GMT'
```

## Query
Expand All @@ -407,41 +407,41 @@ dayjs("2019-01-25").toString(); // 'Fri, 25 Jan 2019 02:00:00 GMT'
Returns a `boolean` indicating whether the `Dayjs`'s date is before the other supplied `Dayjs`'s.

```js
dayjs().isBefore(dayjs()); // false
dayjs().isBefore(dayjs(), "year"); // false
dayjs().isBefore(dayjs()) // false
dayjs().isBefore(dayjs(), 'year') // false
```

### Is Same `.isSame(compared: Dayjs, unit?: string)`

Returns a `boolean` indicating whether the `Dayjs`'s date is the same as the other supplied `Dayjs`'s.

```js
dayjs().isSame(dayjs()); // true
dayjs().isSame(dayjs(), "year"); // true
dayjs().isSame(dayjs()) // true
dayjs().isSame(dayjs(), 'year') // true
```

### Is After `.isAfter(compared: Dayjs, unit?: string)`

Returns a `boolean` indicating whether the `Dayjs`'s date is after the other supplied `Dayjs`'s.

```js
dayjs().isAfter(dayjs()); // false
dayjs().isAfter(dayjs(), "year"); // false
dayjs().isAfter(dayjs()) // false
dayjs().isAfter(dayjs(), 'year') // 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
dayjs.isDayjs(dayjs()) // true
dayjs.isDayjs(new Date()) // false
```

The operator `instanceof` works equally well:

```js
dayjs() instanceof dayjs; // true
dayjs() instanceof dayjs // true
```

## Plugin APIs
Expand Down
Loading

0 comments on commit 8ede9b7

Please sign in to comment.