@date-io/date-fns
Advanced tools
Comparing version 2.8.1 to 2.9.1
@@ -1,2 +0,2 @@ | ||
import { IUtils, DateIOFormats } from "@date-io/core/IUtils"; | ||
import { IUtils, DateIOFormats, Unit } from "@date-io/core/IUtils"; | ||
import defaultLocale from "date-fns/locale/en-US"; | ||
@@ -18,3 +18,3 @@ declare type Locale = typeof defaultLocale; | ||
isValid(value: any): boolean; | ||
getDiff(value: Date, comparing: Date | string): number; | ||
getDiff(value: Date, comparing: Date | string, unit?: Unit): number; | ||
isAfter(value: Date, comparing: Date): boolean; | ||
@@ -54,2 +54,3 @@ isBefore(value: Date, comparing: Date): boolean; | ||
getMonth(date: Date): number; | ||
getDaysInMonth(date: Date): number; | ||
setMonth(date: Date, count: number): Date; | ||
@@ -56,0 +57,0 @@ getMeridiemText(ampm: "am" | "pm"): "AM" | "PM"; |
import addDays from 'date-fns/addDays'; | ||
import addMonths from 'date-fns/addMonths'; | ||
import addYears from 'date-fns/addYears'; | ||
import differenceInYears from 'date-fns/differenceInYears'; | ||
import differenceInQuarters from 'date-fns/differenceInQuarters'; | ||
import differenceInMonths from 'date-fns/differenceInMonths'; | ||
import differenceInWeeks from 'date-fns/differenceInWeeks'; | ||
import differenceInDays from 'date-fns/differenceInDays'; | ||
import differenceInHours from 'date-fns/differenceInHours'; | ||
import differenceInMinutes from 'date-fns/differenceInMinutes'; | ||
import differenceInSeconds from 'date-fns/differenceInSeconds'; | ||
import differenceInMilliseconds from 'date-fns/differenceInMilliseconds'; | ||
@@ -25,2 +33,3 @@ import eachDayOfInterval from 'date-fns/eachDayOfInterval'; | ||
import setMonth from 'date-fns/setMonth'; | ||
import getDaysInMonth from 'date-fns/getDaysInMonth'; | ||
import setSeconds from 'date-fns/setSeconds'; | ||
@@ -113,4 +122,24 @@ import setYear from 'date-fns/setYear'; | ||
}; | ||
DateFnsUtils.prototype.getDiff = function (value, comparing) { | ||
return differenceInMilliseconds(value, this.date(comparing)); | ||
DateFnsUtils.prototype.getDiff = function (value, comparing, unit) { | ||
switch (unit) { | ||
case "years": | ||
return differenceInYears(value, this.date(comparing)); | ||
case "quarters": | ||
return differenceInQuarters(value, this.date(comparing)); | ||
case "months": | ||
return differenceInMonths(value, this.date(comparing)); | ||
case "weeks": | ||
return differenceInWeeks(value, this.date(comparing)); | ||
case "days": | ||
return differenceInDays(value, this.date(comparing)); | ||
case "hours": | ||
return differenceInHours(value, this.date(comparing)); | ||
case "minutes": | ||
return differenceInMinutes(value, this.date(comparing)); | ||
case "seconds": | ||
return differenceInSeconds(value, this.date(comparing)); | ||
default: { | ||
return differenceInMilliseconds(value, this.date(comparing)); | ||
} | ||
} | ||
}; | ||
@@ -232,2 +261,5 @@ DateFnsUtils.prototype.isAfter = function (value, comparing) { | ||
}; | ||
DateFnsUtils.prototype.getDaysInMonth = function (date) { | ||
return getDaysInMonth(date); | ||
}; | ||
DateFnsUtils.prototype.setMonth = function (date, count) { | ||
@@ -234,0 +266,0 @@ return setMonth(date, count); |
@@ -6,2 +6,10 @@ 'use strict'; | ||
var addYears = require('date-fns/addYears'); | ||
var differenceInYears = require('date-fns/differenceInYears'); | ||
var differenceInQuarters = require('date-fns/differenceInQuarters'); | ||
var differenceInMonths = require('date-fns/differenceInMonths'); | ||
var differenceInWeeks = require('date-fns/differenceInWeeks'); | ||
var differenceInDays = require('date-fns/differenceInDays'); | ||
var differenceInHours = require('date-fns/differenceInHours'); | ||
var differenceInMinutes = require('date-fns/differenceInMinutes'); | ||
var differenceInSeconds = require('date-fns/differenceInSeconds'); | ||
var differenceInMilliseconds = require('date-fns/differenceInMilliseconds'); | ||
@@ -28,2 +36,3 @@ var eachDayOfInterval = require('date-fns/eachDayOfInterval'); | ||
var setMonth = require('date-fns/setMonth'); | ||
var getDaysInMonth = require('date-fns/getDaysInMonth'); | ||
var setSeconds = require('date-fns/setSeconds'); | ||
@@ -45,2 +54,10 @@ var setYear = require('date-fns/setYear'); | ||
var addYears__default = /*#__PURE__*/_interopDefaultLegacy(addYears); | ||
var differenceInYears__default = /*#__PURE__*/_interopDefaultLegacy(differenceInYears); | ||
var differenceInQuarters__default = /*#__PURE__*/_interopDefaultLegacy(differenceInQuarters); | ||
var differenceInMonths__default = /*#__PURE__*/_interopDefaultLegacy(differenceInMonths); | ||
var differenceInWeeks__default = /*#__PURE__*/_interopDefaultLegacy(differenceInWeeks); | ||
var differenceInDays__default = /*#__PURE__*/_interopDefaultLegacy(differenceInDays); | ||
var differenceInHours__default = /*#__PURE__*/_interopDefaultLegacy(differenceInHours); | ||
var differenceInMinutes__default = /*#__PURE__*/_interopDefaultLegacy(differenceInMinutes); | ||
var differenceInSeconds__default = /*#__PURE__*/_interopDefaultLegacy(differenceInSeconds); | ||
var differenceInMilliseconds__default = /*#__PURE__*/_interopDefaultLegacy(differenceInMilliseconds); | ||
@@ -67,2 +84,3 @@ var eachDayOfInterval__default = /*#__PURE__*/_interopDefaultLegacy(eachDayOfInterval); | ||
var setMonth__default = /*#__PURE__*/_interopDefaultLegacy(setMonth); | ||
var getDaysInMonth__default = /*#__PURE__*/_interopDefaultLegacy(getDaysInMonth); | ||
var setSeconds__default = /*#__PURE__*/_interopDefaultLegacy(setSeconds); | ||
@@ -155,4 +173,24 @@ var setYear__default = /*#__PURE__*/_interopDefaultLegacy(setYear); | ||
}; | ||
DateFnsUtils.prototype.getDiff = function (value, comparing) { | ||
return differenceInMilliseconds__default['default'](value, this.date(comparing)); | ||
DateFnsUtils.prototype.getDiff = function (value, comparing, unit) { | ||
switch (unit) { | ||
case "years": | ||
return differenceInYears__default['default'](value, this.date(comparing)); | ||
case "quarters": | ||
return differenceInQuarters__default['default'](value, this.date(comparing)); | ||
case "months": | ||
return differenceInMonths__default['default'](value, this.date(comparing)); | ||
case "weeks": | ||
return differenceInWeeks__default['default'](value, this.date(comparing)); | ||
case "days": | ||
return differenceInDays__default['default'](value, this.date(comparing)); | ||
case "hours": | ||
return differenceInHours__default['default'](value, this.date(comparing)); | ||
case "minutes": | ||
return differenceInMinutes__default['default'](value, this.date(comparing)); | ||
case "seconds": | ||
return differenceInSeconds__default['default'](value, this.date(comparing)); | ||
default: { | ||
return differenceInMilliseconds__default['default'](value, this.date(comparing)); | ||
} | ||
} | ||
}; | ||
@@ -274,2 +312,5 @@ DateFnsUtils.prototype.isAfter = function (value, comparing) { | ||
}; | ||
DateFnsUtils.prototype.getDaysInMonth = function (date) { | ||
return getDaysInMonth__default['default'](date); | ||
}; | ||
DateFnsUtils.prototype.setMonth = function (date, count) { | ||
@@ -276,0 +317,0 @@ return setMonth__default['default'](date, count); |
{ | ||
"name": "@date-io/date-fns", | ||
"version": "2.8.1", | ||
"version": "2.9.1", | ||
"description": "Abstraction over common javascript date management libraries", | ||
@@ -36,3 +36,3 @@ "main": "build/index.js", | ||
"dependencies": { | ||
"@date-io/core": "^2.8.1" | ||
"@date-io/core": "^2.9.0" | ||
}, | ||
@@ -44,3 +44,3 @@ "devDependencies": { | ||
}, | ||
"gitHead": "5f04842fb1c5949535b79460f073ab8e668bdb6a" | ||
"gitHead": "b288f4a6e493cefa32226e9363adea4fe1184168" | ||
} |
import addDays from "date-fns/addDays"; | ||
import addMonths from "date-fns/addMonths"; | ||
import addYears from "date-fns/addYears"; | ||
import differenceInYears from "date-fns/differenceInYears"; | ||
import differenceInQuarters from "date-fns/differenceInQuarters"; | ||
import differenceInMonths from "date-fns/differenceInMonths"; | ||
import differenceInWeeks from "date-fns/differenceInWeeks"; | ||
import differenceInDays from "date-fns/differenceInDays"; | ||
import differenceInHours from "date-fns/differenceInHours"; | ||
import differenceInMinutes from "date-fns/differenceInMinutes"; | ||
import differenceInSeconds from "date-fns/differenceInSeconds"; | ||
import differenceInMilliseconds from "date-fns/differenceInMilliseconds"; | ||
@@ -25,2 +33,3 @@ import eachDayOfInterval from "date-fns/eachDayOfInterval"; | ||
import setMonth from "date-fns/setMonth"; | ||
import getDaysInMonth from "date-fns/getDaysInMonth"; | ||
import setSeconds from "date-fns/setSeconds"; | ||
@@ -33,3 +42,3 @@ import setYear from "date-fns/setYear"; | ||
import startOfYear from "date-fns/startOfYear"; | ||
import { IUtils, DateIOFormats } from "@date-io/core/IUtils"; | ||
import { IUtils, DateIOFormats, Unit } from "@date-io/core/IUtils"; | ||
import isWithinInterval from "date-fns/isWithinInterval"; | ||
@@ -130,4 +139,24 @@ import longFormatters from "date-fns/_lib/format/longFormatters"; | ||
public getDiff(value: Date, comparing: Date | string) { | ||
return differenceInMilliseconds(value, this.date(comparing)); | ||
public getDiff(value: Date, comparing: Date | string, unit?: Unit) { | ||
switch (unit) { | ||
case "years": | ||
return differenceInYears(value, this.date(comparing)); | ||
case "quarters": | ||
return differenceInQuarters(value, this.date(comparing)); | ||
case "months": | ||
return differenceInMonths(value, this.date(comparing)); | ||
case "weeks": | ||
return differenceInWeeks(value, this.date(comparing)); | ||
case "days": | ||
return differenceInDays(value, this.date(comparing)); | ||
case "hours": | ||
return differenceInHours(value, this.date(comparing)); | ||
case "minutes": | ||
return differenceInMinutes(value, this.date(comparing)); | ||
case "seconds": | ||
return differenceInSeconds(value, this.date(comparing)); | ||
default: { | ||
return differenceInMilliseconds(value, this.date(comparing)); | ||
} | ||
} | ||
} | ||
@@ -287,2 +316,6 @@ | ||
public getDaysInMonth(date: Date) { | ||
return getDaysInMonth(date); | ||
} | ||
public setMonth(date: Date, count: number) { | ||
@@ -289,0 +322,0 @@ return setMonth(date, count); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
45487
1093
1
12
Updated@date-io/core@^2.9.0