Skip to content

Commit

Permalink
Merge pull request #211 from huihuimoe/master
Browse files Browse the repository at this point in the history
query methods support Dayjs constructor args
  • Loading branch information
iamkun committed May 31, 2018
2 parents 6ef7d98 + ad46ef9 commit cebc757
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,14 @@ const dayjs = (date, c) => {
return new Dayjs(cfg) // eslint-disable-line no-use-before-define
}

const toDayjs = input => (isDayjs(input) ? input : dayjs(input.valueOf()))

const wrapper = (date, instance) => dayjs(date, { locale: instance.$L })

const Utils = U // for plugin use
Utils.parseLocale = parseLocale
Utils.isDayjs = isDayjs
Utils.toDayjs = toDayjs
Utils.wrapper = wrapper

const parseDate = (date) => {
Expand Down Expand Up @@ -96,16 +99,16 @@ class Dayjs {
return ((this.$y % 4 === 0) && (this.$y % 100 !== 0)) || (this.$y % 400 === 0)
}

isSame(that) {
return this.valueOf() === that.valueOf()
isSame(input) {
return this.valueOf() === toDayjs(input).valueOf()
}

isBefore(that) {
return this.valueOf() < that.valueOf()
isBefore(input) {
return this.valueOf() < toDayjs(input).valueOf()
}

isAfter(that) {
return this.valueOf() > that.valueOf()
isAfter(input) {
return this.valueOf() > toDayjs(input).valueOf()
}

year() {
Expand Down Expand Up @@ -336,7 +339,7 @@ class Dayjs {

diff(input, units, float) {
const unit = Utils.prettyUnit(units)
const that = isDayjs(input) ? input : dayjs(input.valueOf())
const that = toDayjs(input)
const diff = this - that
let result = Utils.monthDiff(this, that)
switch (unit) {
Expand Down

0 comments on commit cebc757

Please sign in to comment.