Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: iamkun/dayjs
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v1.8.24
Choose a base ref
...
head repository: iamkun/dayjs
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v1.8.25
Choose a head ref
  • 7 commits
  • 9 files changed
  • 3 contributors

Commits on Apr 15, 2020

  1. fixed incorrect definition of locale in typescript

    the first parameter of locale is optional so that locale() can be called with no arguments to return the current locale.
    I would have added a test case to prove this works, but everything is in javascript and I expect you would not appreciate adding typescript to the unit tests.
    Greg Veres committed Apr 15, 2020
    Copy the full SHA
    9dfcb07 View commit details

Commits on Apr 16, 2020

  1. Copy the full SHA
    9790b85 View commit details

Commits on Apr 17, 2020

  1. Copy the full SHA
    62b092d View commit details
  2. Copy the full SHA
    3cea04d View commit details
  3. Copy the full SHA
    4141084 View commit details

Commits on Apr 21, 2020

  1. Merge pull request #877 from iamkun/dev

    D2M
    iamkun authored Apr 21, 2020
    Copy the full SHA
    9dbe5b0 View commit details
  2. chore(release): 1.8.25 [skip ci]

    ## [1.8.25](v1.8.24...v1.8.25) (2020-04-21)
    
    ### Bug Fixes
    
    * Fix CustomParseFormat plugin of parsing only YYYY / YYYY-MM bug ([#873](#873)) ([3cea04d](3cea04d)), closes [#849](#849)
    * Fix Duration plugin get seconds ([#867](#867)) ([62b092d](62b092d))
    * Fix type definition of locale ([9790b85](9790b85))
    * Fix UTC plugin startOf, endOf bug ([#872](#872)) ([4141084](4141084)), closes [#809](#809) [#808](#808)
    semantic-release-bot committed Apr 21, 2020
    Copy the full SHA
    bcea067 View commit details
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
## [1.8.25](https://github.com/iamkun/dayjs/compare/v1.8.24...v1.8.25) (2020-04-21)


### Bug Fixes

* Fix CustomParseFormat plugin of parsing only YYYY / YYYY-MM bug ([#873](https://github.com/iamkun/dayjs/issues/873)) ([3cea04d](https://github.com/iamkun/dayjs/commit/3cea04d33d54d44bbdd3d026b5c7f67ebf176116)), closes [#849](https://github.com/iamkun/dayjs/issues/849)
* Fix Duration plugin get seconds ([#867](https://github.com/iamkun/dayjs/issues/867)) ([62b092d](https://github.com/iamkun/dayjs/commit/62b092d9f9a3db5506ef01f798bdf211f163f53f))
* Fix type definition of locale ([9790b85](https://github.com/iamkun/dayjs/commit/9790b853e6113243a7f4a81dd12c6509e406a102))
* Fix UTC plugin startOf, endOf bug ([#872](https://github.com/iamkun/dayjs/issues/872)) ([4141084](https://github.com/iamkun/dayjs/commit/4141084ba96d35cadcda3f1e661bf1d0f6c8e4de)), closes [#809](https://github.com/iamkun/dayjs/issues/809) [#808](https://github.com/iamkun/dayjs/issues/808)

## [1.8.24](https://github.com/iamkun/dayjs/compare/v1.8.23...v1.8.24) (2020-04-10)


2 changes: 1 addition & 1 deletion src/index.js
Original file line number Diff line number Diff line change
@@ -172,7 +172,7 @@ class Dayjs {
const argumentStart = [0, 0, 0, 0]
const argumentEnd = [23, 59, 59, 999]
return Utils.w(this.toDate()[method].apply( // eslint-disable-line prefer-spread
this.toDate(),
this.toDate('s'),
(isStartOf ? argumentStart : argumentEnd).slice(slice)
), this)
}
15 changes: 7 additions & 8 deletions src/plugin/customParseFormat/index.js
Original file line number Diff line number Diff line change
@@ -151,21 +151,20 @@ const parseFormattedInput = (input, format, utc) => {
const {
year, month, day, hours, minutes, seconds, milliseconds, zone
} = parser(input)
if (zone) {
return new Date(Date.UTC(
year, month - 1, day,
hours || 0,
minutes || 0, seconds || 0, milliseconds || 0
) + (zone.offset * 60 * 1000))
}
const now = new Date()
const d = day || ((!year && !month) ? now.getDate() : 1)
const y = year || now.getFullYear()
const M = month > 0 ? month - 1 : now.getMonth()
let M = 0
if (!(year && !month)) {
M = month > 0 ? month - 1 : now.getMonth()
}
const h = hours || 0
const m = minutes || 0
const s = seconds || 0
const ms = milliseconds || 0
if (zone) {
return new Date(Date.UTC(y, M, d, h, m, s, ms + (zone.offset * 60 * 1000)))
}
if (utc) {
return new Date(Date.UTC(y, M, d, h, m, s, ms))
}
8 changes: 6 additions & 2 deletions src/plugin/duration/index.js
Original file line number Diff line number Diff line change
@@ -75,7 +75,9 @@ class Duration {
$ms %= MILLISECONDS_A_HOUR
this.$d.minutes = Math.floor($ms / MILLISECONDS_A_MINUTE)
$ms %= MILLISECONDS_A_MINUTE
this.$d.seconds = $ms / MILLISECONDS_A_SECOND
this.$d.seconds = Math.floor($ms / MILLISECONDS_A_SECOND)
$ms %= MILLISECONDS_A_SECOND
this.$d.milliseconds = $ms
}

toISOString() {
@@ -111,8 +113,10 @@ class Duration {
const pUnit = prettyUnit(unit)
if (pUnit === 'milliseconds') {
base %= 1000
} else {
} else if (pUnit === 'weeks') {
base = Math.floor(base / unitToMS[pUnit])
} else {
base = this.$d[pUnit]
}
return base
}
8 changes: 8 additions & 0 deletions src/plugin/utc/index.js
Original file line number Diff line number Diff line change
@@ -91,4 +91,12 @@ export default (option, Dayjs, dayjs) => {
proto.toString = function () {
return this.toDate().toUTCString()
}

const oldToDate = proto.toDate
proto.toDate = function (type) {
if (type === 's' && this.$offset) {
return dayjs(this.format('YYYY-MM-DD HH:mm:ss:SSS')).toDate()
}
return oldToDate.call(this)
}
}
19 changes: 19 additions & 0 deletions test/plugin/customParseFormat.test.js
Original file line number Diff line number Diff line change
@@ -98,6 +98,25 @@ it('parse HH:mm:ss but only one digit', () => {
expect(dayjs(input, format).valueOf()).toBe(moment(input, format).valueOf())
})

describe('parse YYYY / YYYY-MM only', () => {
it('YYYY', () => {
const input = '2001 +08:00'
const format = 'YYYY Z'
expect(dayjs(input, format).valueOf()).toBe(moment(input, format).valueOf())
const input2 = '2001'
const format2 = 'YYYY'
expect(dayjs(input2, format2).valueOf()).toBe(moment(input2, format2).valueOf())
})
it('YYYY-MM', () => {
const input = '2001-01 +08:00'
const format = 'YYYY-MM Z'
expect(dayjs(input, format).valueOf()).toBe(moment(input, format).valueOf())
const input2 = '2001-01'
const format2 = 'YYYY-MM'
expect(dayjs(input2, format2).valueOf()).toBe(moment(input2, format2).valueOf())
})
})

it('parse hh:mm:ss but only one digit', () => {
const input = '0:0:1'
const format = 'hh:mm:ss'
2 changes: 2 additions & 0 deletions test/plugin/duration.test.js
Original file line number Diff line number Diff line change
@@ -134,13 +134,15 @@ describe('Seconds', () => {
expect(dayjs.duration(500).seconds()).toBe(0)
expect(dayjs.duration(1500).seconds()).toBe(1)
expect(dayjs.duration(15000).seconds()).toBe(15)
expect(dayjs.duration(61000).seconds()).toBe(1) // 1 minute 1 second
expect(dayjs.duration(500).asSeconds()).toBe(0.5)
expect(dayjs.duration(1500).asSeconds()).toBe(1.5)
expect(dayjs.duration(15000).asSeconds()).toBe(15)
})

describe('Minutes', () => {
expect(dayjs.duration(100000).minutes()).toBe(1)
expect(dayjs.duration(61000).minutes()).toBe(1) // 1 minute 1 second
expect(dayjs.duration(100000).asMinutes().toFixed(2)).toBe('1.67')
})

7 changes: 7 additions & 0 deletions test/plugin/utc-utcOffset.test.js
Original file line number Diff line number Diff line change
@@ -100,4 +100,11 @@ test('utc startOf', () => {
.valueOf())
.toBe(dayjs(d).utc().utcOffset(480).endOf('day')
.valueOf())
const d2 = '2017-07-20T11:00:00+00:00'
const d2d = dayjs(d2).utcOffset(-12).startOf('day').valueOf()
const d2m = moment(d2).utcOffset(-12).startOf('day').valueOf()
expect(d2d)
.toBe(d2m)
expect(d2d)
.toBe(1500465600000)
})
2 changes: 1 addition & 1 deletion types/index.d.ts
Original file line number Diff line number Diff line change
@@ -100,7 +100,7 @@ declare namespace dayjs {

export function extend<T = unknown>(plugin: PluginFunc<T>, option?: T): Dayjs

export function locale(preset: string | ILocale, object?: Partial<ILocale>, isLocal?: boolean): string
export function locale(preset?: string | ILocale, object?: Partial<ILocale>, isLocal?: boolean): string

export function isDayjs(d: any): d is Dayjs