Skip to content

Commit ce2e30e

Browse files
naulacambraiamkun
authored andcommitted
fix: add deltaZone in the equation when calculating diff and added utcOffset api method (#453)
1 parent 3bd06f2 commit ce2e30e

File tree

5 files changed

+147
-105
lines changed

5 files changed

+147
-105
lines changed

docs/en/API-reference.md

+46-35
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ The `Dayjs` object is immutable, that is, all API operations that change the `Da
3636
- [Difference `.diff(compared: Dayjs, unit: string (default: 'milliseconds'), float?: boolean)`](#difference-diffcompared-dayjs-unit-string-default-milliseconds-float-boolean)
3737
- [Unix Timestamp (milliseconds) `.valueOf()`](#unix-timestamp-milliseconds-valueof)
3838
- [Unix Timestamp (seconds) `.unix()`](#unix-timestamp-seconds-unix)
39+
- [UTC offset (minutes) `.utcOffset()`](#utc-offset-minutes-utcoffset)
3940
- [Days in the Month `.daysInMonth()`](#days-in-the-month-daysinmonth)
4041
- [As Javascript Date `.toDate()`](#as-javascript-date-todate)
4142
- [As Array `.toArray()`](#as-array-toarray)
@@ -72,7 +73,7 @@ Day.js also parses other date formats.
7273
#### [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) string
7374

7475
```js
75-
dayjs('2018-04-04T16:00:00.000Z');
76+
dayjs("2018-04-04T16:00:00.000Z");
7677
```
7778

7879
#### Native Javascript Date object
@@ -99,15 +100,16 @@ dayjs.unix(1318781876.721);
99100
```
100101

101102
### Custom Parse Format
102-
* parse custom formats `dayjs("12-25-1995", "MM-DD-YYYY")` in plugin [`CustomParseFormat`](./Plugin.md#customparseformat)
103+
104+
- parse custom formats `dayjs("12-25-1995", "MM-DD-YYYY")` in plugin [`CustomParseFormat`](./Plugin.md#customparseformat)
103105

104106
### Clone `.clone() | dayjs(original: Dayjs)`
105107

106108
Returns a cloned `Dayjs`.
107109

108110
```js
109111
dayjs().clone();
110-
dayjs(dayjs('2019-01-25')); // passing a Dayjs object to a constructor will also clone it
112+
dayjs(dayjs("2019-01-25")); // passing a Dayjs object to a constructor will also clone it
111113
```
112114

113115
### Validation `.isValid()`
@@ -189,9 +191,9 @@ dayjs().millisecond();
189191
Returns a `Dayjs` with the applied changes.
190192

191193
```js
192-
dayjs().set('date', 1);
193-
dayjs().set('month', 3); // April
194-
dayjs().set('second', 30);
194+
dayjs().set("date", 1);
195+
dayjs().set("month", 3); // April
196+
dayjs().set("second", 30);
195197
```
196198

197199
#### List of all available units
@@ -212,41 +214,42 @@ dayjs().set('second', 30);
212214
`Dayjs` objects can be manipulated in many ways.
213215

214216
```js
215-
dayjs('2019-01-25')
216-
.add(1, 'day')
217-
.subtract(1, 'year').toString(); // Fri, 26 Jan 2018 00:00:00 GMT
217+
dayjs("2019-01-25")
218+
.add(1, "day")
219+
.subtract(1, "year")
220+
.toString(); // Fri, 26 Jan 2018 00:00:00 GMT
218221
```
219222

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

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

224227
```js
225-
dayjs().add(7, 'day');
228+
dayjs().add(7, "day");
226229
```
227230

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

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

232235
```js
233-
dayjs().subtract(7, 'year');
236+
dayjs().subtract(7, "year");
234237
```
235238

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

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

240243
```js
241-
dayjs().startOf('week');
244+
dayjs().startOf("week");
242245
```
243246

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

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

248251
```js
249-
dayjs().endOf('month');
252+
dayjs().endOf("month");
250253
```
251254

252255
## Displaying
@@ -259,9 +262,9 @@ To escape characters, wrap them in square or curly brackets (e.g. `[G] {um}`).
259262
```js
260263
dayjs().format(); // current date in ISO6801, without fraction seconds e.g. '2020-04-02T08:02:17-05:00'
261264

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

264-
dayjs('2019-01-25').format('DD/MM/YYYY'); // '25/01/2019'
267+
dayjs("2019-01-25").format("DD/MM/YYYY"); // '25/01/2019'
265268
```
266269

267270
#### List of all available formats
@@ -294,84 +297,92 @@ dayjs('2019-01-25').format('DD/MM/YYYY'); // '25/01/2019'
294297
| `A` | AM PM | |
295298
| `a` | am pm | |
296299

297-
* More available formats `Q Do k kk X x ...` in plugin [`AdvancedFormat`](./Plugin.md#advancedformat)
298-
* Localized format options `L LT LTS ...` in plugin [`LocalizedFormat`](./Plugin.md#localizedFormat)
300+
- More available formats `Q Do k kk X x ...` in plugin [`AdvancedFormat`](./Plugin.md#advancedformat)
301+
- Localized format options `L LT LTS ...` in plugin [`LocalizedFormat`](./Plugin.md#localizedFormat)
299302

300303
### Difference `.diff(compared: Dayjs, unit: string (default: 'milliseconds'), float?: boolean)`
301304

302305
Returns a `number` indicating the difference of two `Dayjs`s in the specified unit.
303306

304307
```js
305-
const date1 = dayjs('2019-01-25');
306-
const date2 = dayjs('2018-06-05');
308+
const date1 = dayjs("2019-01-25");
309+
const date2 = dayjs("2018-06-05");
307310
date1.diff(date2); // 20214000000
308-
date1.diff(date2, 'month'); // 7
309-
date1.diff(date2, 'month', true); // 7.645161290322581
310-
date1.diff(date2, 'day'); // 233
311+
date1.diff(date2, "month"); // 7
312+
date1.diff(date2, "month", true); // 7.645161290322581
313+
date1.diff(date2, "day"); // 233
311314
```
312315

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

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

317320
```js
318-
dayjs('2019-01-25').valueOf(); // 1548381600000
321+
dayjs("2019-01-25").valueOf(); // 1548381600000
319322
```
320323

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

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

325328
```js
326-
dayjs('2019-01-25').unix(); // 1548381600
329+
dayjs("2019-01-25").unix(); // 1548381600
330+
```
331+
332+
### UTC Offset (minutes) `.utcOffset()`
333+
334+
Returns the UTC offset in minutes for the `Dayjs`.
335+
336+
```js
337+
dayjs("2013-03-07T07:00:00+08:00").utcOffset(); // 60
327338
```
328339

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

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

333344
```js
334-
dayjs('2019-01-25').daysInMonth(); // 31
345+
dayjs("2019-01-25").daysInMonth(); // 31
335346
```
336347

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

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

341352
```js
342-
dayjs('2019-01-25').toDate();
353+
dayjs("2019-01-25").toDate();
343354
```
344355

345356
### As Array `.toArray()`
346357

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

349360
```js
350-
dayjs('2019-01-25').toArray(); // [ 2019, 0, 25, 0, 0, 0, 0 ]
361+
dayjs("2019-01-25").toArray(); // [ 2019, 0, 25, 0, 0, 0, 0 ]
351362
```
352363

353364
### As JSON `.toJSON()`
354365

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

357368
```js
358-
dayjs('2019-01-25').toJSON(); // '2019-01-25T02:00:00.000Z'
369+
dayjs("2019-01-25").toJSON(); // '2019-01-25T02:00:00.000Z'
359370
```
360371

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

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

365376
```js
366-
dayjs('2019-01-25').toISOString(); // '2019-01-25T02:00:00.000Z'
377+
dayjs("2019-01-25").toISOString(); // '2019-01-25T02:00:00.000Z'
367378
```
368379

369380
### As Object `.toObject()`
370381

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

373384
```js
374-
dayjs('2019-01-25').toObject();
385+
dayjs("2019-01-25").toObject();
375386
/* { years: 2019,
376387
months: 0,
377388
date: 25,
@@ -386,7 +397,7 @@ dayjs('2019-01-25').toObject();
386397
Returns a `string` representation of the date.
387398

388399
```js
389-
dayjs('2019-01-25').toString(); // 'Fri, 25 Jan 2019 02:00:00 GMT'
400+
dayjs("2019-01-25").toString(); // 'Fri, 25 Jan 2019 02:00:00 GMT'
390401
```
391402

392403
## Query
@@ -397,7 +408,7 @@ Returns a `boolean` indicating whether the `Dayjs`'s date is before the other su
397408

398409
```js
399410
dayjs().isBefore(dayjs()); // false
400-
dayjs().isBefore(dayjs(), 'year'); // false
411+
dayjs().isBefore(dayjs(), "year"); // false
401412
```
402413

403414
### Is Same `.isSame(compared: Dayjs, unit?: string)`
@@ -406,7 +417,7 @@ Returns a `boolean` indicating whether the `Dayjs`'s date is the same as the oth
406417

407418
```js
408419
dayjs().isSame(dayjs()); // true
409-
dayjs().isSame(dayjs(), 'year'); // true
420+
dayjs().isSame(dayjs(), "year"); // true
410421
```
411422

412423
### Is After `.isAfter(compared: Dayjs, unit?: string)`
@@ -415,7 +426,7 @@ Returns a `boolean` indicating whether the `Dayjs`'s date is after the other sup
415426

416427
```js
417428
dayjs().isAfter(dayjs()); // false
418-
dayjs().isAfter(dayjs(), 'year'); // false
429+
dayjs().isAfter(dayjs(), "year"); // false
419430
```
420431

421432
### Is a Dayjs `.isDayjs(compared: any)`
@@ -430,7 +441,7 @@ dayjs.isDayjs(new Date()); // false
430441
The operator `instanceof` works equally well:
431442

432443
```js
433-
dayjs() instanceof dayjs // true
444+
dayjs() instanceof dayjs; // true
434445
```
435446

436447
## Plugin APIs

0 commit comments

Comments
 (0)