Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

query methods support Dayjs constructor args #211

Merged
merged 2 commits into from
May 31, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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