project files added
This commit is contained in:
+1955
File diff suppressed because it is too large
Load Diff
+4
@@ -0,0 +1,4 @@
|
||||
# License
|
||||
|
||||
date-fns is licensed under the [MIT license](http://kossnocorp.mit-license.org).
|
||||
Read more about MIT at [TLDRLegal](https://tldrlegal.com/license/mit-license).
|
||||
+57
@@ -0,0 +1,57 @@
|
||||
#  date-fns
|
||||
|
||||
🔥🔥🔥 **date-fns v2 is out!** 🔥🔥🔥
|
||||
|
||||
⭐️ **Upgrading from v1 to v2?**
|
||||
|
||||
- [See the changelog](https://github.com/date-fns/date-fns/blob/master/CHANGELOG.md)
|
||||
- Check out [@date-fns/upgrade](https://github.com/date-fns/date-fns-upgrade) and [@date-fns/upgrade-codemod](https://github.com/date-fns/date-fns-upgrade-codemod), they could help you with the upgrade!
|
||||
|
||||
**date-fns** provides the most comprehensive, yet simple and consistent toolset
|
||||
for manipulating **JavaScript dates** in **a browser** & **Node.js**.
|
||||
|
||||
**date-fns** is like [lodash](https://lodash.com) for dates. It has
|
||||
[**180+ functions** for all occasions](https://date-fns.org/docs/).
|
||||
|
||||
```js
|
||||
import { compareAsc, format } from 'date-fns'
|
||||
|
||||
format(new Date(2014, 1, 11), 'yyyy-MM-dd')
|
||||
//=> '2014-02-11'
|
||||
|
||||
const dates = [
|
||||
new Date(1995, 6, 2),
|
||||
new Date(1987, 1, 11),
|
||||
new Date(1989, 6, 10)
|
||||
]
|
||||
dates.sort(compareAsc)
|
||||
//=> [
|
||||
// Wed Feb 11 1987 00:00:00,
|
||||
// Mon Jul 10 1989 00:00:00,
|
||||
// Sun Jul 02 1995 00:00:00
|
||||
// ]
|
||||
```
|
||||
|
||||
The library is available as an [npm package](https://www.npmjs.com/package/date-fns).
|
||||
To install the package run:
|
||||
|
||||
```bash
|
||||
npm install date-fns --save
|
||||
# or with yarn
|
||||
yarn add date-fns
|
||||
```
|
||||
|
||||
## Docs
|
||||
|
||||
[See date-fns.org](https://date-fns.org/) for more details, API,
|
||||
and other docs.
|
||||
|
||||
## JavaScript jobs by date-fns
|
||||
|
||||
👋 Know someone who's looking for JavaScript devs? [Recommend us a job!](https://jobs.date-fns.org/#recommend)
|
||||
|
||||
✉️ Get jobs worth sharing to your email! [Subscribe to the newsletter](https://jobs.date-fns.org).
|
||||
|
||||
## License
|
||||
|
||||
[MIT © Sasha Koss](https://kossnocorp.mit-license.org/)
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.default = addLeadingZeros;
|
||||
|
||||
function addLeadingZeros(number, targetLength) {
|
||||
var sign = number < 0 ? '-' : '';
|
||||
var output = Math.abs(number).toString();
|
||||
|
||||
while (output.length < targetLength) {
|
||||
output = '0' + output;
|
||||
}
|
||||
|
||||
return sign + output;
|
||||
}
|
||||
|
||||
module.exports = exports.default;
|
||||
+24
@@ -0,0 +1,24 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.default = assign;
|
||||
|
||||
function assign(target, dirtyObject) {
|
||||
if (target == null) {
|
||||
throw new TypeError('assign requires that input parameter not be null or undefined');
|
||||
}
|
||||
|
||||
dirtyObject = dirtyObject || {};
|
||||
|
||||
for (var property in dirtyObject) {
|
||||
if (dirtyObject.hasOwnProperty(property)) {
|
||||
target[property] = dirtyObject[property];
|
||||
}
|
||||
}
|
||||
|
||||
return target;
|
||||
}
|
||||
|
||||
module.exports = exports.default;
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.default = cloneObject;
|
||||
|
||||
var _index = _interopRequireDefault(require("../assign/index.js"));
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
|
||||
function cloneObject(dirtyObject) {
|
||||
return (0, _index.default)({}, dirtyObject);
|
||||
}
|
||||
|
||||
module.exports = exports.default;
|
||||
+874
@@ -0,0 +1,874 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.default = void 0;
|
||||
|
||||
var _index = _interopRequireDefault(require("../lightFormatters/index.js"));
|
||||
|
||||
var _index2 = _interopRequireDefault(require("../../../_lib/getUTCDayOfYear/index.js"));
|
||||
|
||||
var _index3 = _interopRequireDefault(require("../../../_lib/getUTCISOWeek/index.js"));
|
||||
|
||||
var _index4 = _interopRequireDefault(require("../../../_lib/getUTCISOWeekYear/index.js"));
|
||||
|
||||
var _index5 = _interopRequireDefault(require("../../../_lib/getUTCWeek/index.js"));
|
||||
|
||||
var _index6 = _interopRequireDefault(require("../../../_lib/getUTCWeekYear/index.js"));
|
||||
|
||||
var _index7 = _interopRequireDefault(require("../../addLeadingZeros/index.js"));
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
|
||||
var dayPeriodEnum = {
|
||||
am: 'am',
|
||||
pm: 'pm',
|
||||
midnight: 'midnight',
|
||||
noon: 'noon',
|
||||
morning: 'morning',
|
||||
afternoon: 'afternoon',
|
||||
evening: 'evening',
|
||||
night: 'night'
|
||||
/*
|
||||
* | | Unit | | Unit |
|
||||
* |-----|--------------------------------|-----|--------------------------------|
|
||||
* | a | AM, PM | A* | Milliseconds in day |
|
||||
* | b | AM, PM, noon, midnight | B | Flexible day period |
|
||||
* | c | Stand-alone local day of week | C* | Localized hour w/ day period |
|
||||
* | d | Day of month | D | Day of year |
|
||||
* | e | Local day of week | E | Day of week |
|
||||
* | f | | F* | Day of week in month |
|
||||
* | g* | Modified Julian day | G | Era |
|
||||
* | h | Hour [1-12] | H | Hour [0-23] |
|
||||
* | i! | ISO day of week | I! | ISO week of year |
|
||||
* | j* | Localized hour w/ day period | J* | Localized hour w/o day period |
|
||||
* | k | Hour [1-24] | K | Hour [0-11] |
|
||||
* | l* | (deprecated) | L | Stand-alone month |
|
||||
* | m | Minute | M | Month |
|
||||
* | n | | N | |
|
||||
* | o! | Ordinal number modifier | O | Timezone (GMT) |
|
||||
* | p! | Long localized time | P! | Long localized date |
|
||||
* | q | Stand-alone quarter | Q | Quarter |
|
||||
* | r* | Related Gregorian year | R! | ISO week-numbering year |
|
||||
* | s | Second | S | Fraction of second |
|
||||
* | t! | Seconds timestamp | T! | Milliseconds timestamp |
|
||||
* | u | Extended year | U* | Cyclic year |
|
||||
* | v* | Timezone (generic non-locat.) | V* | Timezone (location) |
|
||||
* | w | Local week of year | W* | Week of month |
|
||||
* | x | Timezone (ISO-8601 w/o Z) | X | Timezone (ISO-8601) |
|
||||
* | y | Year (abs) | Y | Local week-numbering year |
|
||||
* | z | Timezone (specific non-locat.) | Z* | Timezone (aliases) |
|
||||
*
|
||||
* Letters marked by * are not implemented but reserved by Unicode standard.
|
||||
*
|
||||
* Letters marked by ! are non-standard, but implemented by date-fns:
|
||||
* - `o` modifies the previous token to turn it into an ordinal (see `format` docs)
|
||||
* - `i` is ISO day of week. For `i` and `ii` is returns numeric ISO week days,
|
||||
* i.e. 7 for Sunday, 1 for Monday, etc.
|
||||
* - `I` is ISO week of year, as opposed to `w` which is local week of year.
|
||||
* - `R` is ISO week-numbering year, as opposed to `Y` which is local week-numbering year.
|
||||
* `R` is supposed to be used in conjunction with `I` and `i`
|
||||
* for universal ISO week-numbering date, whereas
|
||||
* `Y` is supposed to be used in conjunction with `w` and `e`
|
||||
* for week-numbering date specific to the locale.
|
||||
* - `P` is long localized date format
|
||||
* - `p` is long localized time format
|
||||
*/
|
||||
|
||||
};
|
||||
var formatters = {
|
||||
// Era
|
||||
G: function (date, token, localize) {
|
||||
var era = date.getUTCFullYear() > 0 ? 1 : 0;
|
||||
|
||||
switch (token) {
|
||||
// AD, BC
|
||||
case 'G':
|
||||
case 'GG':
|
||||
case 'GGG':
|
||||
return localize.era(era, {
|
||||
width: 'abbreviated'
|
||||
});
|
||||
// A, B
|
||||
|
||||
case 'GGGGG':
|
||||
return localize.era(era, {
|
||||
width: 'narrow'
|
||||
});
|
||||
// Anno Domini, Before Christ
|
||||
|
||||
case 'GGGG':
|
||||
default:
|
||||
return localize.era(era, {
|
||||
width: 'wide'
|
||||
});
|
||||
}
|
||||
},
|
||||
// Year
|
||||
y: function (date, token, localize) {
|
||||
// Ordinal number
|
||||
if (token === 'yo') {
|
||||
var signedYear = date.getUTCFullYear(); // Returns 1 for 1 BC (which is year 0 in JavaScript)
|
||||
|
||||
var year = signedYear > 0 ? signedYear : 1 - signedYear;
|
||||
return localize.ordinalNumber(year, {
|
||||
unit: 'year'
|
||||
});
|
||||
}
|
||||
|
||||
return _index.default.y(date, token);
|
||||
},
|
||||
// Local week-numbering year
|
||||
Y: function (date, token, localize, options) {
|
||||
var signedWeekYear = (0, _index6.default)(date, options); // Returns 1 for 1 BC (which is year 0 in JavaScript)
|
||||
|
||||
var weekYear = signedWeekYear > 0 ? signedWeekYear : 1 - signedWeekYear; // Two digit year
|
||||
|
||||
if (token === 'YY') {
|
||||
var twoDigitYear = weekYear % 100;
|
||||
return (0, _index7.default)(twoDigitYear, 2);
|
||||
} // Ordinal number
|
||||
|
||||
|
||||
if (token === 'Yo') {
|
||||
return localize.ordinalNumber(weekYear, {
|
||||
unit: 'year'
|
||||
});
|
||||
} // Padding
|
||||
|
||||
|
||||
return (0, _index7.default)(weekYear, token.length);
|
||||
},
|
||||
// ISO week-numbering year
|
||||
R: function (date, token) {
|
||||
var isoWeekYear = (0, _index4.default)(date); // Padding
|
||||
|
||||
return (0, _index7.default)(isoWeekYear, token.length);
|
||||
},
|
||||
// Extended year. This is a single number designating the year of this calendar system.
|
||||
// The main difference between `y` and `u` localizers are B.C. years:
|
||||
// | Year | `y` | `u` |
|
||||
// |------|-----|-----|
|
||||
// | AC 1 | 1 | 1 |
|
||||
// | BC 1 | 1 | 0 |
|
||||
// | BC 2 | 2 | -1 |
|
||||
// Also `yy` always returns the last two digits of a year,
|
||||
// while `uu` pads single digit years to 2 characters and returns other years unchanged.
|
||||
u: function (date, token) {
|
||||
var year = date.getUTCFullYear();
|
||||
return (0, _index7.default)(year, token.length);
|
||||
},
|
||||
// Quarter
|
||||
Q: function (date, token, localize) {
|
||||
var quarter = Math.ceil((date.getUTCMonth() + 1) / 3);
|
||||
|
||||
switch (token) {
|
||||
// 1, 2, 3, 4
|
||||
case 'Q':
|
||||
return String(quarter);
|
||||
// 01, 02, 03, 04
|
||||
|
||||
case 'QQ':
|
||||
return (0, _index7.default)(quarter, 2);
|
||||
// 1st, 2nd, 3rd, 4th
|
||||
|
||||
case 'Qo':
|
||||
return localize.ordinalNumber(quarter, {
|
||||
unit: 'quarter'
|
||||
});
|
||||
// Q1, Q2, Q3, Q4
|
||||
|
||||
case 'QQQ':
|
||||
return localize.quarter(quarter, {
|
||||
width: 'abbreviated',
|
||||
context: 'formatting'
|
||||
});
|
||||
// 1, 2, 3, 4 (narrow quarter; could be not numerical)
|
||||
|
||||
case 'QQQQQ':
|
||||
return localize.quarter(quarter, {
|
||||
width: 'narrow',
|
||||
context: 'formatting'
|
||||
});
|
||||
// 1st quarter, 2nd quarter, ...
|
||||
|
||||
case 'QQQQ':
|
||||
default:
|
||||
return localize.quarter(quarter, {
|
||||
width: 'wide',
|
||||
context: 'formatting'
|
||||
});
|
||||
}
|
||||
},
|
||||
// Stand-alone quarter
|
||||
q: function (date, token, localize) {
|
||||
var quarter = Math.ceil((date.getUTCMonth() + 1) / 3);
|
||||
|
||||
switch (token) {
|
||||
// 1, 2, 3, 4
|
||||
case 'q':
|
||||
return String(quarter);
|
||||
// 01, 02, 03, 04
|
||||
|
||||
case 'qq':
|
||||
return (0, _index7.default)(quarter, 2);
|
||||
// 1st, 2nd, 3rd, 4th
|
||||
|
||||
case 'qo':
|
||||
return localize.ordinalNumber(quarter, {
|
||||
unit: 'quarter'
|
||||
});
|
||||
// Q1, Q2, Q3, Q4
|
||||
|
||||
case 'qqq':
|
||||
return localize.quarter(quarter, {
|
||||
width: 'abbreviated',
|
||||
context: 'standalone'
|
||||
});
|
||||
// 1, 2, 3, 4 (narrow quarter; could be not numerical)
|
||||
|
||||
case 'qqqqq':
|
||||
return localize.quarter(quarter, {
|
||||
width: 'narrow',
|
||||
context: 'standalone'
|
||||
});
|
||||
// 1st quarter, 2nd quarter, ...
|
||||
|
||||
case 'qqqq':
|
||||
default:
|
||||
return localize.quarter(quarter, {
|
||||
width: 'wide',
|
||||
context: 'standalone'
|
||||
});
|
||||
}
|
||||
},
|
||||
// Month
|
||||
M: function (date, token, localize) {
|
||||
var month = date.getUTCMonth();
|
||||
|
||||
switch (token) {
|
||||
case 'M':
|
||||
case 'MM':
|
||||
return _index.default.M(date, token);
|
||||
// 1st, 2nd, ..., 12th
|
||||
|
||||
case 'Mo':
|
||||
return localize.ordinalNumber(month + 1, {
|
||||
unit: 'month'
|
||||
});
|
||||
// Jan, Feb, ..., Dec
|
||||
|
||||
case 'MMM':
|
||||
return localize.month(month, {
|
||||
width: 'abbreviated',
|
||||
context: 'formatting'
|
||||
});
|
||||
// J, F, ..., D
|
||||
|
||||
case 'MMMMM':
|
||||
return localize.month(month, {
|
||||
width: 'narrow',
|
||||
context: 'formatting'
|
||||
});
|
||||
// January, February, ..., December
|
||||
|
||||
case 'MMMM':
|
||||
default:
|
||||
return localize.month(month, {
|
||||
width: 'wide',
|
||||
context: 'formatting'
|
||||
});
|
||||
}
|
||||
},
|
||||
// Stand-alone month
|
||||
L: function (date, token, localize) {
|
||||
var month = date.getUTCMonth();
|
||||
|
||||
switch (token) {
|
||||
// 1, 2, ..., 12
|
||||
case 'L':
|
||||
return String(month + 1);
|
||||
// 01, 02, ..., 12
|
||||
|
||||
case 'LL':
|
||||
return (0, _index7.default)(month + 1, 2);
|
||||
// 1st, 2nd, ..., 12th
|
||||
|
||||
case 'Lo':
|
||||
return localize.ordinalNumber(month + 1, {
|
||||
unit: 'month'
|
||||
});
|
||||
// Jan, Feb, ..., Dec
|
||||
|
||||
case 'LLL':
|
||||
return localize.month(month, {
|
||||
width: 'abbreviated',
|
||||
context: 'standalone'
|
||||
});
|
||||
// J, F, ..., D
|
||||
|
||||
case 'LLLLL':
|
||||
return localize.month(month, {
|
||||
width: 'narrow',
|
||||
context: 'standalone'
|
||||
});
|
||||
// January, February, ..., December
|
||||
|
||||
case 'LLLL':
|
||||
default:
|
||||
return localize.month(month, {
|
||||
width: 'wide',
|
||||
context: 'standalone'
|
||||
});
|
||||
}
|
||||
},
|
||||
// Local week of year
|
||||
w: function (date, token, localize, options) {
|
||||
var week = (0, _index5.default)(date, options);
|
||||
|
||||
if (token === 'wo') {
|
||||
return localize.ordinalNumber(week, {
|
||||
unit: 'week'
|
||||
});
|
||||
}
|
||||
|
||||
return (0, _index7.default)(week, token.length);
|
||||
},
|
||||
// ISO week of year
|
||||
I: function (date, token, localize) {
|
||||
var isoWeek = (0, _index3.default)(date);
|
||||
|
||||
if (token === 'Io') {
|
||||
return localize.ordinalNumber(isoWeek, {
|
||||
unit: 'week'
|
||||
});
|
||||
}
|
||||
|
||||
return (0, _index7.default)(isoWeek, token.length);
|
||||
},
|
||||
// Day of the month
|
||||
d: function (date, token, localize) {
|
||||
if (token === 'do') {
|
||||
return localize.ordinalNumber(date.getUTCDate(), {
|
||||
unit: 'date'
|
||||
});
|
||||
}
|
||||
|
||||
return _index.default.d(date, token);
|
||||
},
|
||||
// Day of year
|
||||
D: function (date, token, localize) {
|
||||
var dayOfYear = (0, _index2.default)(date);
|
||||
|
||||
if (token === 'Do') {
|
||||
return localize.ordinalNumber(dayOfYear, {
|
||||
unit: 'dayOfYear'
|
||||
});
|
||||
}
|
||||
|
||||
return (0, _index7.default)(dayOfYear, token.length);
|
||||
},
|
||||
// Day of week
|
||||
E: function (date, token, localize) {
|
||||
var dayOfWeek = date.getUTCDay();
|
||||
|
||||
switch (token) {
|
||||
// Tue
|
||||
case 'E':
|
||||
case 'EE':
|
||||
case 'EEE':
|
||||
return localize.day(dayOfWeek, {
|
||||
width: 'abbreviated',
|
||||
context: 'formatting'
|
||||
});
|
||||
// T
|
||||
|
||||
case 'EEEEE':
|
||||
return localize.day(dayOfWeek, {
|
||||
width: 'narrow',
|
||||
context: 'formatting'
|
||||
});
|
||||
// Tu
|
||||
|
||||
case 'EEEEEE':
|
||||
return localize.day(dayOfWeek, {
|
||||
width: 'short',
|
||||
context: 'formatting'
|
||||
});
|
||||
// Tuesday
|
||||
|
||||
case 'EEEE':
|
||||
default:
|
||||
return localize.day(dayOfWeek, {
|
||||
width: 'wide',
|
||||
context: 'formatting'
|
||||
});
|
||||
}
|
||||
},
|
||||
// Local day of week
|
||||
e: function (date, token, localize, options) {
|
||||
var dayOfWeek = date.getUTCDay();
|
||||
var localDayOfWeek = (dayOfWeek - options.weekStartsOn + 8) % 7 || 7;
|
||||
|
||||
switch (token) {
|
||||
// Numerical value (Nth day of week with current locale or weekStartsOn)
|
||||
case 'e':
|
||||
return String(localDayOfWeek);
|
||||
// Padded numerical value
|
||||
|
||||
case 'ee':
|
||||
return (0, _index7.default)(localDayOfWeek, 2);
|
||||
// 1st, 2nd, ..., 7th
|
||||
|
||||
case 'eo':
|
||||
return localize.ordinalNumber(localDayOfWeek, {
|
||||
unit: 'day'
|
||||
});
|
||||
|
||||
case 'eee':
|
||||
return localize.day(dayOfWeek, {
|
||||
width: 'abbreviated',
|
||||
context: 'formatting'
|
||||
});
|
||||
// T
|
||||
|
||||
case 'eeeee':
|
||||
return localize.day(dayOfWeek, {
|
||||
width: 'narrow',
|
||||
context: 'formatting'
|
||||
});
|
||||
// Tu
|
||||
|
||||
case 'eeeeee':
|
||||
return localize.day(dayOfWeek, {
|
||||
width: 'short',
|
||||
context: 'formatting'
|
||||
});
|
||||
// Tuesday
|
||||
|
||||
case 'eeee':
|
||||
default:
|
||||
return localize.day(dayOfWeek, {
|
||||
width: 'wide',
|
||||
context: 'formatting'
|
||||
});
|
||||
}
|
||||
},
|
||||
// Stand-alone local day of week
|
||||
c: function (date, token, localize, options) {
|
||||
var dayOfWeek = date.getUTCDay();
|
||||
var localDayOfWeek = (dayOfWeek - options.weekStartsOn + 8) % 7 || 7;
|
||||
|
||||
switch (token) {
|
||||
// Numerical value (same as in `e`)
|
||||
case 'c':
|
||||
return String(localDayOfWeek);
|
||||
// Padded numerical value
|
||||
|
||||
case 'cc':
|
||||
return (0, _index7.default)(localDayOfWeek, token.length);
|
||||
// 1st, 2nd, ..., 7th
|
||||
|
||||
case 'co':
|
||||
return localize.ordinalNumber(localDayOfWeek, {
|
||||
unit: 'day'
|
||||
});
|
||||
|
||||
case 'ccc':
|
||||
return localize.day(dayOfWeek, {
|
||||
width: 'abbreviated',
|
||||
context: 'standalone'
|
||||
});
|
||||
// T
|
||||
|
||||
case 'ccccc':
|
||||
return localize.day(dayOfWeek, {
|
||||
width: 'narrow',
|
||||
context: 'standalone'
|
||||
});
|
||||
// Tu
|
||||
|
||||
case 'cccccc':
|
||||
return localize.day(dayOfWeek, {
|
||||
width: 'short',
|
||||
context: 'standalone'
|
||||
});
|
||||
// Tuesday
|
||||
|
||||
case 'cccc':
|
||||
default:
|
||||
return localize.day(dayOfWeek, {
|
||||
width: 'wide',
|
||||
context: 'standalone'
|
||||
});
|
||||
}
|
||||
},
|
||||
// ISO day of week
|
||||
i: function (date, token, localize) {
|
||||
var dayOfWeek = date.getUTCDay();
|
||||
var isoDayOfWeek = dayOfWeek === 0 ? 7 : dayOfWeek;
|
||||
|
||||
switch (token) {
|
||||
// 2
|
||||
case 'i':
|
||||
return String(isoDayOfWeek);
|
||||
// 02
|
||||
|
||||
case 'ii':
|
||||
return (0, _index7.default)(isoDayOfWeek, token.length);
|
||||
// 2nd
|
||||
|
||||
case 'io':
|
||||
return localize.ordinalNumber(isoDayOfWeek, {
|
||||
unit: 'day'
|
||||
});
|
||||
// Tue
|
||||
|
||||
case 'iii':
|
||||
return localize.day(dayOfWeek, {
|
||||
width: 'abbreviated',
|
||||
context: 'formatting'
|
||||
});
|
||||
// T
|
||||
|
||||
case 'iiiii':
|
||||
return localize.day(dayOfWeek, {
|
||||
width: 'narrow',
|
||||
context: 'formatting'
|
||||
});
|
||||
// Tu
|
||||
|
||||
case 'iiiiii':
|
||||
return localize.day(dayOfWeek, {
|
||||
width: 'short',
|
||||
context: 'formatting'
|
||||
});
|
||||
// Tuesday
|
||||
|
||||
case 'iiii':
|
||||
default:
|
||||
return localize.day(dayOfWeek, {
|
||||
width: 'wide',
|
||||
context: 'formatting'
|
||||
});
|
||||
}
|
||||
},
|
||||
// AM or PM
|
||||
a: function (date, token, localize) {
|
||||
var hours = date.getUTCHours();
|
||||
var dayPeriodEnumValue = hours / 12 >= 1 ? 'pm' : 'am';
|
||||
|
||||
switch (token) {
|
||||
case 'a':
|
||||
case 'aa':
|
||||
case 'aaa':
|
||||
return localize.dayPeriod(dayPeriodEnumValue, {
|
||||
width: 'abbreviated',
|
||||
context: 'formatting'
|
||||
});
|
||||
|
||||
case 'aaaaa':
|
||||
return localize.dayPeriod(dayPeriodEnumValue, {
|
||||
width: 'narrow',
|
||||
context: 'formatting'
|
||||
});
|
||||
|
||||
case 'aaaa':
|
||||
default:
|
||||
return localize.dayPeriod(dayPeriodEnumValue, {
|
||||
width: 'wide',
|
||||
context: 'formatting'
|
||||
});
|
||||
}
|
||||
},
|
||||
// AM, PM, midnight, noon
|
||||
b: function (date, token, localize) {
|
||||
var hours = date.getUTCHours();
|
||||
var dayPeriodEnumValue;
|
||||
|
||||
if (hours === 12) {
|
||||
dayPeriodEnumValue = dayPeriodEnum.noon;
|
||||
} else if (hours === 0) {
|
||||
dayPeriodEnumValue = dayPeriodEnum.midnight;
|
||||
} else {
|
||||
dayPeriodEnumValue = hours / 12 >= 1 ? 'pm' : 'am';
|
||||
}
|
||||
|
||||
switch (token) {
|
||||
case 'b':
|
||||
case 'bb':
|
||||
case 'bbb':
|
||||
return localize.dayPeriod(dayPeriodEnumValue, {
|
||||
width: 'abbreviated',
|
||||
context: 'formatting'
|
||||
});
|
||||
|
||||
case 'bbbbb':
|
||||
return localize.dayPeriod(dayPeriodEnumValue, {
|
||||
width: 'narrow',
|
||||
context: 'formatting'
|
||||
});
|
||||
|
||||
case 'bbbb':
|
||||
default:
|
||||
return localize.dayPeriod(dayPeriodEnumValue, {
|
||||
width: 'wide',
|
||||
context: 'formatting'
|
||||
});
|
||||
}
|
||||
},
|
||||
// in the morning, in the afternoon, in the evening, at night
|
||||
B: function (date, token, localize) {
|
||||
var hours = date.getUTCHours();
|
||||
var dayPeriodEnumValue;
|
||||
|
||||
if (hours >= 17) {
|
||||
dayPeriodEnumValue = dayPeriodEnum.evening;
|
||||
} else if (hours >= 12) {
|
||||
dayPeriodEnumValue = dayPeriodEnum.afternoon;
|
||||
} else if (hours >= 4) {
|
||||
dayPeriodEnumValue = dayPeriodEnum.morning;
|
||||
} else {
|
||||
dayPeriodEnumValue = dayPeriodEnum.night;
|
||||
}
|
||||
|
||||
switch (token) {
|
||||
case 'B':
|
||||
case 'BB':
|
||||
case 'BBB':
|
||||
return localize.dayPeriod(dayPeriodEnumValue, {
|
||||
width: 'abbreviated',
|
||||
context: 'formatting'
|
||||
});
|
||||
|
||||
case 'BBBBB':
|
||||
return localize.dayPeriod(dayPeriodEnumValue, {
|
||||
width: 'narrow',
|
||||
context: 'formatting'
|
||||
});
|
||||
|
||||
case 'BBBB':
|
||||
default:
|
||||
return localize.dayPeriod(dayPeriodEnumValue, {
|
||||
width: 'wide',
|
||||
context: 'formatting'
|
||||
});
|
||||
}
|
||||
},
|
||||
// Hour [1-12]
|
||||
h: function (date, token, localize) {
|
||||
if (token === 'ho') {
|
||||
var hours = date.getUTCHours() % 12;
|
||||
if (hours === 0) hours = 12;
|
||||
return localize.ordinalNumber(hours, {
|
||||
unit: 'hour'
|
||||
});
|
||||
}
|
||||
|
||||
return _index.default.h(date, token);
|
||||
},
|
||||
// Hour [0-23]
|
||||
H: function (date, token, localize) {
|
||||
if (token === 'Ho') {
|
||||
return localize.ordinalNumber(date.getUTCHours(), {
|
||||
unit: 'hour'
|
||||
});
|
||||
}
|
||||
|
||||
return _index.default.H(date, token);
|
||||
},
|
||||
// Hour [0-11]
|
||||
K: function (date, token, localize) {
|
||||
var hours = date.getUTCHours() % 12;
|
||||
|
||||
if (token === 'Ko') {
|
||||
return localize.ordinalNumber(hours, {
|
||||
unit: 'hour'
|
||||
});
|
||||
}
|
||||
|
||||
return (0, _index7.default)(hours, token.length);
|
||||
},
|
||||
// Hour [1-24]
|
||||
k: function (date, token, localize) {
|
||||
var hours = date.getUTCHours();
|
||||
if (hours === 0) hours = 24;
|
||||
|
||||
if (token === 'ko') {
|
||||
return localize.ordinalNumber(hours, {
|
||||
unit: 'hour'
|
||||
});
|
||||
}
|
||||
|
||||
return (0, _index7.default)(hours, token.length);
|
||||
},
|
||||
// Minute
|
||||
m: function (date, token, localize) {
|
||||
if (token === 'mo') {
|
||||
return localize.ordinalNumber(date.getUTCMinutes(), {
|
||||
unit: 'minute'
|
||||
});
|
||||
}
|
||||
|
||||
return _index.default.m(date, token);
|
||||
},
|
||||
// Second
|
||||
s: function (date, token, localize) {
|
||||
if (token === 'so') {
|
||||
return localize.ordinalNumber(date.getUTCSeconds(), {
|
||||
unit: 'second'
|
||||
});
|
||||
}
|
||||
|
||||
return _index.default.s(date, token);
|
||||
},
|
||||
// Fraction of second
|
||||
S: function (date, token) {
|
||||
return _index.default.S(date, token);
|
||||
},
|
||||
// Timezone (ISO-8601. If offset is 0, output is always `'Z'`)
|
||||
X: function (date, token, _localize, options) {
|
||||
var originalDate = options._originalDate || date;
|
||||
var timezoneOffset = originalDate.getTimezoneOffset();
|
||||
|
||||
if (timezoneOffset === 0) {
|
||||
return 'Z';
|
||||
}
|
||||
|
||||
switch (token) {
|
||||
// Hours and optional minutes
|
||||
case 'X':
|
||||
return formatTimezoneWithOptionalMinutes(timezoneOffset);
|
||||
// Hours, minutes and optional seconds without `:` delimiter
|
||||
// Note: neither ISO-8601 nor JavaScript supports seconds in timezone offsets
|
||||
// so this token always has the same output as `XX`
|
||||
|
||||
case 'XXXX':
|
||||
case 'XX':
|
||||
// Hours and minutes without `:` delimiter
|
||||
return formatTimezone(timezoneOffset);
|
||||
// Hours, minutes and optional seconds with `:` delimiter
|
||||
// Note: neither ISO-8601 nor JavaScript supports seconds in timezone offsets
|
||||
// so this token always has the same output as `XXX`
|
||||
|
||||
case 'XXXXX':
|
||||
case 'XXX': // Hours and minutes with `:` delimiter
|
||||
|
||||
default:
|
||||
return formatTimezone(timezoneOffset, ':');
|
||||
}
|
||||
},
|
||||
// Timezone (ISO-8601. If offset is 0, output is `'+00:00'` or equivalent)
|
||||
x: function (date, token, _localize, options) {
|
||||
var originalDate = options._originalDate || date;
|
||||
var timezoneOffset = originalDate.getTimezoneOffset();
|
||||
|
||||
switch (token) {
|
||||
// Hours and optional minutes
|
||||
case 'x':
|
||||
return formatTimezoneWithOptionalMinutes(timezoneOffset);
|
||||
// Hours, minutes and optional seconds without `:` delimiter
|
||||
// Note: neither ISO-8601 nor JavaScript supports seconds in timezone offsets
|
||||
// so this token always has the same output as `xx`
|
||||
|
||||
case 'xxxx':
|
||||
case 'xx':
|
||||
// Hours and minutes without `:` delimiter
|
||||
return formatTimezone(timezoneOffset);
|
||||
// Hours, minutes and optional seconds with `:` delimiter
|
||||
// Note: neither ISO-8601 nor JavaScript supports seconds in timezone offsets
|
||||
// so this token always has the same output as `xxx`
|
||||
|
||||
case 'xxxxx':
|
||||
case 'xxx': // Hours and minutes with `:` delimiter
|
||||
|
||||
default:
|
||||
return formatTimezone(timezoneOffset, ':');
|
||||
}
|
||||
},
|
||||
// Timezone (GMT)
|
||||
O: function (date, token, _localize, options) {
|
||||
var originalDate = options._originalDate || date;
|
||||
var timezoneOffset = originalDate.getTimezoneOffset();
|
||||
|
||||
switch (token) {
|
||||
// Short
|
||||
case 'O':
|
||||
case 'OO':
|
||||
case 'OOO':
|
||||
return 'GMT' + formatTimezoneShort(timezoneOffset, ':');
|
||||
// Long
|
||||
|
||||
case 'OOOO':
|
||||
default:
|
||||
return 'GMT' + formatTimezone(timezoneOffset, ':');
|
||||
}
|
||||
},
|
||||
// Timezone (specific non-location)
|
||||
z: function (date, token, _localize, options) {
|
||||
var originalDate = options._originalDate || date;
|
||||
var timezoneOffset = originalDate.getTimezoneOffset();
|
||||
|
||||
switch (token) {
|
||||
// Short
|
||||
case 'z':
|
||||
case 'zz':
|
||||
case 'zzz':
|
||||
return 'GMT' + formatTimezoneShort(timezoneOffset, ':');
|
||||
// Long
|
||||
|
||||
case 'zzzz':
|
||||
default:
|
||||
return 'GMT' + formatTimezone(timezoneOffset, ':');
|
||||
}
|
||||
},
|
||||
// Seconds timestamp
|
||||
t: function (date, token, _localize, options) {
|
||||
var originalDate = options._originalDate || date;
|
||||
var timestamp = Math.floor(originalDate.getTime() / 1000);
|
||||
return (0, _index7.default)(timestamp, token.length);
|
||||
},
|
||||
// Milliseconds timestamp
|
||||
T: function (date, token, _localize, options) {
|
||||
var originalDate = options._originalDate || date;
|
||||
var timestamp = originalDate.getTime();
|
||||
return (0, _index7.default)(timestamp, token.length);
|
||||
}
|
||||
};
|
||||
|
||||
function formatTimezoneShort(offset, dirtyDelimiter) {
|
||||
var sign = offset > 0 ? '-' : '+';
|
||||
var absOffset = Math.abs(offset);
|
||||
var hours = Math.floor(absOffset / 60);
|
||||
var minutes = absOffset % 60;
|
||||
|
||||
if (minutes === 0) {
|
||||
return sign + String(hours);
|
||||
}
|
||||
|
||||
var delimiter = dirtyDelimiter || '';
|
||||
return sign + String(hours) + delimiter + (0, _index7.default)(minutes, 2);
|
||||
}
|
||||
|
||||
function formatTimezoneWithOptionalMinutes(offset, dirtyDelimiter) {
|
||||
if (offset % 60 === 0) {
|
||||
var sign = offset > 0 ? '-' : '+';
|
||||
return sign + (0, _index7.default)(Math.abs(offset) / 60, 2);
|
||||
}
|
||||
|
||||
return formatTimezone(offset, dirtyDelimiter);
|
||||
}
|
||||
|
||||
function formatTimezone(offset, dirtyDelimiter) {
|
||||
var delimiter = dirtyDelimiter || '';
|
||||
var sign = offset > 0 ? '-' : '+';
|
||||
var absOffset = Math.abs(offset);
|
||||
var hours = (0, _index7.default)(Math.floor(absOffset / 60), 2);
|
||||
var minutes = (0, _index7.default)(absOffset % 60, 2);
|
||||
return sign + hours + delimiter + minutes;
|
||||
}
|
||||
|
||||
var _default = formatters;
|
||||
exports.default = _default;
|
||||
module.exports = exports.default;
|
||||
+93
@@ -0,0 +1,93 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.default = void 0;
|
||||
|
||||
var _index = _interopRequireDefault(require("../../addLeadingZeros/index.js"));
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
|
||||
/*
|
||||
* | | Unit | | Unit |
|
||||
* |-----|--------------------------------|-----|--------------------------------|
|
||||
* | a | AM, PM | A* | |
|
||||
* | d | Day of month | D | |
|
||||
* | h | Hour [1-12] | H | Hour [0-23] |
|
||||
* | m | Minute | M | Month |
|
||||
* | s | Second | S | Fraction of second |
|
||||
* | y | Year (abs) | Y | |
|
||||
*
|
||||
* Letters marked by * are not implemented but reserved by Unicode standard.
|
||||
*/
|
||||
var formatters = {
|
||||
// Year
|
||||
y: function (date, token) {
|
||||
// From http://www.unicode.org/reports/tr35/tr35-31/tr35-dates.html#Date_Format_tokens
|
||||
// | Year | y | yy | yyy | yyyy | yyyyy |
|
||||
// |----------|-------|----|-------|-------|-------|
|
||||
// | AD 1 | 1 | 01 | 001 | 0001 | 00001 |
|
||||
// | AD 12 | 12 | 12 | 012 | 0012 | 00012 |
|
||||
// | AD 123 | 123 | 23 | 123 | 0123 | 00123 |
|
||||
// | AD 1234 | 1234 | 34 | 1234 | 1234 | 01234 |
|
||||
// | AD 12345 | 12345 | 45 | 12345 | 12345 | 12345 |
|
||||
var signedYear = date.getUTCFullYear(); // Returns 1 for 1 BC (which is year 0 in JavaScript)
|
||||
|
||||
var year = signedYear > 0 ? signedYear : 1 - signedYear;
|
||||
return (0, _index.default)(token === 'yy' ? year % 100 : year, token.length);
|
||||
},
|
||||
// Month
|
||||
M: function (date, token) {
|
||||
var month = date.getUTCMonth();
|
||||
return token === 'M' ? String(month + 1) : (0, _index.default)(month + 1, 2);
|
||||
},
|
||||
// Day of the month
|
||||
d: function (date, token) {
|
||||
return (0, _index.default)(date.getUTCDate(), token.length);
|
||||
},
|
||||
// AM or PM
|
||||
a: function (date, token) {
|
||||
var dayPeriodEnumValue = date.getUTCHours() / 12 >= 1 ? 'pm' : 'am';
|
||||
|
||||
switch (token) {
|
||||
case 'a':
|
||||
case 'aa':
|
||||
case 'aaa':
|
||||
return dayPeriodEnumValue.toUpperCase();
|
||||
|
||||
case 'aaaaa':
|
||||
return dayPeriodEnumValue[0];
|
||||
|
||||
case 'aaaa':
|
||||
default:
|
||||
return dayPeriodEnumValue === 'am' ? 'a.m.' : 'p.m.';
|
||||
}
|
||||
},
|
||||
// Hour [1-12]
|
||||
h: function (date, token) {
|
||||
return (0, _index.default)(date.getUTCHours() % 12 || 12, token.length);
|
||||
},
|
||||
// Hour [0-23]
|
||||
H: function (date, token) {
|
||||
return (0, _index.default)(date.getUTCHours(), token.length);
|
||||
},
|
||||
// Minute
|
||||
m: function (date, token) {
|
||||
return (0, _index.default)(date.getUTCMinutes(), token.length);
|
||||
},
|
||||
// Second
|
||||
s: function (date, token) {
|
||||
return (0, _index.default)(date.getUTCSeconds(), token.length);
|
||||
},
|
||||
// Fraction of second
|
||||
S: function (date, token) {
|
||||
var numberOfDigits = token.length;
|
||||
var milliseconds = date.getUTCMilliseconds();
|
||||
var fractionalSeconds = Math.floor(milliseconds * Math.pow(10, numberOfDigits - 3));
|
||||
return (0, _index.default)(fractionalSeconds, token.length);
|
||||
}
|
||||
};
|
||||
var _default = formatters;
|
||||
exports.default = _default;
|
||||
module.exports = exports.default;
|
||||
+105
@@ -0,0 +1,105 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.default = void 0;
|
||||
|
||||
function dateLongFormatter(pattern, formatLong) {
|
||||
switch (pattern) {
|
||||
case 'P':
|
||||
return formatLong.date({
|
||||
width: 'short'
|
||||
});
|
||||
|
||||
case 'PP':
|
||||
return formatLong.date({
|
||||
width: 'medium'
|
||||
});
|
||||
|
||||
case 'PPP':
|
||||
return formatLong.date({
|
||||
width: 'long'
|
||||
});
|
||||
|
||||
case 'PPPP':
|
||||
default:
|
||||
return formatLong.date({
|
||||
width: 'full'
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
function timeLongFormatter(pattern, formatLong) {
|
||||
switch (pattern) {
|
||||
case 'p':
|
||||
return formatLong.time({
|
||||
width: 'short'
|
||||
});
|
||||
|
||||
case 'pp':
|
||||
return formatLong.time({
|
||||
width: 'medium'
|
||||
});
|
||||
|
||||
case 'ppp':
|
||||
return formatLong.time({
|
||||
width: 'long'
|
||||
});
|
||||
|
||||
case 'pppp':
|
||||
default:
|
||||
return formatLong.time({
|
||||
width: 'full'
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
function dateTimeLongFormatter(pattern, formatLong) {
|
||||
var matchResult = pattern.match(/(P+)(p+)?/);
|
||||
var datePattern = matchResult[1];
|
||||
var timePattern = matchResult[2];
|
||||
|
||||
if (!timePattern) {
|
||||
return dateLongFormatter(pattern, formatLong);
|
||||
}
|
||||
|
||||
var dateTimeFormat;
|
||||
|
||||
switch (datePattern) {
|
||||
case 'P':
|
||||
dateTimeFormat = formatLong.dateTime({
|
||||
width: 'short'
|
||||
});
|
||||
break;
|
||||
|
||||
case 'PP':
|
||||
dateTimeFormat = formatLong.dateTime({
|
||||
width: 'medium'
|
||||
});
|
||||
break;
|
||||
|
||||
case 'PPP':
|
||||
dateTimeFormat = formatLong.dateTime({
|
||||
width: 'long'
|
||||
});
|
||||
break;
|
||||
|
||||
case 'PPPP':
|
||||
default:
|
||||
dateTimeFormat = formatLong.dateTime({
|
||||
width: 'full'
|
||||
});
|
||||
break;
|
||||
}
|
||||
|
||||
return dateTimeFormat.replace('{{date}}', dateLongFormatter(datePattern, formatLong)).replace('{{time}}', timeLongFormatter(timePattern, formatLong));
|
||||
}
|
||||
|
||||
var longFormatters = {
|
||||
p: timeLongFormatter,
|
||||
P: dateTimeLongFormatter
|
||||
};
|
||||
var _default = longFormatters;
|
||||
exports.default = _default;
|
||||
module.exports = exports.default;
|
||||
Generated
Vendored
+28
@@ -0,0 +1,28 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.default = getTimezoneOffsetInMilliseconds;
|
||||
var MILLISECONDS_IN_MINUTE = 60000;
|
||||
/**
|
||||
* Google Chrome as of 67.0.3396.87 introduced timezones with offset that includes seconds.
|
||||
* They usually appear for dates that denote time before the timezones were introduced
|
||||
* (e.g. for 'Europe/Prague' timezone the offset is GMT+00:57:44 before 1 October 1891
|
||||
* and GMT+01:00:00 after that date)
|
||||
*
|
||||
* Date#getTimezoneOffset returns the offset in minutes and would return 57 for the example above,
|
||||
* which would lead to incorrect calculations.
|
||||
*
|
||||
* This function returns the timezone offset in milliseconds that takes seconds in account.
|
||||
*/
|
||||
|
||||
function getTimezoneOffsetInMilliseconds(dirtyDate) {
|
||||
var date = new Date(dirtyDate.getTime());
|
||||
var baseTimezoneOffset = Math.ceil(date.getTimezoneOffset());
|
||||
date.setSeconds(0, 0);
|
||||
var millisecondsPartOfTimezoneOffset = date.getTime() % MILLISECONDS_IN_MINUTE;
|
||||
return baseTimezoneOffset * MILLISECONDS_IN_MINUTE + millisecondsPartOfTimezoneOffset;
|
||||
}
|
||||
|
||||
module.exports = exports.default;
|
||||
+29
@@ -0,0 +1,29 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.default = getUTCDayOfYear;
|
||||
|
||||
var _index = _interopRequireDefault(require("../../toDate/index.js"));
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
|
||||
var MILLISECONDS_IN_DAY = 86400000; // This function will be a part of public API when UTC function will be implemented.
|
||||
// See issue: https://github.com/date-fns/date-fns/issues/376
|
||||
|
||||
function getUTCDayOfYear(dirtyDate) {
|
||||
if (arguments.length < 1) {
|
||||
throw new TypeError('1 argument required, but only ' + arguments.length + ' present');
|
||||
}
|
||||
|
||||
var date = (0, _index.default)(dirtyDate);
|
||||
var timestamp = date.getTime();
|
||||
date.setUTCMonth(0, 1);
|
||||
date.setUTCHours(0, 0, 0, 0);
|
||||
var startOfYearTimestamp = date.getTime();
|
||||
var difference = timestamp - startOfYearTimestamp;
|
||||
return Math.floor(difference / MILLISECONDS_IN_DAY) + 1;
|
||||
}
|
||||
|
||||
module.exports = exports.default;
|
||||
+32
@@ -0,0 +1,32 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.default = getUTCISOWeek;
|
||||
|
||||
var _index = _interopRequireDefault(require("../../toDate/index.js"));
|
||||
|
||||
var _index2 = _interopRequireDefault(require("../startOfUTCISOWeek/index.js"));
|
||||
|
||||
var _index3 = _interopRequireDefault(require("../startOfUTCISOWeekYear/index.js"));
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
|
||||
var MILLISECONDS_IN_WEEK = 604800000; // This function will be a part of public API when UTC function will be implemented.
|
||||
// See issue: https://github.com/date-fns/date-fns/issues/376
|
||||
|
||||
function getUTCISOWeek(dirtyDate) {
|
||||
if (arguments.length < 1) {
|
||||
throw new TypeError('1 argument required, but only ' + arguments.length + ' present');
|
||||
}
|
||||
|
||||
var date = (0, _index.default)(dirtyDate);
|
||||
var diff = (0, _index2.default)(date).getTime() - (0, _index3.default)(date).getTime(); // Round the number of days to the nearest integer
|
||||
// because the number of milliseconds in a week is not constant
|
||||
// (e.g. it's different in the week of the daylight saving time clock shift)
|
||||
|
||||
return Math.round(diff / MILLISECONDS_IN_WEEK) + 1;
|
||||
}
|
||||
|
||||
module.exports = exports.default;
|
||||
+41
@@ -0,0 +1,41 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.default = getUTCISOWeekYear;
|
||||
|
||||
var _index = _interopRequireDefault(require("../../toDate/index.js"));
|
||||
|
||||
var _index2 = _interopRequireDefault(require("../startOfUTCISOWeek/index.js"));
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
|
||||
// This function will be a part of public API when UTC function will be implemented.
|
||||
// See issue: https://github.com/date-fns/date-fns/issues/376
|
||||
function getUTCISOWeekYear(dirtyDate) {
|
||||
if (arguments.length < 1) {
|
||||
throw new TypeError('1 argument required, but only ' + arguments.length + ' present');
|
||||
}
|
||||
|
||||
var date = (0, _index.default)(dirtyDate);
|
||||
var year = date.getUTCFullYear();
|
||||
var fourthOfJanuaryOfNextYear = new Date(0);
|
||||
fourthOfJanuaryOfNextYear.setUTCFullYear(year + 1, 0, 4);
|
||||
fourthOfJanuaryOfNextYear.setUTCHours(0, 0, 0, 0);
|
||||
var startOfNextYear = (0, _index2.default)(fourthOfJanuaryOfNextYear);
|
||||
var fourthOfJanuaryOfThisYear = new Date(0);
|
||||
fourthOfJanuaryOfThisYear.setUTCFullYear(year, 0, 4);
|
||||
fourthOfJanuaryOfThisYear.setUTCHours(0, 0, 0, 0);
|
||||
var startOfThisYear = (0, _index2.default)(fourthOfJanuaryOfThisYear);
|
||||
|
||||
if (date.getTime() >= startOfNextYear.getTime()) {
|
||||
return year + 1;
|
||||
} else if (date.getTime() >= startOfThisYear.getTime()) {
|
||||
return year;
|
||||
} else {
|
||||
return year - 1;
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = exports.default;
|
||||
+32
@@ -0,0 +1,32 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.default = getUTCWeek;
|
||||
|
||||
var _index = _interopRequireDefault(require("../../toDate/index.js"));
|
||||
|
||||
var _index2 = _interopRequireDefault(require("../startOfUTCWeek/index.js"));
|
||||
|
||||
var _index3 = _interopRequireDefault(require("../startOfUTCWeekYear/index.js"));
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
|
||||
var MILLISECONDS_IN_WEEK = 604800000; // This function will be a part of public API when UTC function will be implemented.
|
||||
// See issue: https://github.com/date-fns/date-fns/issues/376
|
||||
|
||||
function getUTCWeek(dirtyDate, options) {
|
||||
if (arguments.length < 1) {
|
||||
throw new TypeError('1 argument required, but only ' + arguments.length + ' present');
|
||||
}
|
||||
|
||||
var date = (0, _index.default)(dirtyDate);
|
||||
var diff = (0, _index2.default)(date, options).getTime() - (0, _index3.default)(date, options).getTime(); // Round the number of days to the nearest integer
|
||||
// because the number of milliseconds in a week is not constant
|
||||
// (e.g. it's different in the week of the daylight saving time clock shift)
|
||||
|
||||
return Math.round(diff / MILLISECONDS_IN_WEEK) + 1;
|
||||
}
|
||||
|
||||
module.exports = exports.default;
|
||||
+53
@@ -0,0 +1,53 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.default = getUTCWeekYear;
|
||||
|
||||
var _index = _interopRequireDefault(require("../toInteger/index.js"));
|
||||
|
||||
var _index2 = _interopRequireDefault(require("../../toDate/index.js"));
|
||||
|
||||
var _index3 = _interopRequireDefault(require("../startOfUTCWeek/index.js"));
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
|
||||
// This function will be a part of public API when UTC function will be implemented.
|
||||
// See issue: https://github.com/date-fns/date-fns/issues/376
|
||||
function getUTCWeekYear(dirtyDate, dirtyOptions) {
|
||||
if (arguments.length < 1) {
|
||||
throw new TypeError('1 argument required, but only ' + arguments.length + ' present');
|
||||
}
|
||||
|
||||
var date = (0, _index2.default)(dirtyDate, dirtyOptions);
|
||||
var year = date.getUTCFullYear();
|
||||
var options = dirtyOptions || {};
|
||||
var locale = options.locale;
|
||||
var localeFirstWeekContainsDate = locale && locale.options && locale.options.firstWeekContainsDate;
|
||||
var defaultFirstWeekContainsDate = localeFirstWeekContainsDate == null ? 1 : (0, _index.default)(localeFirstWeekContainsDate);
|
||||
var firstWeekContainsDate = options.firstWeekContainsDate == null ? defaultFirstWeekContainsDate : (0, _index.default)(options.firstWeekContainsDate); // Test if weekStartsOn is between 1 and 7 _and_ is not NaN
|
||||
|
||||
if (!(firstWeekContainsDate >= 1 && firstWeekContainsDate <= 7)) {
|
||||
throw new RangeError('firstWeekContainsDate must be between 1 and 7 inclusively');
|
||||
}
|
||||
|
||||
var firstWeekOfNextYear = new Date(0);
|
||||
firstWeekOfNextYear.setUTCFullYear(year + 1, 0, firstWeekContainsDate);
|
||||
firstWeekOfNextYear.setUTCHours(0, 0, 0, 0);
|
||||
var startOfNextYear = (0, _index3.default)(firstWeekOfNextYear, dirtyOptions);
|
||||
var firstWeekOfThisYear = new Date(0);
|
||||
firstWeekOfThisYear.setUTCFullYear(year, 0, firstWeekContainsDate);
|
||||
firstWeekOfThisYear.setUTCHours(0, 0, 0, 0);
|
||||
var startOfThisYear = (0, _index3.default)(firstWeekOfThisYear, dirtyOptions);
|
||||
|
||||
if (date.getTime() >= startOfNextYear.getTime()) {
|
||||
return year + 1;
|
||||
} else if (date.getTime() >= startOfThisYear.getTime()) {
|
||||
return year;
|
||||
} else {
|
||||
return year - 1;
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = exports.default;
|
||||
+24
@@ -0,0 +1,24 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.default = isSameUTCWeek;
|
||||
|
||||
var _index = _interopRequireDefault(require("../startOfUTCWeek/index.js"));
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
|
||||
// This function will be a part of public API when UTC function will be implemented.
|
||||
// See issue: https://github.com/date-fns/date-fns/issues/376
|
||||
function isSameUTCWeek(dirtyDateLeft, dirtyDateRight, options) {
|
||||
if (arguments.length < 2) {
|
||||
throw new TypeError('2 argument required, but only ' + arguments.length + ' present');
|
||||
}
|
||||
|
||||
var dateLeftStartOfWeek = (0, _index.default)(dirtyDateLeft, options);
|
||||
var dateRightStartOfWeek = (0, _index.default)(dirtyDateRight, options);
|
||||
return dateLeftStartOfWeek.getTime() === dateRightStartOfWeek.getTime();
|
||||
}
|
||||
|
||||
module.exports = exports.default;
|
||||
+30
@@ -0,0 +1,30 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.isProtectedDayOfYearToken = isProtectedDayOfYearToken;
|
||||
exports.isProtectedWeekYearToken = isProtectedWeekYearToken;
|
||||
exports.throwProtectedError = throwProtectedError;
|
||||
var protectedDayOfYearTokens = ['D', 'DD'];
|
||||
var protectedWeekYearTokens = ['YY', 'YYYY'];
|
||||
|
||||
function isProtectedDayOfYearToken(token) {
|
||||
return protectedDayOfYearTokens.indexOf(token) !== -1;
|
||||
}
|
||||
|
||||
function isProtectedWeekYearToken(token) {
|
||||
return protectedWeekYearTokens.indexOf(token) !== -1;
|
||||
}
|
||||
|
||||
function throwProtectedError(token) {
|
||||
if (token === 'YYYY') {
|
||||
throw new RangeError('Use `yyyy` instead of `YYYY` for formatting years; see: https://git.io/fxCyr');
|
||||
} else if (token === 'YY') {
|
||||
throw new RangeError('Use `yy` instead of `YY` for formatting years; see: https://git.io/fxCyr');
|
||||
} else if (token === 'D') {
|
||||
throw new RangeError('Use `d` instead of `D` for formatting days of the month; see: https://git.io/fxCyr');
|
||||
} else if (token === 'DD') {
|
||||
throw new RangeError('Use `dd` instead of `DD` for formatting days of the month; see: https://git.io/fxCyr');
|
||||
}
|
||||
}
|
||||
+41
@@ -0,0 +1,41 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.default = setUTCDay;
|
||||
|
||||
var _index = _interopRequireDefault(require("../toInteger/index.js"));
|
||||
|
||||
var _index2 = _interopRequireDefault(require("../../toDate/index.js"));
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
|
||||
// This function will be a part of public API when UTC function will be implemented.
|
||||
// See issue: https://github.com/date-fns/date-fns/issues/376
|
||||
function setUTCDay(dirtyDate, dirtyDay, dirtyOptions) {
|
||||
if (arguments.length < 2) {
|
||||
throw new TypeError('2 arguments required, but only ' + arguments.length + ' present');
|
||||
}
|
||||
|
||||
var options = dirtyOptions || {};
|
||||
var locale = options.locale;
|
||||
var localeWeekStartsOn = locale && locale.options && locale.options.weekStartsOn;
|
||||
var defaultWeekStartsOn = localeWeekStartsOn == null ? 0 : (0, _index.default)(localeWeekStartsOn);
|
||||
var weekStartsOn = options.weekStartsOn == null ? defaultWeekStartsOn : (0, _index.default)(options.weekStartsOn); // Test if weekStartsOn is between 0 and 6 _and_ is not NaN
|
||||
|
||||
if (!(weekStartsOn >= 0 && weekStartsOn <= 6)) {
|
||||
throw new RangeError('weekStartsOn must be between 0 and 6 inclusively');
|
||||
}
|
||||
|
||||
var date = (0, _index2.default)(dirtyDate);
|
||||
var day = (0, _index.default)(dirtyDay);
|
||||
var currentDay = date.getUTCDay();
|
||||
var remainder = day % 7;
|
||||
var dayIndex = (remainder + 7) % 7;
|
||||
var diff = (dayIndex < weekStartsOn ? 7 : 0) + day - currentDay;
|
||||
date.setUTCDate(date.getUTCDate() + diff);
|
||||
return date;
|
||||
}
|
||||
|
||||
module.exports = exports.default;
|
||||
+37
@@ -0,0 +1,37 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.default = setUTCISODay;
|
||||
|
||||
var _index = _interopRequireDefault(require("../toInteger/index.js"));
|
||||
|
||||
var _index2 = _interopRequireDefault(require("../../toDate/index.js"));
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
|
||||
// This function will be a part of public API when UTC function will be implemented.
|
||||
// See issue: https://github.com/date-fns/date-fns/issues/376
|
||||
function setUTCISODay(dirtyDate, dirtyDay) {
|
||||
if (arguments.length < 2) {
|
||||
throw new TypeError('2 arguments required, but only ' + arguments.length + ' present');
|
||||
}
|
||||
|
||||
var day = (0, _index.default)(dirtyDay);
|
||||
|
||||
if (day % 7 === 0) {
|
||||
day = day - 7;
|
||||
}
|
||||
|
||||
var weekStartsOn = 1;
|
||||
var date = (0, _index2.default)(dirtyDate);
|
||||
var currentDay = date.getUTCDay();
|
||||
var remainder = day % 7;
|
||||
var dayIndex = (remainder + 7) % 7;
|
||||
var diff = (dayIndex < weekStartsOn ? 7 : 0) + day - currentDay;
|
||||
date.setUTCDate(date.getUTCDate() + diff);
|
||||
return date;
|
||||
}
|
||||
|
||||
module.exports = exports.default;
|
||||
+30
@@ -0,0 +1,30 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.default = setUTCISOWeek;
|
||||
|
||||
var _index = _interopRequireDefault(require("../toInteger/index.js"));
|
||||
|
||||
var _index2 = _interopRequireDefault(require("../../toDate/index.js"));
|
||||
|
||||
var _index3 = _interopRequireDefault(require("../getUTCISOWeek/index.js"));
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
|
||||
// This function will be a part of public API when UTC function will be implemented.
|
||||
// See issue: https://github.com/date-fns/date-fns/issues/376
|
||||
function setUTCISOWeek(dirtyDate, dirtyISOWeek) {
|
||||
if (arguments.length < 2) {
|
||||
throw new TypeError('2 arguments required, but only ' + arguments.length + ' present');
|
||||
}
|
||||
|
||||
var date = (0, _index2.default)(dirtyDate);
|
||||
var isoWeek = (0, _index.default)(dirtyISOWeek);
|
||||
var diff = (0, _index3.default)(date) - isoWeek;
|
||||
date.setUTCDate(date.getUTCDate() - diff * 7);
|
||||
return date;
|
||||
}
|
||||
|
||||
module.exports = exports.default;
|
||||
+30
@@ -0,0 +1,30 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.default = setUTCWeek;
|
||||
|
||||
var _index = _interopRequireDefault(require("../toInteger/index.js"));
|
||||
|
||||
var _index2 = _interopRequireDefault(require("../../toDate/index.js"));
|
||||
|
||||
var _index3 = _interopRequireDefault(require("../getUTCWeek/index.js"));
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
|
||||
// This function will be a part of public API when UTC function will be implemented.
|
||||
// See issue: https://github.com/date-fns/date-fns/issues/376
|
||||
function setUTCWeek(dirtyDate, dirtyWeek, options) {
|
||||
if (arguments.length < 2) {
|
||||
throw new TypeError('2 arguments required, but only ' + arguments.length + ' present');
|
||||
}
|
||||
|
||||
var date = (0, _index2.default)(dirtyDate);
|
||||
var week = (0, _index.default)(dirtyWeek);
|
||||
var diff = (0, _index3.default)(date, options) - week;
|
||||
date.setUTCDate(date.getUTCDate() - diff * 7);
|
||||
return date;
|
||||
}
|
||||
|
||||
module.exports = exports.default;
|
||||
+28
@@ -0,0 +1,28 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.default = startOfUTCISOWeek;
|
||||
|
||||
var _index = _interopRequireDefault(require("../../toDate/index.js"));
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
|
||||
// This function will be a part of public API when UTC function will be implemented.
|
||||
// See issue: https://github.com/date-fns/date-fns/issues/376
|
||||
function startOfUTCISOWeek(dirtyDate) {
|
||||
if (arguments.length < 1) {
|
||||
throw new TypeError('1 argument required, but only ' + arguments.length + ' present');
|
||||
}
|
||||
|
||||
var weekStartsOn = 1;
|
||||
var date = (0, _index.default)(dirtyDate);
|
||||
var day = date.getUTCDay();
|
||||
var diff = (day < weekStartsOn ? 7 : 0) + day - weekStartsOn;
|
||||
date.setUTCDate(date.getUTCDate() - diff);
|
||||
date.setUTCHours(0, 0, 0, 0);
|
||||
return date;
|
||||
}
|
||||
|
||||
module.exports = exports.default;
|
||||
+29
@@ -0,0 +1,29 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.default = startOfUTCISOWeekYear;
|
||||
|
||||
var _index = _interopRequireDefault(require("../getUTCISOWeekYear/index.js"));
|
||||
|
||||
var _index2 = _interopRequireDefault(require("../startOfUTCISOWeek/index.js"));
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
|
||||
// This function will be a part of public API when UTC function will be implemented.
|
||||
// See issue: https://github.com/date-fns/date-fns/issues/376
|
||||
function startOfUTCISOWeekYear(dirtyDate) {
|
||||
if (arguments.length < 1) {
|
||||
throw new TypeError('1 argument required, but only ' + arguments.length + ' present');
|
||||
}
|
||||
|
||||
var year = (0, _index.default)(dirtyDate);
|
||||
var fourthOfJanuary = new Date(0);
|
||||
fourthOfJanuary.setUTCFullYear(year, 0, 4);
|
||||
fourthOfJanuary.setUTCHours(0, 0, 0, 0);
|
||||
var date = (0, _index2.default)(fourthOfJanuary);
|
||||
return date;
|
||||
}
|
||||
|
||||
module.exports = exports.default;
|
||||
+39
@@ -0,0 +1,39 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.default = startOfUTCWeek;
|
||||
|
||||
var _index = _interopRequireDefault(require("../toInteger/index.js"));
|
||||
|
||||
var _index2 = _interopRequireDefault(require("../../toDate/index.js"));
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
|
||||
// This function will be a part of public API when UTC function will be implemented.
|
||||
// See issue: https://github.com/date-fns/date-fns/issues/376
|
||||
function startOfUTCWeek(dirtyDate, dirtyOptions) {
|
||||
if (arguments.length < 1) {
|
||||
throw new TypeError('1 argument required, but only ' + arguments.length + ' present');
|
||||
}
|
||||
|
||||
var options = dirtyOptions || {};
|
||||
var locale = options.locale;
|
||||
var localeWeekStartsOn = locale && locale.options && locale.options.weekStartsOn;
|
||||
var defaultWeekStartsOn = localeWeekStartsOn == null ? 0 : (0, _index.default)(localeWeekStartsOn);
|
||||
var weekStartsOn = options.weekStartsOn == null ? defaultWeekStartsOn : (0, _index.default)(options.weekStartsOn); // Test if weekStartsOn is between 0 and 6 _and_ is not NaN
|
||||
|
||||
if (!(weekStartsOn >= 0 && weekStartsOn <= 6)) {
|
||||
throw new RangeError('weekStartsOn must be between 0 and 6 inclusively');
|
||||
}
|
||||
|
||||
var date = (0, _index2.default)(dirtyDate);
|
||||
var day = date.getUTCDay();
|
||||
var diff = (day < weekStartsOn ? 7 : 0) + day - weekStartsOn;
|
||||
date.setUTCDate(date.getUTCDate() - diff);
|
||||
date.setUTCHours(0, 0, 0, 0);
|
||||
return date;
|
||||
}
|
||||
|
||||
module.exports = exports.default;
|
||||
+36
@@ -0,0 +1,36 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.default = startOfUTCWeekYear;
|
||||
|
||||
var _index = _interopRequireDefault(require("../toInteger/index.js"));
|
||||
|
||||
var _index2 = _interopRequireDefault(require("../getUTCWeekYear/index.js"));
|
||||
|
||||
var _index3 = _interopRequireDefault(require("../startOfUTCWeek/index.js"));
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
|
||||
// This function will be a part of public API when UTC function will be implemented.
|
||||
// See issue: https://github.com/date-fns/date-fns/issues/376
|
||||
function startOfUTCWeekYear(dirtyDate, dirtyOptions) {
|
||||
if (arguments.length < 1) {
|
||||
throw new TypeError('1 argument required, but only ' + arguments.length + ' present');
|
||||
}
|
||||
|
||||
var options = dirtyOptions || {};
|
||||
var locale = options.locale;
|
||||
var localeFirstWeekContainsDate = locale && locale.options && locale.options.firstWeekContainsDate;
|
||||
var defaultFirstWeekContainsDate = localeFirstWeekContainsDate == null ? 1 : (0, _index.default)(localeFirstWeekContainsDate);
|
||||
var firstWeekContainsDate = options.firstWeekContainsDate == null ? defaultFirstWeekContainsDate : (0, _index.default)(options.firstWeekContainsDate);
|
||||
var year = (0, _index2.default)(dirtyDate, dirtyOptions);
|
||||
var firstWeek = new Date(0);
|
||||
firstWeek.setUTCFullYear(year, 0, firstWeekContainsDate);
|
||||
firstWeek.setUTCHours(0, 0, 0, 0);
|
||||
var date = (0, _index3.default)(firstWeek, dirtyOptions);
|
||||
return date;
|
||||
}
|
||||
|
||||
module.exports = exports.default;
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.default = toInteger;
|
||||
|
||||
function toInteger(dirtyNumber) {
|
||||
if (dirtyNumber === null || dirtyNumber === true || dirtyNumber === false) {
|
||||
return NaN;
|
||||
}
|
||||
|
||||
var number = Number(dirtyNumber);
|
||||
|
||||
if (isNaN(number)) {
|
||||
return number;
|
||||
}
|
||||
|
||||
return number < 0 ? Math.ceil(number) : Math.floor(number);
|
||||
}
|
||||
|
||||
module.exports = exports.default;
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
// This file is generated automatically by `scripts/build/typings.js`. Please, don't change it.
|
||||
|
||||
import { addBusinessDays } from 'date-fns'
|
||||
export default addBusinessDays
|
||||
+58
@@ -0,0 +1,58 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.default = addBusinessDays;
|
||||
|
||||
var _index = _interopRequireDefault(require("../isWeekend/index.js"));
|
||||
|
||||
var _index2 = _interopRequireDefault(require("../toDate/index.js"));
|
||||
|
||||
var _index3 = _interopRequireDefault(require("../_lib/toInteger/index.js"));
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
|
||||
/**
|
||||
* @name addBusinessDays
|
||||
* @category Day Helpers
|
||||
* @summary Add the specified number of business days (mon - fri) to the given date.
|
||||
*
|
||||
* @description
|
||||
* Add the specified number of business days (mon - fri) to the given date, ignoring weekends.
|
||||
*
|
||||
* @param {Date|Number} date - the date to be changed
|
||||
* @param {Number} amount - the amount of business days to be added
|
||||
* @returns {Date} the new date with the business days added
|
||||
* @throws {TypeError} 2 arguments required
|
||||
*
|
||||
* @example
|
||||
* // Add 10 business days to 1 September 2014:
|
||||
* var result = addBusinessDays(new Date(2014, 8, 1), 10)
|
||||
* //=> Mon Sep 15 2014 00:00:00 (skipped weekend days)
|
||||
*/
|
||||
function addBusinessDays(dirtyDate, dirtyAmount) {
|
||||
if (arguments.length < 2) {
|
||||
throw new TypeError('2 arguments required, but only ' + arguments.length + ' present');
|
||||
}
|
||||
|
||||
var date = (0, _index2.default)(dirtyDate);
|
||||
var amount = (0, _index3.default)(dirtyAmount);
|
||||
if (isNaN(amount)) return new Date(NaN);
|
||||
var hours = date.getHours();
|
||||
var sign = amount < 0 ? -1 : 1;
|
||||
date.setDate(date.getDate() + (0, _index3.default)(amount / 5) * 7);
|
||||
amount %= 5; // to get remaining days not part of a full week
|
||||
|
||||
var shiftSize = Math.abs(amount); // only loops over remaining days or if day is a weekend, ensures a business day is returned
|
||||
|
||||
while (shiftSize > 0 || (0, _index.default)(date)) {
|
||||
if (!(0, _index.default)(date)) shiftSize -= 1;
|
||||
date.setDate(date.getDate() + sign);
|
||||
}
|
||||
|
||||
date.setHours(hours);
|
||||
return date;
|
||||
}
|
||||
|
||||
module.exports = exports.default;
|
||||
+38
@@ -0,0 +1,38 @@
|
||||
// @flow
|
||||
// This file is generated automatically by `scripts/build/typings.js`. Please, don't change it.
|
||||
|
||||
export type Interval = {
|
||||
start: Date | number,
|
||||
end: Date | number
|
||||
}
|
||||
|
||||
export type Locale = {
|
||||
formatDistance: (...args: Array<any>) => any,
|
||||
formatRelative: (...args: Array<any>) => any,
|
||||
localize: {
|
||||
ordinalNumber: (...args: Array<any>) => any,
|
||||
era: (...args: Array<any>) => any,
|
||||
quarter: (...args: Array<any>) => any,
|
||||
month: (...args: Array<any>) => any,
|
||||
day: (...args: Array<any>) => any,
|
||||
dayPeriod: (...args: Array<any>) => any
|
||||
},
|
||||
formatLong: Object,
|
||||
date: (...args: Array<any>) => any,
|
||||
time: (...args: Array<any>) => any,
|
||||
dateTime: (...args: Array<any>) => any,
|
||||
match: {
|
||||
ordinalNumber: (...args: Array<any>) => any,
|
||||
era: (...args: Array<any>) => any,
|
||||
quarter: (...args: Array<any>) => any,
|
||||
month: (...args: Array<any>) => any,
|
||||
day: (...args: Array<any>) => any,
|
||||
dayPeriod: (...args: Array<any>) => any
|
||||
},
|
||||
options?: {
|
||||
weekStartsOn?: 0 | 1 | 2 | 3 | 4 | 5 | 6,
|
||||
firstWeekContainsDate?: 1 | 2 | 3 | 4 | 5 | 6 | 7
|
||||
}
|
||||
}
|
||||
|
||||
declare module.exports: (date: Date | number, amount: number) => Date
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"sideEffects": false,
|
||||
"module": "../esm/addBusinessDays/index.js",
|
||||
"typings": "../typings.d.ts"
|
||||
}
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
// This file is generated automatically by `scripts/build/typings.js`. Please, don't change it.
|
||||
|
||||
import { addDays } from 'date-fns'
|
||||
export default addDays
|
||||
+47
@@ -0,0 +1,47 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.default = addDays;
|
||||
|
||||
var _index = _interopRequireDefault(require("../_lib/toInteger/index.js"));
|
||||
|
||||
var _index2 = _interopRequireDefault(require("../toDate/index.js"));
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
|
||||
/**
|
||||
* @name addDays
|
||||
* @category Day Helpers
|
||||
* @summary Add the specified number of days to the given date.
|
||||
*
|
||||
* @description
|
||||
* Add the specified number of days to the given date.
|
||||
*
|
||||
* ### v2.0.0 breaking changes:
|
||||
*
|
||||
* - [Changes that are common for the whole library](https://github.com/date-fns/date-fns/blob/master/docs/upgradeGuide.md#Common-Changes).
|
||||
*
|
||||
* @param {Date|Number} date - the date to be changed
|
||||
* @param {Number} amount - the amount of days to be added
|
||||
* @returns {Date} the new date with the days added
|
||||
* @throws {TypeError} 2 arguments required
|
||||
*
|
||||
* @example
|
||||
* // Add 10 days to 1 September 2014:
|
||||
* var result = addDays(new Date(2014, 8, 1), 10)
|
||||
* //=> Thu Sep 11 2014 00:00:00
|
||||
*/
|
||||
function addDays(dirtyDate, dirtyAmount) {
|
||||
if (arguments.length < 2) {
|
||||
throw new TypeError('2 arguments required, but only ' + arguments.length + ' present');
|
||||
}
|
||||
|
||||
var date = (0, _index2.default)(dirtyDate);
|
||||
var amount = (0, _index.default)(dirtyAmount);
|
||||
date.setDate(date.getDate() + amount);
|
||||
return date;
|
||||
}
|
||||
|
||||
module.exports = exports.default;
|
||||
+38
@@ -0,0 +1,38 @@
|
||||
// @flow
|
||||
// This file is generated automatically by `scripts/build/typings.js`. Please, don't change it.
|
||||
|
||||
export type Interval = {
|
||||
start: Date | number,
|
||||
end: Date | number
|
||||
}
|
||||
|
||||
export type Locale = {
|
||||
formatDistance: (...args: Array<any>) => any,
|
||||
formatRelative: (...args: Array<any>) => any,
|
||||
localize: {
|
||||
ordinalNumber: (...args: Array<any>) => any,
|
||||
era: (...args: Array<any>) => any,
|
||||
quarter: (...args: Array<any>) => any,
|
||||
month: (...args: Array<any>) => any,
|
||||
day: (...args: Array<any>) => any,
|
||||
dayPeriod: (...args: Array<any>) => any
|
||||
},
|
||||
formatLong: Object,
|
||||
date: (...args: Array<any>) => any,
|
||||
time: (...args: Array<any>) => any,
|
||||
dateTime: (...args: Array<any>) => any,
|
||||
match: {
|
||||
ordinalNumber: (...args: Array<any>) => any,
|
||||
era: (...args: Array<any>) => any,
|
||||
quarter: (...args: Array<any>) => any,
|
||||
month: (...args: Array<any>) => any,
|
||||
day: (...args: Array<any>) => any,
|
||||
dayPeriod: (...args: Array<any>) => any
|
||||
},
|
||||
options?: {
|
||||
weekStartsOn?: 0 | 1 | 2 | 3 | 4 | 5 | 6,
|
||||
firstWeekContainsDate?: 1 | 2 | 3 | 4 | 5 | 6 | 7
|
||||
}
|
||||
}
|
||||
|
||||
declare module.exports: (date: Date | number, amount: number) => Date
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"sideEffects": false,
|
||||
"module": "../esm/addDays/index.js",
|
||||
"typings": "../typings.d.ts"
|
||||
}
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
// This file is generated automatically by `scripts/build/typings.js`. Please, don't change it.
|
||||
|
||||
import { addHours } from 'date-fns'
|
||||
export default addHours
|
||||
+47
@@ -0,0 +1,47 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.default = addHours;
|
||||
|
||||
var _index = _interopRequireDefault(require("../_lib/toInteger/index.js"));
|
||||
|
||||
var _index2 = _interopRequireDefault(require("../addMilliseconds/index.js"));
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
|
||||
var MILLISECONDS_IN_HOUR = 3600000;
|
||||
/**
|
||||
* @name addHours
|
||||
* @category Hour Helpers
|
||||
* @summary Add the specified number of hours to the given date.
|
||||
*
|
||||
* @description
|
||||
* Add the specified number of hours to the given date.
|
||||
*
|
||||
* ### v2.0.0 breaking changes:
|
||||
*
|
||||
* - [Changes that are common for the whole library](https://github.com/date-fns/date-fns/blob/master/docs/upgradeGuide.md#Common-Changes).
|
||||
*
|
||||
* @param {Date|Number} date - the date to be changed
|
||||
* @param {Number} amount - the amount of hours to be added
|
||||
* @returns {Date} the new date with the hours added
|
||||
* @throws {TypeError} 2 arguments required
|
||||
*
|
||||
* @example
|
||||
* // Add 2 hours to 10 July 2014 23:00:00:
|
||||
* var result = addHours(new Date(2014, 6, 10, 23, 0), 2)
|
||||
* //=> Fri Jul 11 2014 01:00:00
|
||||
*/
|
||||
|
||||
function addHours(dirtyDate, dirtyAmount) {
|
||||
if (arguments.length < 2) {
|
||||
throw new TypeError('2 arguments required, but only ' + arguments.length + ' present');
|
||||
}
|
||||
|
||||
var amount = (0, _index.default)(dirtyAmount);
|
||||
return (0, _index2.default)(dirtyDate, amount * MILLISECONDS_IN_HOUR);
|
||||
}
|
||||
|
||||
module.exports = exports.default;
|
||||
+38
@@ -0,0 +1,38 @@
|
||||
// @flow
|
||||
// This file is generated automatically by `scripts/build/typings.js`. Please, don't change it.
|
||||
|
||||
export type Interval = {
|
||||
start: Date | number,
|
||||
end: Date | number
|
||||
}
|
||||
|
||||
export type Locale = {
|
||||
formatDistance: (...args: Array<any>) => any,
|
||||
formatRelative: (...args: Array<any>) => any,
|
||||
localize: {
|
||||
ordinalNumber: (...args: Array<any>) => any,
|
||||
era: (...args: Array<any>) => any,
|
||||
quarter: (...args: Array<any>) => any,
|
||||
month: (...args: Array<any>) => any,
|
||||
day: (...args: Array<any>) => any,
|
||||
dayPeriod: (...args: Array<any>) => any
|
||||
},
|
||||
formatLong: Object,
|
||||
date: (...args: Array<any>) => any,
|
||||
time: (...args: Array<any>) => any,
|
||||
dateTime: (...args: Array<any>) => any,
|
||||
match: {
|
||||
ordinalNumber: (...args: Array<any>) => any,
|
||||
era: (...args: Array<any>) => any,
|
||||
quarter: (...args: Array<any>) => any,
|
||||
month: (...args: Array<any>) => any,
|
||||
day: (...args: Array<any>) => any,
|
||||
dayPeriod: (...args: Array<any>) => any
|
||||
},
|
||||
options?: {
|
||||
weekStartsOn?: 0 | 1 | 2 | 3 | 4 | 5 | 6,
|
||||
firstWeekContainsDate?: 1 | 2 | 3 | 4 | 5 | 6 | 7
|
||||
}
|
||||
}
|
||||
|
||||
declare module.exports: (date: Date | number, amount: number) => Date
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"sideEffects": false,
|
||||
"module": "../esm/addHours/index.js",
|
||||
"typings": "../typings.d.ts"
|
||||
}
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
// This file is generated automatically by `scripts/build/typings.js`. Please, don't change it.
|
||||
|
||||
import { addISOWeekYears } from 'date-fns'
|
||||
export default addISOWeekYears
|
||||
+54
@@ -0,0 +1,54 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.default = addISOWeekYears;
|
||||
|
||||
var _index = _interopRequireDefault(require("../_lib/toInteger/index.js"));
|
||||
|
||||
var _index2 = _interopRequireDefault(require("../getISOWeekYear/index.js"));
|
||||
|
||||
var _index3 = _interopRequireDefault(require("../setISOWeekYear/index.js"));
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
|
||||
/**
|
||||
* @name addISOWeekYears
|
||||
* @category ISO Week-Numbering Year Helpers
|
||||
* @summary Add the specified number of ISO week-numbering years to the given date.
|
||||
*
|
||||
* @description
|
||||
* Add the specified number of ISO week-numbering years to the given date.
|
||||
*
|
||||
* ISO week-numbering year: http://en.wikipedia.org/wiki/ISO_week_date
|
||||
*
|
||||
* ### v2.0.0 breaking changes:
|
||||
*
|
||||
* - [Changes that are common for the whole library](https://github.com/date-fns/date-fns/blob/master/docs/upgradeGuide.md#Common-Changes).
|
||||
*
|
||||
* - The function was renamed from `addISOYears` to `addISOWeekYears`.
|
||||
* "ISO week year" is short for [ISO week-numbering year](https://en.wikipedia.org/wiki/ISO_week_date).
|
||||
* This change makes the name consistent with
|
||||
* locale-dependent week-numbering year helpers, e.g., `addWeekYears`.
|
||||
*
|
||||
* @param {Date|Number} date - the date to be changed
|
||||
* @param {Number} amount - the amount of ISO week-numbering years to be added
|
||||
* @returns {Date} the new date with the ISO week-numbering years added
|
||||
* @throws {TypeError} 2 arguments required
|
||||
*
|
||||
* @example
|
||||
* // Add 5 ISO week-numbering years to 2 July 2010:
|
||||
* var result = addISOWeekYears(new Date(2010, 6, 2), 5)
|
||||
* //=> Fri Jun 26 2015 00:00:00
|
||||
*/
|
||||
function addISOWeekYears(dirtyDate, dirtyAmount) {
|
||||
if (arguments.length < 2) {
|
||||
throw new TypeError('2 arguments required, but only ' + arguments.length + ' present');
|
||||
}
|
||||
|
||||
var amount = (0, _index.default)(dirtyAmount);
|
||||
return (0, _index3.default)(dirtyDate, (0, _index2.default)(dirtyDate) + amount);
|
||||
}
|
||||
|
||||
module.exports = exports.default;
|
||||
+38
@@ -0,0 +1,38 @@
|
||||
// @flow
|
||||
// This file is generated automatically by `scripts/build/typings.js`. Please, don't change it.
|
||||
|
||||
export type Interval = {
|
||||
start: Date | number,
|
||||
end: Date | number
|
||||
}
|
||||
|
||||
export type Locale = {
|
||||
formatDistance: (...args: Array<any>) => any,
|
||||
formatRelative: (...args: Array<any>) => any,
|
||||
localize: {
|
||||
ordinalNumber: (...args: Array<any>) => any,
|
||||
era: (...args: Array<any>) => any,
|
||||
quarter: (...args: Array<any>) => any,
|
||||
month: (...args: Array<any>) => any,
|
||||
day: (...args: Array<any>) => any,
|
||||
dayPeriod: (...args: Array<any>) => any
|
||||
},
|
||||
formatLong: Object,
|
||||
date: (...args: Array<any>) => any,
|
||||
time: (...args: Array<any>) => any,
|
||||
dateTime: (...args: Array<any>) => any,
|
||||
match: {
|
||||
ordinalNumber: (...args: Array<any>) => any,
|
||||
era: (...args: Array<any>) => any,
|
||||
quarter: (...args: Array<any>) => any,
|
||||
month: (...args: Array<any>) => any,
|
||||
day: (...args: Array<any>) => any,
|
||||
dayPeriod: (...args: Array<any>) => any
|
||||
},
|
||||
options?: {
|
||||
weekStartsOn?: 0 | 1 | 2 | 3 | 4 | 5 | 6,
|
||||
firstWeekContainsDate?: 1 | 2 | 3 | 4 | 5 | 6 | 7
|
||||
}
|
||||
}
|
||||
|
||||
declare module.exports: (date: Date | number, amount: number) => Date
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"sideEffects": false,
|
||||
"module": "../esm/addISOWeekYears/index.js",
|
||||
"typings": "../typings.d.ts"
|
||||
}
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
// This file is generated automatically by `scripts/build/typings.js`. Please, don't change it.
|
||||
|
||||
import { addMilliseconds } from 'date-fns'
|
||||
export default addMilliseconds
|
||||
+46
@@ -0,0 +1,46 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.default = addMilliseconds;
|
||||
|
||||
var _index = _interopRequireDefault(require("../_lib/toInteger/index.js"));
|
||||
|
||||
var _index2 = _interopRequireDefault(require("../toDate/index.js"));
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
|
||||
/**
|
||||
* @name addMilliseconds
|
||||
* @category Millisecond Helpers
|
||||
* @summary Add the specified number of milliseconds to the given date.
|
||||
*
|
||||
* @description
|
||||
* Add the specified number of milliseconds to the given date.
|
||||
*
|
||||
* ### v2.0.0 breaking changes:
|
||||
*
|
||||
* - [Changes that are common for the whole library](https://github.com/date-fns/date-fns/blob/master/docs/upgradeGuide.md#Common-Changes).
|
||||
*
|
||||
* @param {Date|Number} date - the date to be changed
|
||||
* @param {Number} amount - the amount of milliseconds to be added
|
||||
* @returns {Date} the new date with the milliseconds added
|
||||
* @throws {TypeError} 2 arguments required
|
||||
*
|
||||
* @example
|
||||
* // Add 750 milliseconds to 10 July 2014 12:45:30.000:
|
||||
* var result = addMilliseconds(new Date(2014, 6, 10, 12, 45, 30, 0), 750)
|
||||
* //=> Thu Jul 10 2014 12:45:30.750
|
||||
*/
|
||||
function addMilliseconds(dirtyDate, dirtyAmount) {
|
||||
if (arguments.length < 2) {
|
||||
throw new TypeError('2 arguments required, but only ' + arguments.length + ' present');
|
||||
}
|
||||
|
||||
var timestamp = (0, _index2.default)(dirtyDate).getTime();
|
||||
var amount = (0, _index.default)(dirtyAmount);
|
||||
return new Date(timestamp + amount);
|
||||
}
|
||||
|
||||
module.exports = exports.default;
|
||||
+38
@@ -0,0 +1,38 @@
|
||||
// @flow
|
||||
// This file is generated automatically by `scripts/build/typings.js`. Please, don't change it.
|
||||
|
||||
export type Interval = {
|
||||
start: Date | number,
|
||||
end: Date | number
|
||||
}
|
||||
|
||||
export type Locale = {
|
||||
formatDistance: (...args: Array<any>) => any,
|
||||
formatRelative: (...args: Array<any>) => any,
|
||||
localize: {
|
||||
ordinalNumber: (...args: Array<any>) => any,
|
||||
era: (...args: Array<any>) => any,
|
||||
quarter: (...args: Array<any>) => any,
|
||||
month: (...args: Array<any>) => any,
|
||||
day: (...args: Array<any>) => any,
|
||||
dayPeriod: (...args: Array<any>) => any
|
||||
},
|
||||
formatLong: Object,
|
||||
date: (...args: Array<any>) => any,
|
||||
time: (...args: Array<any>) => any,
|
||||
dateTime: (...args: Array<any>) => any,
|
||||
match: {
|
||||
ordinalNumber: (...args: Array<any>) => any,
|
||||
era: (...args: Array<any>) => any,
|
||||
quarter: (...args: Array<any>) => any,
|
||||
month: (...args: Array<any>) => any,
|
||||
day: (...args: Array<any>) => any,
|
||||
dayPeriod: (...args: Array<any>) => any
|
||||
},
|
||||
options?: {
|
||||
weekStartsOn?: 0 | 1 | 2 | 3 | 4 | 5 | 6,
|
||||
firstWeekContainsDate?: 1 | 2 | 3 | 4 | 5 | 6 | 7
|
||||
}
|
||||
}
|
||||
|
||||
declare module.exports: (date: Date | number, amount: number) => Date
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"sideEffects": false,
|
||||
"module": "../esm/addMilliseconds/index.js",
|
||||
"typings": "../typings.d.ts"
|
||||
}
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
// This file is generated automatically by `scripts/build/typings.js`. Please, don't change it.
|
||||
|
||||
import { addMinutes } from 'date-fns'
|
||||
export default addMinutes
|
||||
+47
@@ -0,0 +1,47 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.default = addMinutes;
|
||||
|
||||
var _index = _interopRequireDefault(require("../_lib/toInteger/index.js"));
|
||||
|
||||
var _index2 = _interopRequireDefault(require("../addMilliseconds/index.js"));
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
|
||||
var MILLISECONDS_IN_MINUTE = 60000;
|
||||
/**
|
||||
* @name addMinutes
|
||||
* @category Minute Helpers
|
||||
* @summary Add the specified number of minutes to the given date.
|
||||
*
|
||||
* @description
|
||||
* Add the specified number of minutes to the given date.
|
||||
*
|
||||
* ### v2.0.0 breaking changes:
|
||||
*
|
||||
* - [Changes that are common for the whole library](https://github.com/date-fns/date-fns/blob/master/docs/upgradeGuide.md#Common-Changes).
|
||||
*
|
||||
* @param {Date|Number} date - the date to be changed
|
||||
* @param {Number} amount - the amount of minutes to be added
|
||||
* @returns {Date} the new date with the minutes added
|
||||
* @throws {TypeError} 2 arguments required
|
||||
*
|
||||
* @example
|
||||
* // Add 30 minutes to 10 July 2014 12:00:00:
|
||||
* var result = addMinutes(new Date(2014, 6, 10, 12, 0), 30)
|
||||
* //=> Thu Jul 10 2014 12:30:00
|
||||
*/
|
||||
|
||||
function addMinutes(dirtyDate, dirtyAmount) {
|
||||
if (arguments.length < 2) {
|
||||
throw new TypeError('2 arguments required, but only ' + arguments.length + ' present');
|
||||
}
|
||||
|
||||
var amount = (0, _index.default)(dirtyAmount);
|
||||
return (0, _index2.default)(dirtyDate, amount * MILLISECONDS_IN_MINUTE);
|
||||
}
|
||||
|
||||
module.exports = exports.default;
|
||||
+38
@@ -0,0 +1,38 @@
|
||||
// @flow
|
||||
// This file is generated automatically by `scripts/build/typings.js`. Please, don't change it.
|
||||
|
||||
export type Interval = {
|
||||
start: Date | number,
|
||||
end: Date | number
|
||||
}
|
||||
|
||||
export type Locale = {
|
||||
formatDistance: (...args: Array<any>) => any,
|
||||
formatRelative: (...args: Array<any>) => any,
|
||||
localize: {
|
||||
ordinalNumber: (...args: Array<any>) => any,
|
||||
era: (...args: Array<any>) => any,
|
||||
quarter: (...args: Array<any>) => any,
|
||||
month: (...args: Array<any>) => any,
|
||||
day: (...args: Array<any>) => any,
|
||||
dayPeriod: (...args: Array<any>) => any
|
||||
},
|
||||
formatLong: Object,
|
||||
date: (...args: Array<any>) => any,
|
||||
time: (...args: Array<any>) => any,
|
||||
dateTime: (...args: Array<any>) => any,
|
||||
match: {
|
||||
ordinalNumber: (...args: Array<any>) => any,
|
||||
era: (...args: Array<any>) => any,
|
||||
quarter: (...args: Array<any>) => any,
|
||||
month: (...args: Array<any>) => any,
|
||||
day: (...args: Array<any>) => any,
|
||||
dayPeriod: (...args: Array<any>) => any
|
||||
},
|
||||
options?: {
|
||||
weekStartsOn?: 0 | 1 | 2 | 3 | 4 | 5 | 6,
|
||||
firstWeekContainsDate?: 1 | 2 | 3 | 4 | 5 | 6 | 7
|
||||
}
|
||||
}
|
||||
|
||||
declare module.exports: (date: Date | number, amount: number) => Date
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"sideEffects": false,
|
||||
"module": "../esm/addMinutes/index.js",
|
||||
"typings": "../typings.d.ts"
|
||||
}
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
// This file is generated automatically by `scripts/build/typings.js`. Please, don't change it.
|
||||
|
||||
import { addMonths } from 'date-fns'
|
||||
export default addMonths
|
||||
+56
@@ -0,0 +1,56 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.default = addMonths;
|
||||
|
||||
var _index = _interopRequireDefault(require("../_lib/toInteger/index.js"));
|
||||
|
||||
var _index2 = _interopRequireDefault(require("../toDate/index.js"));
|
||||
|
||||
var _index3 = _interopRequireDefault(require("../getDaysInMonth/index.js"));
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
|
||||
/**
|
||||
* @name addMonths
|
||||
* @category Month Helpers
|
||||
* @summary Add the specified number of months to the given date.
|
||||
*
|
||||
* @description
|
||||
* Add the specified number of months to the given date.
|
||||
*
|
||||
* ### v2.0.0 breaking changes:
|
||||
*
|
||||
* - [Changes that are common for the whole library](https://github.com/date-fns/date-fns/blob/master/docs/upgradeGuide.md#Common-Changes).
|
||||
*
|
||||
* @param {Date|Number} date - the date to be changed
|
||||
* @param {Number} amount - the amount of months to be added
|
||||
* @returns {Date} the new date with the months added
|
||||
* @throws {TypeError} 2 arguments required
|
||||
*
|
||||
* @example
|
||||
* // Add 5 months to 1 September 2014:
|
||||
* var result = addMonths(new Date(2014, 8, 1), 5)
|
||||
* //=> Sun Feb 01 2015 00:00:00
|
||||
*/
|
||||
function addMonths(dirtyDate, dirtyAmount) {
|
||||
if (arguments.length < 2) {
|
||||
throw new TypeError('2 arguments required, but only ' + arguments.length + ' present');
|
||||
}
|
||||
|
||||
var date = (0, _index2.default)(dirtyDate);
|
||||
var amount = (0, _index.default)(dirtyAmount);
|
||||
var desiredMonth = date.getMonth() + amount;
|
||||
var dateWithDesiredMonth = new Date(0);
|
||||
dateWithDesiredMonth.setFullYear(date.getFullYear(), desiredMonth, 1);
|
||||
dateWithDesiredMonth.setHours(0, 0, 0, 0);
|
||||
var daysInMonth = (0, _index3.default)(dateWithDesiredMonth); // Set the last day of the new month
|
||||
// if the original date was the last day of the longer month
|
||||
|
||||
date.setMonth(desiredMonth, Math.min(daysInMonth, date.getDate()));
|
||||
return date;
|
||||
}
|
||||
|
||||
module.exports = exports.default;
|
||||
+38
@@ -0,0 +1,38 @@
|
||||
// @flow
|
||||
// This file is generated automatically by `scripts/build/typings.js`. Please, don't change it.
|
||||
|
||||
export type Interval = {
|
||||
start: Date | number,
|
||||
end: Date | number
|
||||
}
|
||||
|
||||
export type Locale = {
|
||||
formatDistance: (...args: Array<any>) => any,
|
||||
formatRelative: (...args: Array<any>) => any,
|
||||
localize: {
|
||||
ordinalNumber: (...args: Array<any>) => any,
|
||||
era: (...args: Array<any>) => any,
|
||||
quarter: (...args: Array<any>) => any,
|
||||
month: (...args: Array<any>) => any,
|
||||
day: (...args: Array<any>) => any,
|
||||
dayPeriod: (...args: Array<any>) => any
|
||||
},
|
||||
formatLong: Object,
|
||||
date: (...args: Array<any>) => any,
|
||||
time: (...args: Array<any>) => any,
|
||||
dateTime: (...args: Array<any>) => any,
|
||||
match: {
|
||||
ordinalNumber: (...args: Array<any>) => any,
|
||||
era: (...args: Array<any>) => any,
|
||||
quarter: (...args: Array<any>) => any,
|
||||
month: (...args: Array<any>) => any,
|
||||
day: (...args: Array<any>) => any,
|
||||
dayPeriod: (...args: Array<any>) => any
|
||||
},
|
||||
options?: {
|
||||
weekStartsOn?: 0 | 1 | 2 | 3 | 4 | 5 | 6,
|
||||
firstWeekContainsDate?: 1 | 2 | 3 | 4 | 5 | 6 | 7
|
||||
}
|
||||
}
|
||||
|
||||
declare module.exports: (date: Date | number, amount: number) => Date
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"sideEffects": false,
|
||||
"module": "../esm/addMonths/index.js",
|
||||
"typings": "../typings.d.ts"
|
||||
}
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
// This file is generated automatically by `scripts/build/typings.js`. Please, don't change it.
|
||||
|
||||
import { addQuarters } from 'date-fns'
|
||||
export default addQuarters
|
||||
+46
@@ -0,0 +1,46 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.default = addQuarters;
|
||||
|
||||
var _index = _interopRequireDefault(require("../_lib/toInteger/index.js"));
|
||||
|
||||
var _index2 = _interopRequireDefault(require("../addMonths/index.js"));
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
|
||||
/**
|
||||
* @name addQuarters
|
||||
* @category Quarter Helpers
|
||||
* @summary Add the specified number of year quarters to the given date.
|
||||
*
|
||||
* @description
|
||||
* Add the specified number of year quarters to the given date.
|
||||
*
|
||||
* ### v2.0.0 breaking changes:
|
||||
*
|
||||
* - [Changes that are common for the whole library](https://github.com/date-fns/date-fns/blob/master/docs/upgradeGuide.md#Common-Changes).
|
||||
*
|
||||
* @param {Date|Number} date - the date to be changed
|
||||
* @param {Number} amount - the amount of quarters to be added
|
||||
* @returns {Date} the new date with the quarters added
|
||||
* @throws {TypeError} 2 arguments required
|
||||
*
|
||||
* @example
|
||||
* // Add 1 quarter to 1 September 2014:
|
||||
* var result = addQuarters(new Date(2014, 8, 1), 1)
|
||||
* //=> Mon Dec 01 2014 00:00:00
|
||||
*/
|
||||
function addQuarters(dirtyDate, dirtyAmount) {
|
||||
if (arguments.length < 2) {
|
||||
throw new TypeError('2 arguments required, but only ' + arguments.length + ' present');
|
||||
}
|
||||
|
||||
var amount = (0, _index.default)(dirtyAmount);
|
||||
var months = amount * 3;
|
||||
return (0, _index2.default)(dirtyDate, months);
|
||||
}
|
||||
|
||||
module.exports = exports.default;
|
||||
+38
@@ -0,0 +1,38 @@
|
||||
// @flow
|
||||
// This file is generated automatically by `scripts/build/typings.js`. Please, don't change it.
|
||||
|
||||
export type Interval = {
|
||||
start: Date | number,
|
||||
end: Date | number
|
||||
}
|
||||
|
||||
export type Locale = {
|
||||
formatDistance: (...args: Array<any>) => any,
|
||||
formatRelative: (...args: Array<any>) => any,
|
||||
localize: {
|
||||
ordinalNumber: (...args: Array<any>) => any,
|
||||
era: (...args: Array<any>) => any,
|
||||
quarter: (...args: Array<any>) => any,
|
||||
month: (...args: Array<any>) => any,
|
||||
day: (...args: Array<any>) => any,
|
||||
dayPeriod: (...args: Array<any>) => any
|
||||
},
|
||||
formatLong: Object,
|
||||
date: (...args: Array<any>) => any,
|
||||
time: (...args: Array<any>) => any,
|
||||
dateTime: (...args: Array<any>) => any,
|
||||
match: {
|
||||
ordinalNumber: (...args: Array<any>) => any,
|
||||
era: (...args: Array<any>) => any,
|
||||
quarter: (...args: Array<any>) => any,
|
||||
month: (...args: Array<any>) => any,
|
||||
day: (...args: Array<any>) => any,
|
||||
dayPeriod: (...args: Array<any>) => any
|
||||
},
|
||||
options?: {
|
||||
weekStartsOn?: 0 | 1 | 2 | 3 | 4 | 5 | 6,
|
||||
firstWeekContainsDate?: 1 | 2 | 3 | 4 | 5 | 6 | 7
|
||||
}
|
||||
}
|
||||
|
||||
declare module.exports: (date: Date | number, amount: number) => Date
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"sideEffects": false,
|
||||
"module": "../esm/addQuarters/index.js",
|
||||
"typings": "../typings.d.ts"
|
||||
}
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
// This file is generated automatically by `scripts/build/typings.js`. Please, don't change it.
|
||||
|
||||
import { addSeconds } from 'date-fns'
|
||||
export default addSeconds
|
||||
+45
@@ -0,0 +1,45 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.default = addSeconds;
|
||||
|
||||
var _index = _interopRequireDefault(require("../_lib/toInteger/index.js"));
|
||||
|
||||
var _index2 = _interopRequireDefault(require("../addMilliseconds/index.js"));
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
|
||||
/**
|
||||
* @name addSeconds
|
||||
* @category Second Helpers
|
||||
* @summary Add the specified number of seconds to the given date.
|
||||
*
|
||||
* @description
|
||||
* Add the specified number of seconds to the given date.
|
||||
*
|
||||
* ### v2.0.0 breaking changes:
|
||||
*
|
||||
* - [Changes that are common for the whole library](https://github.com/date-fns/date-fns/blob/master/docs/upgradeGuide.md#Common-Changes).
|
||||
*
|
||||
* @param {Date|Number} date - the date to be changed
|
||||
* @param {Number} amount - the amount of seconds to be added
|
||||
* @returns {Date} the new date with the seconds added
|
||||
* @throws {TypeError} 2 arguments required
|
||||
*
|
||||
* @example
|
||||
* // Add 30 seconds to 10 July 2014 12:45:00:
|
||||
* var result = addSeconds(new Date(2014, 6, 10, 12, 45, 0), 30)
|
||||
* //=> Thu Jul 10 2014 12:45:30
|
||||
*/
|
||||
function addSeconds(dirtyDate, dirtyAmount) {
|
||||
if (arguments.length < 2) {
|
||||
throw new TypeError('2 arguments required, but only ' + arguments.length + ' present');
|
||||
}
|
||||
|
||||
var amount = (0, _index.default)(dirtyAmount);
|
||||
return (0, _index2.default)(dirtyDate, amount * 1000);
|
||||
}
|
||||
|
||||
module.exports = exports.default;
|
||||
+38
@@ -0,0 +1,38 @@
|
||||
// @flow
|
||||
// This file is generated automatically by `scripts/build/typings.js`. Please, don't change it.
|
||||
|
||||
export type Interval = {
|
||||
start: Date | number,
|
||||
end: Date | number
|
||||
}
|
||||
|
||||
export type Locale = {
|
||||
formatDistance: (...args: Array<any>) => any,
|
||||
formatRelative: (...args: Array<any>) => any,
|
||||
localize: {
|
||||
ordinalNumber: (...args: Array<any>) => any,
|
||||
era: (...args: Array<any>) => any,
|
||||
quarter: (...args: Array<any>) => any,
|
||||
month: (...args: Array<any>) => any,
|
||||
day: (...args: Array<any>) => any,
|
||||
dayPeriod: (...args: Array<any>) => any
|
||||
},
|
||||
formatLong: Object,
|
||||
date: (...args: Array<any>) => any,
|
||||
time: (...args: Array<any>) => any,
|
||||
dateTime: (...args: Array<any>) => any,
|
||||
match: {
|
||||
ordinalNumber: (...args: Array<any>) => any,
|
||||
era: (...args: Array<any>) => any,
|
||||
quarter: (...args: Array<any>) => any,
|
||||
month: (...args: Array<any>) => any,
|
||||
day: (...args: Array<any>) => any,
|
||||
dayPeriod: (...args: Array<any>) => any
|
||||
},
|
||||
options?: {
|
||||
weekStartsOn?: 0 | 1 | 2 | 3 | 4 | 5 | 6,
|
||||
firstWeekContainsDate?: 1 | 2 | 3 | 4 | 5 | 6 | 7
|
||||
}
|
||||
}
|
||||
|
||||
declare module.exports: (date: Date | number, amount: number) => Date
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"sideEffects": false,
|
||||
"module": "../esm/addSeconds/index.js",
|
||||
"typings": "../typings.d.ts"
|
||||
}
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
// This file is generated automatically by `scripts/build/typings.js`. Please, don't change it.
|
||||
|
||||
import { addWeeks } from 'date-fns'
|
||||
export default addWeeks
|
||||
+46
@@ -0,0 +1,46 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.default = addWeeks;
|
||||
|
||||
var _index = _interopRequireDefault(require("../_lib/toInteger/index.js"));
|
||||
|
||||
var _index2 = _interopRequireDefault(require("../addDays/index.js"));
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
|
||||
/**
|
||||
* @name addWeeks
|
||||
* @category Week Helpers
|
||||
* @summary Add the specified number of weeks to the given date.
|
||||
*
|
||||
* @description
|
||||
* Add the specified number of week to the given date.
|
||||
*
|
||||
* ### v2.0.0 breaking changes:
|
||||
*
|
||||
* - [Changes that are common for the whole library](https://github.com/date-fns/date-fns/blob/master/docs/upgradeGuide.md#Common-Changes).
|
||||
*
|
||||
* @param {Date|Number} date - the date to be changed
|
||||
* @param {Number} amount - the amount of weeks to be added
|
||||
* @returns {Date} the new date with the weeks added
|
||||
* @throws {TypeError} 2 arguments required
|
||||
*
|
||||
* @example
|
||||
* // Add 4 weeks to 1 September 2014:
|
||||
* var result = addWeeks(new Date(2014, 8, 1), 4)
|
||||
* //=> Mon Sep 29 2014 00:00:00
|
||||
*/
|
||||
function addWeeks(dirtyDate, dirtyAmount) {
|
||||
if (arguments.length < 2) {
|
||||
throw new TypeError('2 arguments required, but only ' + arguments.length + ' present');
|
||||
}
|
||||
|
||||
var amount = (0, _index.default)(dirtyAmount);
|
||||
var days = amount * 7;
|
||||
return (0, _index2.default)(dirtyDate, days);
|
||||
}
|
||||
|
||||
module.exports = exports.default;
|
||||
+38
@@ -0,0 +1,38 @@
|
||||
// @flow
|
||||
// This file is generated automatically by `scripts/build/typings.js`. Please, don't change it.
|
||||
|
||||
export type Interval = {
|
||||
start: Date | number,
|
||||
end: Date | number
|
||||
}
|
||||
|
||||
export type Locale = {
|
||||
formatDistance: (...args: Array<any>) => any,
|
||||
formatRelative: (...args: Array<any>) => any,
|
||||
localize: {
|
||||
ordinalNumber: (...args: Array<any>) => any,
|
||||
era: (...args: Array<any>) => any,
|
||||
quarter: (...args: Array<any>) => any,
|
||||
month: (...args: Array<any>) => any,
|
||||
day: (...args: Array<any>) => any,
|
||||
dayPeriod: (...args: Array<any>) => any
|
||||
},
|
||||
formatLong: Object,
|
||||
date: (...args: Array<any>) => any,
|
||||
time: (...args: Array<any>) => any,
|
||||
dateTime: (...args: Array<any>) => any,
|
||||
match: {
|
||||
ordinalNumber: (...args: Array<any>) => any,
|
||||
era: (...args: Array<any>) => any,
|
||||
quarter: (...args: Array<any>) => any,
|
||||
month: (...args: Array<any>) => any,
|
||||
day: (...args: Array<any>) => any,
|
||||
dayPeriod: (...args: Array<any>) => any
|
||||
},
|
||||
options?: {
|
||||
weekStartsOn?: 0 | 1 | 2 | 3 | 4 | 5 | 6,
|
||||
firstWeekContainsDate?: 1 | 2 | 3 | 4 | 5 | 6 | 7
|
||||
}
|
||||
}
|
||||
|
||||
declare module.exports: (date: Date | number, amount: number) => Date
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"sideEffects": false,
|
||||
"module": "../esm/addWeeks/index.js",
|
||||
"typings": "../typings.d.ts"
|
||||
}
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
// This file is generated automatically by `scripts/build/typings.js`. Please, don't change it.
|
||||
|
||||
import { addYears } from 'date-fns'
|
||||
export default addYears
|
||||
+45
@@ -0,0 +1,45 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.default = addYears;
|
||||
|
||||
var _index = _interopRequireDefault(require("../_lib/toInteger/index.js"));
|
||||
|
||||
var _index2 = _interopRequireDefault(require("../addMonths/index.js"));
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
|
||||
/**
|
||||
* @name addYears
|
||||
* @category Year Helpers
|
||||
* @summary Add the specified number of years to the given date.
|
||||
*
|
||||
* @description
|
||||
* Add the specified number of years to the given date.
|
||||
*
|
||||
* ### v2.0.0 breaking changes:
|
||||
*
|
||||
* - [Changes that are common for the whole library](https://github.com/date-fns/date-fns/blob/master/docs/upgradeGuide.md#Common-Changes).
|
||||
*
|
||||
* @param {Date|Number} date - the date to be changed
|
||||
* @param {Number} amount - the amount of years to be added
|
||||
* @returns {Date} the new date with the years added
|
||||
* @throws {TypeError} 2 arguments required
|
||||
*
|
||||
* @example
|
||||
* // Add 5 years to 1 September 2014:
|
||||
* var result = addYears(new Date(2014, 8, 1), 5)
|
||||
* //=> Sun Sep 01 2019 00:00:00
|
||||
*/
|
||||
function addYears(dirtyDate, dirtyAmount) {
|
||||
if (arguments.length < 2) {
|
||||
throw new TypeError('2 arguments required, but only ' + arguments.length + ' present');
|
||||
}
|
||||
|
||||
var amount = (0, _index.default)(dirtyAmount);
|
||||
return (0, _index2.default)(dirtyDate, amount * 12);
|
||||
}
|
||||
|
||||
module.exports = exports.default;
|
||||
+38
@@ -0,0 +1,38 @@
|
||||
// @flow
|
||||
// This file is generated automatically by `scripts/build/typings.js`. Please, don't change it.
|
||||
|
||||
export type Interval = {
|
||||
start: Date | number,
|
||||
end: Date | number
|
||||
}
|
||||
|
||||
export type Locale = {
|
||||
formatDistance: (...args: Array<any>) => any,
|
||||
formatRelative: (...args: Array<any>) => any,
|
||||
localize: {
|
||||
ordinalNumber: (...args: Array<any>) => any,
|
||||
era: (...args: Array<any>) => any,
|
||||
quarter: (...args: Array<any>) => any,
|
||||
month: (...args: Array<any>) => any,
|
||||
day: (...args: Array<any>) => any,
|
||||
dayPeriod: (...args: Array<any>) => any
|
||||
},
|
||||
formatLong: Object,
|
||||
date: (...args: Array<any>) => any,
|
||||
time: (...args: Array<any>) => any,
|
||||
dateTime: (...args: Array<any>) => any,
|
||||
match: {
|
||||
ordinalNumber: (...args: Array<any>) => any,
|
||||
era: (...args: Array<any>) => any,
|
||||
quarter: (...args: Array<any>) => any,
|
||||
month: (...args: Array<any>) => any,
|
||||
day: (...args: Array<any>) => any,
|
||||
dayPeriod: (...args: Array<any>) => any
|
||||
},
|
||||
options?: {
|
||||
weekStartsOn?: 0 | 1 | 2 | 3 | 4 | 5 | 6,
|
||||
firstWeekContainsDate?: 1 | 2 | 3 | 4 | 5 | 6 | 7
|
||||
}
|
||||
}
|
||||
|
||||
declare module.exports: (date: Date | number, amount: number) => Date
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"sideEffects": false,
|
||||
"module": "../esm/addYears/index.js",
|
||||
"typings": "../typings.d.ts"
|
||||
}
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
// This file is generated automatically by `scripts/build/typings.js`. Please, don't change it.
|
||||
|
||||
import { areIntervalsOverlapping } from 'date-fns'
|
||||
export default areIntervalsOverlapping
|
||||
+104
@@ -0,0 +1,104 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.default = areIntervalsOverlapping;
|
||||
|
||||
var _index = _interopRequireDefault(require("../toDate/index.js"));
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
|
||||
/**
|
||||
* @name areIntervalsOverlapping
|
||||
* @category Interval Helpers
|
||||
* @summary Is the given time interval overlapping with another time interval?
|
||||
*
|
||||
* @description
|
||||
* Is the given time interval overlapping with another time interval? Adjacent intervals do not count as overlapping.
|
||||
*
|
||||
* ### v2.0.0 breaking changes:
|
||||
*
|
||||
* - [Changes that are common for the whole library](https://github.com/date-fns/date-fns/blob/master/docs/upgradeGuide.md#Common-Changes).
|
||||
*
|
||||
* - The function was renamed from `areRangesOverlapping` to `areIntervalsOverlapping`.
|
||||
* This change was made to mirror the use of the word "interval" in standard ISO 8601:2004 terminology:
|
||||
*
|
||||
* ```
|
||||
* 2.1.3
|
||||
* time interval
|
||||
* part of the time axis limited by two instants
|
||||
* ```
|
||||
*
|
||||
* Also, this function now accepts an object with `start` and `end` properties
|
||||
* instead of two arguments as an interval.
|
||||
* This function now throws `RangeError` if the start of the interval is after its end
|
||||
* or if any date in the interval is `Invalid Date`.
|
||||
*
|
||||
* ```javascript
|
||||
* // Before v2.0.0
|
||||
*
|
||||
* areRangesOverlapping(
|
||||
* new Date(2014, 0, 10), new Date(2014, 0, 20),
|
||||
* new Date(2014, 0, 17), new Date(2014, 0, 21)
|
||||
* )
|
||||
*
|
||||
* // v2.0.0 onward
|
||||
*
|
||||
* areIntervalsOverlapping(
|
||||
* { start: new Date(2014, 0, 10), end: new Date(2014, 0, 20) },
|
||||
* { start: new Date(2014, 0, 17), end: new Date(2014, 0, 21) }
|
||||
* )
|
||||
* ```
|
||||
*
|
||||
* @param {Interval} intervalLeft - the first interval to compare. See [Interval]{@link docs/types/Interval}
|
||||
* @param {Interval} intervalRight - the second interval to compare. See [Interval]{@link docs/types/Interval}
|
||||
* @returns {Boolean} whether the time intervals are overlapping
|
||||
* @throws {TypeError} 2 arguments required
|
||||
* @throws {RangeError} The start of an interval cannot be after its end
|
||||
* @throws {RangeError} Date in interval cannot be `Invalid Date`
|
||||
*
|
||||
* @example
|
||||
* // For overlapping time intervals:
|
||||
* areIntervalsOverlapping(
|
||||
* { start: new Date(2014, 0, 10), end: new Date(2014, 0, 20) },
|
||||
* { start: new Date(2014, 0, 17), end: new Date(2014, 0, 21) }
|
||||
* )
|
||||
* //=> true
|
||||
*
|
||||
* @example
|
||||
* // For non-overlapping time intervals:
|
||||
* areIntervalsOverlapping(
|
||||
* { start: new Date(2014, 0, 10), end: new Date(2014, 0, 20) },
|
||||
* { start: new Date(2014, 0, 21), end: new Date(2014, 0, 22) }
|
||||
* )
|
||||
* //=> false
|
||||
*
|
||||
* @example
|
||||
* // For adjacent time intervals:
|
||||
* areIntervalsOverlapping(
|
||||
* { start: new Date(2014, 0, 10), end: new Date(2014, 0, 20) },
|
||||
* { start: new Date(2014, 0, 20), end: new Date(2014, 0, 30) }
|
||||
* )
|
||||
* //=> false
|
||||
*/
|
||||
function areIntervalsOverlapping(dirtyIntervalLeft, dirtyIntervalRight) {
|
||||
if (arguments.length < 2) {
|
||||
throw new TypeError('2 arguments required, but only ' + arguments.length + ' present');
|
||||
}
|
||||
|
||||
var intervalLeft = dirtyIntervalLeft || {};
|
||||
var intervalRight = dirtyIntervalRight || {};
|
||||
var leftStartTime = (0, _index.default)(intervalLeft.start).getTime();
|
||||
var leftEndTime = (0, _index.default)(intervalLeft.end).getTime();
|
||||
var rightStartTime = (0, _index.default)(intervalRight.start).getTime();
|
||||
var rightEndTime = (0, _index.default)(intervalRight.end).getTime(); // Throw an exception if start date is after end date or if any date is `Invalid Date`
|
||||
|
||||
if (!(leftStartTime <= leftEndTime && rightStartTime <= rightEndTime)) {
|
||||
throw new RangeError('Invalid interval');
|
||||
}
|
||||
|
||||
return leftStartTime < rightEndTime && rightStartTime < leftEndTime;
|
||||
}
|
||||
|
||||
module.exports = exports.default;
|
||||
+41
@@ -0,0 +1,41 @@
|
||||
// @flow
|
||||
// This file is generated automatically by `scripts/build/typings.js`. Please, don't change it.
|
||||
|
||||
export type Interval = {
|
||||
start: Date | number,
|
||||
end: Date | number
|
||||
}
|
||||
|
||||
export type Locale = {
|
||||
formatDistance: (...args: Array<any>) => any,
|
||||
formatRelative: (...args: Array<any>) => any,
|
||||
localize: {
|
||||
ordinalNumber: (...args: Array<any>) => any,
|
||||
era: (...args: Array<any>) => any,
|
||||
quarter: (...args: Array<any>) => any,
|
||||
month: (...args: Array<any>) => any,
|
||||
day: (...args: Array<any>) => any,
|
||||
dayPeriod: (...args: Array<any>) => any
|
||||
},
|
||||
formatLong: Object,
|
||||
date: (...args: Array<any>) => any,
|
||||
time: (...args: Array<any>) => any,
|
||||
dateTime: (...args: Array<any>) => any,
|
||||
match: {
|
||||
ordinalNumber: (...args: Array<any>) => any,
|
||||
era: (...args: Array<any>) => any,
|
||||
quarter: (...args: Array<any>) => any,
|
||||
month: (...args: Array<any>) => any,
|
||||
day: (...args: Array<any>) => any,
|
||||
dayPeriod: (...args: Array<any>) => any
|
||||
},
|
||||
options?: {
|
||||
weekStartsOn?: 0 | 1 | 2 | 3 | 4 | 5 | 6,
|
||||
firstWeekContainsDate?: 1 | 2 | 3 | 4 | 5 | 6 | 7
|
||||
}
|
||||
}
|
||||
|
||||
declare module.exports: (
|
||||
intervalLeft: Interval,
|
||||
intervalRight: Interval
|
||||
) => boolean
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"sideEffects": false,
|
||||
"module": "../esm/areIntervalsOverlapping/index.js",
|
||||
"typings": "../typings.d.ts"
|
||||
}
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
// This file is generated automatically by `scripts/build/typings.js`. Please, don't change it.
|
||||
|
||||
import { closestIndexTo } from 'date-fns'
|
||||
export default closestIndexTo
|
||||
+86
@@ -0,0 +1,86 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.default = closestIndexTo;
|
||||
|
||||
var _index = _interopRequireDefault(require("../toDate/index.js"));
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
|
||||
/**
|
||||
* @name closestIndexTo
|
||||
* @category Common Helpers
|
||||
* @summary Return an index of the closest date from the array comparing to the given date.
|
||||
*
|
||||
* @description
|
||||
* Return an index of the closest date from the array comparing to the given date.
|
||||
*
|
||||
* ### v2.0.0 breaking changes:
|
||||
*
|
||||
* - [Changes that are common for the whole library](https://github.com/date-fns/date-fns/blob/master/docs/upgradeGuide.md#Common-Changes).
|
||||
*
|
||||
* - Now, `closestIndexTo` doesn't throw an exception
|
||||
* when the second argument is not an array, and returns Invalid Date instead.
|
||||
*
|
||||
* @param {Date|Number} dateToCompare - the date to compare with
|
||||
* @param {Date[]|Number[]} datesArray - the array to search
|
||||
* @returns {Number} an index of the date closest to the given date
|
||||
* @throws {TypeError} 2 arguments required
|
||||
*
|
||||
* @example
|
||||
* // Which date is closer to 6 September 2015?
|
||||
* var dateToCompare = new Date(2015, 8, 6)
|
||||
* var datesArray = [
|
||||
* new Date(2015, 0, 1),
|
||||
* new Date(2016, 0, 1),
|
||||
* new Date(2017, 0, 1)
|
||||
* ]
|
||||
* var result = closestIndexTo(dateToCompare, datesArray)
|
||||
* //=> 1
|
||||
*/
|
||||
function closestIndexTo(dirtyDateToCompare, dirtyDatesArray) {
|
||||
if (arguments.length < 2) {
|
||||
throw new TypeError('2 arguments required, but only ' + arguments.length + ' present');
|
||||
}
|
||||
|
||||
var dateToCompare = (0, _index.default)(dirtyDateToCompare);
|
||||
|
||||
if (isNaN(dateToCompare)) {
|
||||
return NaN;
|
||||
}
|
||||
|
||||
var timeToCompare = dateToCompare.getTime();
|
||||
var datesArray; // `dirtyDatesArray` is undefined or null
|
||||
|
||||
if (dirtyDatesArray == null) {
|
||||
datesArray = []; // `dirtyDatesArray` is Array, Set or Map, or object with custom `forEach` method
|
||||
} else if (typeof dirtyDatesArray.forEach === 'function') {
|
||||
datesArray = dirtyDatesArray; // If `dirtyDatesArray` is Array-like Object, convert to Array. Otherwise, make it empty Array
|
||||
} else {
|
||||
datesArray = Array.prototype.slice.call(dirtyDatesArray);
|
||||
}
|
||||
|
||||
var result;
|
||||
var minDistance;
|
||||
datesArray.forEach(function (dirtyDate, index) {
|
||||
var currentDate = (0, _index.default)(dirtyDate);
|
||||
|
||||
if (isNaN(currentDate)) {
|
||||
result = NaN;
|
||||
minDistance = NaN;
|
||||
return;
|
||||
}
|
||||
|
||||
var distance = Math.abs(timeToCompare - currentDate.getTime());
|
||||
|
||||
if (result == null || distance < minDistance) {
|
||||
result = index;
|
||||
minDistance = distance;
|
||||
}
|
||||
});
|
||||
return result;
|
||||
}
|
||||
|
||||
module.exports = exports.default;
|
||||
+41
@@ -0,0 +1,41 @@
|
||||
// @flow
|
||||
// This file is generated automatically by `scripts/build/typings.js`. Please, don't change it.
|
||||
|
||||
export type Interval = {
|
||||
start: Date | number,
|
||||
end: Date | number
|
||||
}
|
||||
|
||||
export type Locale = {
|
||||
formatDistance: (...args: Array<any>) => any,
|
||||
formatRelative: (...args: Array<any>) => any,
|
||||
localize: {
|
||||
ordinalNumber: (...args: Array<any>) => any,
|
||||
era: (...args: Array<any>) => any,
|
||||
quarter: (...args: Array<any>) => any,
|
||||
month: (...args: Array<any>) => any,
|
||||
day: (...args: Array<any>) => any,
|
||||
dayPeriod: (...args: Array<any>) => any
|
||||
},
|
||||
formatLong: Object,
|
||||
date: (...args: Array<any>) => any,
|
||||
time: (...args: Array<any>) => any,
|
||||
dateTime: (...args: Array<any>) => any,
|
||||
match: {
|
||||
ordinalNumber: (...args: Array<any>) => any,
|
||||
era: (...args: Array<any>) => any,
|
||||
quarter: (...args: Array<any>) => any,
|
||||
month: (...args: Array<any>) => any,
|
||||
day: (...args: Array<any>) => any,
|
||||
dayPeriod: (...args: Array<any>) => any
|
||||
},
|
||||
options?: {
|
||||
weekStartsOn?: 0 | 1 | 2 | 3 | 4 | 5 | 6,
|
||||
firstWeekContainsDate?: 1 | 2 | 3 | 4 | 5 | 6 | 7
|
||||
}
|
||||
}
|
||||
|
||||
declare module.exports: (
|
||||
dateToCompare: Date | number,
|
||||
datesArray: (Date | number)[]
|
||||
) => number
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"sideEffects": false,
|
||||
"module": "../esm/closestIndexTo/index.js",
|
||||
"typings": "../typings.d.ts"
|
||||
}
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
// This file is generated automatically by `scripts/build/typings.js`. Please, don't change it.
|
||||
|
||||
import { closestTo } from 'date-fns'
|
||||
export default closestTo
|
||||
+84
@@ -0,0 +1,84 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.default = closestTo;
|
||||
|
||||
var _index = _interopRequireDefault(require("../toDate/index.js"));
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
|
||||
/**
|
||||
* @name closestTo
|
||||
* @category Common Helpers
|
||||
* @summary Return a date from the array closest to the given date.
|
||||
*
|
||||
* @description
|
||||
* Return a date from the array closest to the given date.
|
||||
*
|
||||
* ### v2.0.0 breaking changes:
|
||||
*
|
||||
* - [Changes that are common for the whole library](https://github.com/date-fns/date-fns/blob/master/docs/upgradeGuide.md#Common-Changes).
|
||||
*
|
||||
* - Now, `closestTo` doesn't throw an exception
|
||||
* when the second argument is not an array, and returns Invalid Date instead.
|
||||
*
|
||||
* @param {Date|Number} dateToCompare - the date to compare with
|
||||
* @param {Date[]|Number[]} datesArray - the array to search
|
||||
* @returns {Date} the date from the array closest to the given date
|
||||
* @throws {TypeError} 2 arguments required
|
||||
*
|
||||
* @example
|
||||
* // Which date is closer to 6 September 2015: 1 January 2000 or 1 January 2030?
|
||||
* var dateToCompare = new Date(2015, 8, 6)
|
||||
* var result = closestTo(dateToCompare, [
|
||||
* new Date(2000, 0, 1),
|
||||
* new Date(2030, 0, 1)
|
||||
* ])
|
||||
* //=> Tue Jan 01 2030 00:00:00
|
||||
*/
|
||||
function closestTo(dirtyDateToCompare, dirtyDatesArray) {
|
||||
if (arguments.length < 2) {
|
||||
throw new TypeError('2 arguments required, but only ' + arguments.length + ' present');
|
||||
}
|
||||
|
||||
var dateToCompare = (0, _index.default)(dirtyDateToCompare);
|
||||
|
||||
if (isNaN(dateToCompare)) {
|
||||
return new Date(NaN);
|
||||
}
|
||||
|
||||
var timeToCompare = dateToCompare.getTime();
|
||||
var datesArray; // `dirtyDatesArray` is undefined or null
|
||||
|
||||
if (dirtyDatesArray == null) {
|
||||
datesArray = []; // `dirtyDatesArray` is Array, Set or Map, or object with custom `forEach` method
|
||||
} else if (typeof dirtyDatesArray.forEach === 'function') {
|
||||
datesArray = dirtyDatesArray; // If `dirtyDatesArray` is Array-like Object, convert to Array. Otherwise, make it empty Array
|
||||
} else {
|
||||
datesArray = Array.prototype.slice.call(dirtyDatesArray);
|
||||
}
|
||||
|
||||
var result;
|
||||
var minDistance;
|
||||
datesArray.forEach(function (dirtyDate) {
|
||||
var currentDate = (0, _index.default)(dirtyDate);
|
||||
|
||||
if (isNaN(currentDate)) {
|
||||
result = new Date(NaN);
|
||||
minDistance = NaN;
|
||||
return;
|
||||
}
|
||||
|
||||
var distance = Math.abs(timeToCompare - currentDate.getTime());
|
||||
|
||||
if (result == null || distance < minDistance) {
|
||||
result = currentDate;
|
||||
minDistance = distance;
|
||||
}
|
||||
});
|
||||
return result;
|
||||
}
|
||||
|
||||
module.exports = exports.default;
|
||||
+41
@@ -0,0 +1,41 @@
|
||||
// @flow
|
||||
// This file is generated automatically by `scripts/build/typings.js`. Please, don't change it.
|
||||
|
||||
export type Interval = {
|
||||
start: Date | number,
|
||||
end: Date | number
|
||||
}
|
||||
|
||||
export type Locale = {
|
||||
formatDistance: (...args: Array<any>) => any,
|
||||
formatRelative: (...args: Array<any>) => any,
|
||||
localize: {
|
||||
ordinalNumber: (...args: Array<any>) => any,
|
||||
era: (...args: Array<any>) => any,
|
||||
quarter: (...args: Array<any>) => any,
|
||||
month: (...args: Array<any>) => any,
|
||||
day: (...args: Array<any>) => any,
|
||||
dayPeriod: (...args: Array<any>) => any
|
||||
},
|
||||
formatLong: Object,
|
||||
date: (...args: Array<any>) => any,
|
||||
time: (...args: Array<any>) => any,
|
||||
dateTime: (...args: Array<any>) => any,
|
||||
match: {
|
||||
ordinalNumber: (...args: Array<any>) => any,
|
||||
era: (...args: Array<any>) => any,
|
||||
quarter: (...args: Array<any>) => any,
|
||||
month: (...args: Array<any>) => any,
|
||||
day: (...args: Array<any>) => any,
|
||||
dayPeriod: (...args: Array<any>) => any
|
||||
},
|
||||
options?: {
|
||||
weekStartsOn?: 0 | 1 | 2 | 3 | 4 | 5 | 6,
|
||||
firstWeekContainsDate?: 1 | 2 | 3 | 4 | 5 | 6 | 7
|
||||
}
|
||||
}
|
||||
|
||||
declare module.exports: (
|
||||
dateToCompare: Date | number,
|
||||
datesArray: (Date | number)[]
|
||||
) => Date
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"sideEffects": false,
|
||||
"module": "../esm/closestTo/index.js",
|
||||
"typings": "../typings.d.ts"
|
||||
}
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
// This file is generated automatically by `scripts/build/typings.js`. Please, don't change it.
|
||||
|
||||
import { compareAsc } from 'date-fns'
|
||||
export default compareAsc
|
||||
+66
@@ -0,0 +1,66 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.default = compareAsc;
|
||||
|
||||
var _index = _interopRequireDefault(require("../toDate/index.js"));
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
|
||||
/**
|
||||
* @name compareAsc
|
||||
* @category Common Helpers
|
||||
* @summary Compare the two dates and return -1, 0 or 1.
|
||||
*
|
||||
* @description
|
||||
* Compare the two dates and return 1 if the first date is after the second,
|
||||
* -1 if the first date is before the second or 0 if dates are equal.
|
||||
*
|
||||
* ### v2.0.0 breaking changes:
|
||||
*
|
||||
* - [Changes that are common for the whole library](https://github.com/date-fns/date-fns/blob/master/docs/upgradeGuide.md#Common-Changes).
|
||||
*
|
||||
* @param {Date|Number} dateLeft - the first date to compare
|
||||
* @param {Date|Number} dateRight - the second date to compare
|
||||
* @returns {Number} the result of the comparison
|
||||
* @throws {TypeError} 2 arguments required
|
||||
*
|
||||
* @example
|
||||
* // Compare 11 February 1987 and 10 July 1989:
|
||||
* var result = compareAsc(new Date(1987, 1, 11), new Date(1989, 6, 10))
|
||||
* //=> -1
|
||||
*
|
||||
* @example
|
||||
* // Sort the array of dates:
|
||||
* var result = [
|
||||
* new Date(1995, 6, 2),
|
||||
* new Date(1987, 1, 11),
|
||||
* new Date(1989, 6, 10)
|
||||
* ].sort(compareAsc)
|
||||
* //=> [
|
||||
* // Wed Feb 11 1987 00:00:00,
|
||||
* // Mon Jul 10 1989 00:00:00,
|
||||
* // Sun Jul 02 1995 00:00:00
|
||||
* // ]
|
||||
*/
|
||||
function compareAsc(dirtyDateLeft, dirtyDateRight) {
|
||||
if (arguments.length < 2) {
|
||||
throw new TypeError('2 arguments required, but only ' + arguments.length + ' present');
|
||||
}
|
||||
|
||||
var dateLeft = (0, _index.default)(dirtyDateLeft);
|
||||
var dateRight = (0, _index.default)(dirtyDateRight);
|
||||
var diff = dateLeft.getTime() - dateRight.getTime();
|
||||
|
||||
if (diff < 0) {
|
||||
return -1;
|
||||
} else if (diff > 0) {
|
||||
return 1; // Return 0 if diff is 0; return NaN if diff is NaN
|
||||
} else {
|
||||
return diff;
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = exports.default;
|
||||
+41
@@ -0,0 +1,41 @@
|
||||
// @flow
|
||||
// This file is generated automatically by `scripts/build/typings.js`. Please, don't change it.
|
||||
|
||||
export type Interval = {
|
||||
start: Date | number,
|
||||
end: Date | number
|
||||
}
|
||||
|
||||
export type Locale = {
|
||||
formatDistance: (...args: Array<any>) => any,
|
||||
formatRelative: (...args: Array<any>) => any,
|
||||
localize: {
|
||||
ordinalNumber: (...args: Array<any>) => any,
|
||||
era: (...args: Array<any>) => any,
|
||||
quarter: (...args: Array<any>) => any,
|
||||
month: (...args: Array<any>) => any,
|
||||
day: (...args: Array<any>) => any,
|
||||
dayPeriod: (...args: Array<any>) => any
|
||||
},
|
||||
formatLong: Object,
|
||||
date: (...args: Array<any>) => any,
|
||||
time: (...args: Array<any>) => any,
|
||||
dateTime: (...args: Array<any>) => any,
|
||||
match: {
|
||||
ordinalNumber: (...args: Array<any>) => any,
|
||||
era: (...args: Array<any>) => any,
|
||||
quarter: (...args: Array<any>) => any,
|
||||
month: (...args: Array<any>) => any,
|
||||
day: (...args: Array<any>) => any,
|
||||
dayPeriod: (...args: Array<any>) => any
|
||||
},
|
||||
options?: {
|
||||
weekStartsOn?: 0 | 1 | 2 | 3 | 4 | 5 | 6,
|
||||
firstWeekContainsDate?: 1 | 2 | 3 | 4 | 5 | 6 | 7
|
||||
}
|
||||
}
|
||||
|
||||
declare module.exports: (
|
||||
dateLeft: Date | number,
|
||||
dateRight: Date | number
|
||||
) => number
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"sideEffects": false,
|
||||
"module": "../esm/compareAsc/index.js",
|
||||
"typings": "../typings.d.ts"
|
||||
}
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
// This file is generated automatically by `scripts/build/typings.js`. Please, don't change it.
|
||||
|
||||
import { compareDesc } from 'date-fns'
|
||||
export default compareDesc
|
||||
+66
@@ -0,0 +1,66 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.default = compareDesc;
|
||||
|
||||
var _index = _interopRequireDefault(require("../toDate/index.js"));
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
|
||||
/**
|
||||
* @name compareDesc
|
||||
* @category Common Helpers
|
||||
* @summary Compare the two dates reverse chronologically and return -1, 0 or 1.
|
||||
*
|
||||
* @description
|
||||
* Compare the two dates and return -1 if the first date is after the second,
|
||||
* 1 if the first date is before the second or 0 if dates are equal.
|
||||
*
|
||||
* ### v2.0.0 breaking changes:
|
||||
*
|
||||
* - [Changes that are common for the whole library](https://github.com/date-fns/date-fns/blob/master/docs/upgradeGuide.md#Common-Changes).
|
||||
*
|
||||
* @param {Date|Number} dateLeft - the first date to compare
|
||||
* @param {Date|Number} dateRight - the second date to compare
|
||||
* @returns {Number} the result of the comparison
|
||||
* @throws {TypeError} 2 arguments required
|
||||
*
|
||||
* @example
|
||||
* // Compare 11 February 1987 and 10 July 1989 reverse chronologically:
|
||||
* var result = compareDesc(new Date(1987, 1, 11), new Date(1989, 6, 10))
|
||||
* //=> 1
|
||||
*
|
||||
* @example
|
||||
* // Sort the array of dates in reverse chronological order:
|
||||
* var result = [
|
||||
* new Date(1995, 6, 2),
|
||||
* new Date(1987, 1, 11),
|
||||
* new Date(1989, 6, 10)
|
||||
* ].sort(compareDesc)
|
||||
* //=> [
|
||||
* // Sun Jul 02 1995 00:00:00,
|
||||
* // Mon Jul 10 1989 00:00:00,
|
||||
* // Wed Feb 11 1987 00:00:00
|
||||
* // ]
|
||||
*/
|
||||
function compareDesc(dirtyDateLeft, dirtyDateRight) {
|
||||
if (arguments.length < 2) {
|
||||
throw new TypeError('2 arguments required, but only ' + arguments.length + ' present');
|
||||
}
|
||||
|
||||
var dateLeft = (0, _index.default)(dirtyDateLeft);
|
||||
var dateRight = (0, _index.default)(dirtyDateRight);
|
||||
var diff = dateLeft.getTime() - dateRight.getTime();
|
||||
|
||||
if (diff > 0) {
|
||||
return -1;
|
||||
} else if (diff < 0) {
|
||||
return 1; // Return 0 if diff is 0; return NaN if diff is NaN
|
||||
} else {
|
||||
return diff;
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = exports.default;
|
||||
+41
@@ -0,0 +1,41 @@
|
||||
// @flow
|
||||
// This file is generated automatically by `scripts/build/typings.js`. Please, don't change it.
|
||||
|
||||
export type Interval = {
|
||||
start: Date | number,
|
||||
end: Date | number
|
||||
}
|
||||
|
||||
export type Locale = {
|
||||
formatDistance: (...args: Array<any>) => any,
|
||||
formatRelative: (...args: Array<any>) => any,
|
||||
localize: {
|
||||
ordinalNumber: (...args: Array<any>) => any,
|
||||
era: (...args: Array<any>) => any,
|
||||
quarter: (...args: Array<any>) => any,
|
||||
month: (...args: Array<any>) => any,
|
||||
day: (...args: Array<any>) => any,
|
||||
dayPeriod: (...args: Array<any>) => any
|
||||
},
|
||||
formatLong: Object,
|
||||
date: (...args: Array<any>) => any,
|
||||
time: (...args: Array<any>) => any,
|
||||
dateTime: (...args: Array<any>) => any,
|
||||
match: {
|
||||
ordinalNumber: (...args: Array<any>) => any,
|
||||
era: (...args: Array<any>) => any,
|
||||
quarter: (...args: Array<any>) => any,
|
||||
month: (...args: Array<any>) => any,
|
||||
day: (...args: Array<any>) => any,
|
||||
dayPeriod: (...args: Array<any>) => any
|
||||
},
|
||||
options?: {
|
||||
weekStartsOn?: 0 | 1 | 2 | 3 | 4 | 5 | 6,
|
||||
firstWeekContainsDate?: 1 | 2 | 3 | 4 | 5 | 6 | 7
|
||||
}
|
||||
}
|
||||
|
||||
declare module.exports: (
|
||||
dateLeft: Date | number,
|
||||
dateRight: Date | number
|
||||
) => number
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"sideEffects": false,
|
||||
"module": "../esm/compareDesc/index.js",
|
||||
"typings": "../typings.d.ts"
|
||||
}
|
||||
+2
@@ -0,0 +1,2 @@
|
||||
export const maxTime: number
|
||||
export const minTime: number
|
||||
+24
@@ -0,0 +1,24 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.minTime = exports.maxTime = void 0;
|
||||
|
||||
/**
|
||||
* Maximum allowed time.
|
||||
* @constant
|
||||
* @type {number}
|
||||
* @default
|
||||
*/
|
||||
var maxTime = Math.pow(10, 8) * 24 * 60 * 60 * 1000;
|
||||
/**
|
||||
* Minimum allowed time.
|
||||
* @constant
|
||||
* @type {number}
|
||||
* @default
|
||||
*/
|
||||
|
||||
exports.maxTime = maxTime;
|
||||
var minTime = -maxTime;
|
||||
exports.minTime = minTime;
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
// @flow
|
||||
|
||||
declare export var maxTime: number
|
||||
declare export var minTime: number
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
// This file is generated automatically by `scripts/build/typings.js`. Please, don't change it.
|
||||
|
||||
import { differenceInBusinessDays } from 'date-fns'
|
||||
export default differenceInBusinessDays
|
||||
+72
@@ -0,0 +1,72 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.default = differenceInBusinessDays;
|
||||
|
||||
var _index = _interopRequireDefault(require("../isValid/index.js"));
|
||||
|
||||
var _index2 = _interopRequireDefault(require("../isWeekend/index.js"));
|
||||
|
||||
var _index3 = _interopRequireDefault(require("../toDate/index.js"));
|
||||
|
||||
var _index4 = _interopRequireDefault(require("../differenceInCalendarDays/index.js"));
|
||||
|
||||
var _index5 = _interopRequireDefault(require("../addDays/index.js"));
|
||||
|
||||
var _index6 = _interopRequireDefault(require("../isSameDay/index.js"));
|
||||
|
||||
var _index7 = _interopRequireDefault(require("../_lib/toInteger/index.js"));
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
|
||||
/**
|
||||
* @name differenceInBusinessDays
|
||||
* @category Day Helpers
|
||||
* @summary Get the number of business days between the given dates.
|
||||
*
|
||||
* @description
|
||||
* Get the number of business day periods between the given dates.
|
||||
* Business days being days that arent in the weekend.
|
||||
* Like `differenceInCalendarDays`, the function removes the times from
|
||||
* the dates before calculating the difference.
|
||||
*
|
||||
* @param {Date|Number} dateLeft - the later date
|
||||
* @param {Date|Number} dateRight - the earlier date
|
||||
* @returns {Number} the number of business days
|
||||
* @throws {TypeError} 2 arguments required
|
||||
*
|
||||
* @example
|
||||
* // How many business days are between
|
||||
* // 10 January 2014 and 20 July 2014?
|
||||
* var result = differenceInBusinessDays(
|
||||
* new Date(2014, 6, 20),
|
||||
* new Date(2014, 0, 10)
|
||||
* )
|
||||
* //=> 136
|
||||
*/
|
||||
function differenceInBusinessDays(dirtyDateLeft, dirtyDateRight) {
|
||||
if (arguments.length < 2) {
|
||||
throw new TypeError('2 arguments required, but only ' + arguments.length + ' present');
|
||||
}
|
||||
|
||||
var dateLeft = (0, _index3.default)(dirtyDateLeft);
|
||||
var dateRight = (0, _index3.default)(dirtyDateRight);
|
||||
if (!(0, _index.default)(dateLeft) || !(0, _index.default)(dateRight)) return new Date(NaN);
|
||||
var calendarDifference = (0, _index4.default)(dateLeft, dateRight);
|
||||
var sign = calendarDifference < 0 ? -1 : 1;
|
||||
var weeks = (0, _index7.default)(calendarDifference / 7);
|
||||
var result = weeks * 5;
|
||||
dateRight = (0, _index5.default)(dateRight, weeks * 7); // the loop below will run at most 6 times to account for the remaining days that don't makeup a full week
|
||||
|
||||
while (!(0, _index6.default)(dateLeft, dateRight)) {
|
||||
// sign is used to account for both negative and positive differences
|
||||
result += (0, _index2.default)(dateRight) ? 0 : sign;
|
||||
dateRight = (0, _index5.default)(dateRight, sign);
|
||||
}
|
||||
|
||||
return result === 0 ? 0 : result;
|
||||
}
|
||||
|
||||
module.exports = exports.default;
|
||||
+41
@@ -0,0 +1,41 @@
|
||||
// @flow
|
||||
// This file is generated automatically by `scripts/build/typings.js`. Please, don't change it.
|
||||
|
||||
export type Interval = {
|
||||
start: Date | number,
|
||||
end: Date | number
|
||||
}
|
||||
|
||||
export type Locale = {
|
||||
formatDistance: (...args: Array<any>) => any,
|
||||
formatRelative: (...args: Array<any>) => any,
|
||||
localize: {
|
||||
ordinalNumber: (...args: Array<any>) => any,
|
||||
era: (...args: Array<any>) => any,
|
||||
quarter: (...args: Array<any>) => any,
|
||||
month: (...args: Array<any>) => any,
|
||||
day: (...args: Array<any>) => any,
|
||||
dayPeriod: (...args: Array<any>) => any
|
||||
},
|
||||
formatLong: Object,
|
||||
date: (...args: Array<any>) => any,
|
||||
time: (...args: Array<any>) => any,
|
||||
dateTime: (...args: Array<any>) => any,
|
||||
match: {
|
||||
ordinalNumber: (...args: Array<any>) => any,
|
||||
era: (...args: Array<any>) => any,
|
||||
quarter: (...args: Array<any>) => any,
|
||||
month: (...args: Array<any>) => any,
|
||||
day: (...args: Array<any>) => any,
|
||||
dayPeriod: (...args: Array<any>) => any
|
||||
},
|
||||
options?: {
|
||||
weekStartsOn?: 0 | 1 | 2 | 3 | 4 | 5 | 6,
|
||||
firstWeekContainsDate?: 1 | 2 | 3 | 4 | 5 | 6 | 7
|
||||
}
|
||||
}
|
||||
|
||||
declare module.exports: (
|
||||
dateLeft: Date | number,
|
||||
dateRight: Date | number
|
||||
) => number
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"sideEffects": false,
|
||||
"module": "../esm/differenceInBusinessDays/index.js",
|
||||
"typings": "../typings.d.ts"
|
||||
}
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
// This file is generated automatically by `scripts/build/typings.js`. Please, don't change it.
|
||||
|
||||
import { differenceInCalendarDays } from 'date-fns'
|
||||
export default differenceInCalendarDays
|
||||
+65
@@ -0,0 +1,65 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.default = differenceInCalendarDays;
|
||||
|
||||
var _index = _interopRequireDefault(require("../_lib/getTimezoneOffsetInMilliseconds/index.js"));
|
||||
|
||||
var _index2 = _interopRequireDefault(require("../startOfDay/index.js"));
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
|
||||
var MILLISECONDS_IN_DAY = 86400000;
|
||||
/**
|
||||
* @name differenceInCalendarDays
|
||||
* @category Day Helpers
|
||||
* @summary Get the number of calendar days between the given dates.
|
||||
*
|
||||
* @description
|
||||
* Get the number of calendar days between the given dates. This means that the times are removed
|
||||
* from the dates and then the difference in days is calculated.
|
||||
*
|
||||
* ### v2.0.0 breaking changes:
|
||||
*
|
||||
* - [Changes that are common for the whole library](https://github.com/date-fns/date-fns/blob/master/docs/upgradeGuide.md#Common-Changes).
|
||||
*
|
||||
* @param {Date|Number} dateLeft - the later date
|
||||
* @param {Date|Number} dateRight - the earlier date
|
||||
* @returns {Number} the number of calendar days
|
||||
* @throws {TypeError} 2 arguments required
|
||||
*
|
||||
* @example
|
||||
* // How many calendar days are between
|
||||
* // 2 July 2011 23:00:00 and 2 July 2012 00:00:00?
|
||||
* var result = differenceInCalendarDays(
|
||||
* new Date(2012, 6, 2, 0, 0),
|
||||
* new Date(2011, 6, 2, 23, 0)
|
||||
* )
|
||||
* //=> 366
|
||||
* // How many calendar days are between
|
||||
* // 2 July 2011 23:59:00 and 3 July 2011 00:01:00?
|
||||
* var result = differenceInCalendarDays(
|
||||
* new Date(2011, 6, 3, 0, 1),
|
||||
* new Date(2011, 6, 2, 23, 59)
|
||||
* )
|
||||
* //=> 1
|
||||
*/
|
||||
|
||||
function differenceInCalendarDays(dirtyDateLeft, dirtyDateRight) {
|
||||
if (arguments.length < 2) {
|
||||
throw new TypeError('2 arguments required, but only ' + arguments.length + ' present');
|
||||
}
|
||||
|
||||
var startOfDayLeft = (0, _index2.default)(dirtyDateLeft);
|
||||
var startOfDayRight = (0, _index2.default)(dirtyDateRight);
|
||||
var timestampLeft = startOfDayLeft.getTime() - (0, _index.default)(startOfDayLeft);
|
||||
var timestampRight = startOfDayRight.getTime() - (0, _index.default)(startOfDayRight); // Round the number of days to the nearest integer
|
||||
// because the number of milliseconds in a day is not constant
|
||||
// (e.g. it's different in the day of the daylight saving time clock shift)
|
||||
|
||||
return Math.round((timestampLeft - timestampRight) / MILLISECONDS_IN_DAY);
|
||||
}
|
||||
|
||||
module.exports = exports.default;
|
||||
+41
@@ -0,0 +1,41 @@
|
||||
// @flow
|
||||
// This file is generated automatically by `scripts/build/typings.js`. Please, don't change it.
|
||||
|
||||
export type Interval = {
|
||||
start: Date | number,
|
||||
end: Date | number
|
||||
}
|
||||
|
||||
export type Locale = {
|
||||
formatDistance: (...args: Array<any>) => any,
|
||||
formatRelative: (...args: Array<any>) => any,
|
||||
localize: {
|
||||
ordinalNumber: (...args: Array<any>) => any,
|
||||
era: (...args: Array<any>) => any,
|
||||
quarter: (...args: Array<any>) => any,
|
||||
month: (...args: Array<any>) => any,
|
||||
day: (...args: Array<any>) => any,
|
||||
dayPeriod: (...args: Array<any>) => any
|
||||
},
|
||||
formatLong: Object,
|
||||
date: (...args: Array<any>) => any,
|
||||
time: (...args: Array<any>) => any,
|
||||
dateTime: (...args: Array<any>) => any,
|
||||
match: {
|
||||
ordinalNumber: (...args: Array<any>) => any,
|
||||
era: (...args: Array<any>) => any,
|
||||
quarter: (...args: Array<any>) => any,
|
||||
month: (...args: Array<any>) => any,
|
||||
day: (...args: Array<any>) => any,
|
||||
dayPeriod: (...args: Array<any>) => any
|
||||
},
|
||||
options?: {
|
||||
weekStartsOn?: 0 | 1 | 2 | 3 | 4 | 5 | 6,
|
||||
firstWeekContainsDate?: 1 | 2 | 3 | 4 | 5 | 6 | 7
|
||||
}
|
||||
}
|
||||
|
||||
declare module.exports: (
|
||||
dateLeft: Date | number,
|
||||
dateRight: Date | number
|
||||
) => number
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"sideEffects": false,
|
||||
"module": "../esm/differenceInCalendarDays/index.js",
|
||||
"typings": "../typings.d.ts"
|
||||
}
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
// This file is generated automatically by `scripts/build/typings.js`. Please, don't change it.
|
||||
|
||||
import { differenceInCalendarISOWeekYears } from 'date-fns'
|
||||
export default differenceInCalendarISOWeekYears
|
||||
+52
@@ -0,0 +1,52 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.default = differenceInCalendarISOWeekYears;
|
||||
|
||||
var _index = _interopRequireDefault(require("../getISOWeekYear/index.js"));
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
|
||||
/**
|
||||
* @name differenceInCalendarISOWeekYears
|
||||
* @category ISO Week-Numbering Year Helpers
|
||||
* @summary Get the number of calendar ISO week-numbering years between the given dates.
|
||||
*
|
||||
* @description
|
||||
* Get the number of calendar ISO week-numbering years between the given dates.
|
||||
*
|
||||
* ISO week-numbering year: http://en.wikipedia.org/wiki/ISO_week_date
|
||||
*
|
||||
* ### v2.0.0 breaking changes:
|
||||
*
|
||||
* - [Changes that are common for the whole library](https://github.com/date-fns/date-fns/blob/master/docs/upgradeGuide.md#Common-Changes).
|
||||
*
|
||||
* - The function was renamed from `differenceInCalendarISOYears` to `differenceInCalendarISOWeekYears`.
|
||||
* "ISO week year" is short for [ISO week-numbering year](https://en.wikipedia.org/wiki/ISO_week_date).
|
||||
* This change makes the name consistent with
|
||||
* locale-dependent week-numbering year helpers, e.g., `addWeekYears`.
|
||||
*
|
||||
* @param {Date|Number} dateLeft - the later date
|
||||
* @param {Date|Number} dateRight - the earlier date
|
||||
* @returns {Number} the number of calendar ISO week-numbering years
|
||||
* @throws {TypeError} 2 arguments required
|
||||
*
|
||||
* @example
|
||||
* // How many calendar ISO week-numbering years are 1 January 2010 and 1 January 2012?
|
||||
* var result = differenceInCalendarISOWeekYears(
|
||||
* new Date(2012, 0, 1),
|
||||
* new Date(2010, 0, 1)
|
||||
* )
|
||||
* //=> 2
|
||||
*/
|
||||
function differenceInCalendarISOWeekYears(dirtyDateLeft, dirtyDateRight) {
|
||||
if (arguments.length < 2) {
|
||||
throw new TypeError('2 arguments required, but only ' + arguments.length + ' present');
|
||||
}
|
||||
|
||||
return (0, _index.default)(dirtyDateLeft) - (0, _index.default)(dirtyDateRight);
|
||||
}
|
||||
|
||||
module.exports = exports.default;
|
||||
Generated
Vendored
+41
@@ -0,0 +1,41 @@
|
||||
// @flow
|
||||
// This file is generated automatically by `scripts/build/typings.js`. Please, don't change it.
|
||||
|
||||
export type Interval = {
|
||||
start: Date | number,
|
||||
end: Date | number
|
||||
}
|
||||
|
||||
export type Locale = {
|
||||
formatDistance: (...args: Array<any>) => any,
|
||||
formatRelative: (...args: Array<any>) => any,
|
||||
localize: {
|
||||
ordinalNumber: (...args: Array<any>) => any,
|
||||
era: (...args: Array<any>) => any,
|
||||
quarter: (...args: Array<any>) => any,
|
||||
month: (...args: Array<any>) => any,
|
||||
day: (...args: Array<any>) => any,
|
||||
dayPeriod: (...args: Array<any>) => any
|
||||
},
|
||||
formatLong: Object,
|
||||
date: (...args: Array<any>) => any,
|
||||
time: (...args: Array<any>) => any,
|
||||
dateTime: (...args: Array<any>) => any,
|
||||
match: {
|
||||
ordinalNumber: (...args: Array<any>) => any,
|
||||
era: (...args: Array<any>) => any,
|
||||
quarter: (...args: Array<any>) => any,
|
||||
month: (...args: Array<any>) => any,
|
||||
day: (...args: Array<any>) => any,
|
||||
dayPeriod: (...args: Array<any>) => any
|
||||
},
|
||||
options?: {
|
||||
weekStartsOn?: 0 | 1 | 2 | 3 | 4 | 5 | 6,
|
||||
firstWeekContainsDate?: 1 | 2 | 3 | 4 | 5 | 6 | 7
|
||||
}
|
||||
}
|
||||
|
||||
declare module.exports: (
|
||||
dateLeft: Date | number,
|
||||
dateRight: Date | number
|
||||
) => number
|
||||
Generated
Vendored
+5
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"sideEffects": false,
|
||||
"module": "../esm/differenceInCalendarISOWeekYears/index.js",
|
||||
"typings": "../typings.d.ts"
|
||||
}
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
// This file is generated automatically by `scripts/build/typings.js`. Please, don't change it.
|
||||
|
||||
import { differenceInCalendarISOWeeks } from 'date-fns'
|
||||
export default differenceInCalendarISOWeeks
|
||||
+58
@@ -0,0 +1,58 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.default = differenceInCalendarISOWeeks;
|
||||
|
||||
var _index = _interopRequireDefault(require("../_lib/getTimezoneOffsetInMilliseconds/index.js"));
|
||||
|
||||
var _index2 = _interopRequireDefault(require("../startOfISOWeek/index.js"));
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
|
||||
var MILLISECONDS_IN_WEEK = 604800000;
|
||||
/**
|
||||
* @name differenceInCalendarISOWeeks
|
||||
* @category ISO Week Helpers
|
||||
* @summary Get the number of calendar ISO weeks between the given dates.
|
||||
*
|
||||
* @description
|
||||
* Get the number of calendar ISO weeks between the given dates.
|
||||
*
|
||||
* ISO week-numbering year: http://en.wikipedia.org/wiki/ISO_week_date
|
||||
*
|
||||
* ### v2.0.0 breaking changes:
|
||||
*
|
||||
* - [Changes that are common for the whole library](https://github.com/date-fns/date-fns/blob/master/docs/upgradeGuide.md#Common-Changes).
|
||||
*
|
||||
* @param {Date|Number} dateLeft - the later date
|
||||
* @param {Date|Number} dateRight - the earlier date
|
||||
* @returns {Number} the number of calendar ISO weeks
|
||||
* @throws {TypeError} 2 arguments required
|
||||
*
|
||||
* @example
|
||||
* // How many calendar ISO weeks are between 6 July 2014 and 21 July 2014?
|
||||
* var result = differenceInCalendarISOWeeks(
|
||||
* new Date(2014, 6, 21),
|
||||
* new Date(2014, 6, 6)
|
||||
* )
|
||||
* //=> 3
|
||||
*/
|
||||
|
||||
function differenceInCalendarISOWeeks(dirtyDateLeft, dirtyDateRight) {
|
||||
if (arguments.length < 2) {
|
||||
throw new TypeError('2 arguments required, but only ' + arguments.length + ' present');
|
||||
}
|
||||
|
||||
var startOfISOWeekLeft = (0, _index2.default)(dirtyDateLeft);
|
||||
var startOfISOWeekRight = (0, _index2.default)(dirtyDateRight);
|
||||
var timestampLeft = startOfISOWeekLeft.getTime() - (0, _index.default)(startOfISOWeekLeft);
|
||||
var timestampRight = startOfISOWeekRight.getTime() - (0, _index.default)(startOfISOWeekRight); // Round the number of days to the nearest integer
|
||||
// because the number of milliseconds in a week is not constant
|
||||
// (e.g. it's different in the week of the daylight saving time clock shift)
|
||||
|
||||
return Math.round((timestampLeft - timestampRight) / MILLISECONDS_IN_WEEK);
|
||||
}
|
||||
|
||||
module.exports = exports.default;
|
||||
+41
@@ -0,0 +1,41 @@
|
||||
// @flow
|
||||
// This file is generated automatically by `scripts/build/typings.js`. Please, don't change it.
|
||||
|
||||
export type Interval = {
|
||||
start: Date | number,
|
||||
end: Date | number
|
||||
}
|
||||
|
||||
export type Locale = {
|
||||
formatDistance: (...args: Array<any>) => any,
|
||||
formatRelative: (...args: Array<any>) => any,
|
||||
localize: {
|
||||
ordinalNumber: (...args: Array<any>) => any,
|
||||
era: (...args: Array<any>) => any,
|
||||
quarter: (...args: Array<any>) => any,
|
||||
month: (...args: Array<any>) => any,
|
||||
day: (...args: Array<any>) => any,
|
||||
dayPeriod: (...args: Array<any>) => any
|
||||
},
|
||||
formatLong: Object,
|
||||
date: (...args: Array<any>) => any,
|
||||
time: (...args: Array<any>) => any,
|
||||
dateTime: (...args: Array<any>) => any,
|
||||
match: {
|
||||
ordinalNumber: (...args: Array<any>) => any,
|
||||
era: (...args: Array<any>) => any,
|
||||
quarter: (...args: Array<any>) => any,
|
||||
month: (...args: Array<any>) => any,
|
||||
day: (...args: Array<any>) => any,
|
||||
dayPeriod: (...args: Array<any>) => any
|
||||
},
|
||||
options?: {
|
||||
weekStartsOn?: 0 | 1 | 2 | 3 | 4 | 5 | 6,
|
||||
firstWeekContainsDate?: 1 | 2 | 3 | 4 | 5 | 6 | 7
|
||||
}
|
||||
}
|
||||
|
||||
declare module.exports: (
|
||||
dateLeft: Date | number,
|
||||
dateRight: Date | number
|
||||
) => number
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"sideEffects": false,
|
||||
"module": "../esm/differenceInCalendarISOWeeks/index.js",
|
||||
"typings": "../typings.d.ts"
|
||||
}
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
// This file is generated automatically by `scripts/build/typings.js`. Please, don't change it.
|
||||
|
||||
import { differenceInCalendarMonths } from 'date-fns'
|
||||
export default differenceInCalendarMonths
|
||||
+49
@@ -0,0 +1,49 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.default = differenceInCalendarMonths;
|
||||
|
||||
var _index = _interopRequireDefault(require("../toDate/index.js"));
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
|
||||
/**
|
||||
* @name differenceInCalendarMonths
|
||||
* @category Month Helpers
|
||||
* @summary Get the number of calendar months between the given dates.
|
||||
*
|
||||
* @description
|
||||
* Get the number of calendar months between the given dates.
|
||||
*
|
||||
* ### v2.0.0 breaking changes:
|
||||
*
|
||||
* - [Changes that are common for the whole library](https://github.com/date-fns/date-fns/blob/master/docs/upgradeGuide.md#Common-Changes).
|
||||
*
|
||||
* @param {Date|Number} dateLeft - the later date
|
||||
* @param {Date|Number} dateRight - the earlier date
|
||||
* @returns {Number} the number of calendar months
|
||||
* @throws {TypeError} 2 arguments required
|
||||
*
|
||||
* @example
|
||||
* // How many calendar months are between 31 January 2014 and 1 September 2014?
|
||||
* var result = differenceInCalendarMonths(
|
||||
* new Date(2014, 8, 1),
|
||||
* new Date(2014, 0, 31)
|
||||
* )
|
||||
* //=> 8
|
||||
*/
|
||||
function differenceInCalendarMonths(dirtyDateLeft, dirtyDateRight) {
|
||||
if (arguments.length < 2) {
|
||||
throw new TypeError('2 arguments required, but only ' + arguments.length + ' present');
|
||||
}
|
||||
|
||||
var dateLeft = (0, _index.default)(dirtyDateLeft);
|
||||
var dateRight = (0, _index.default)(dirtyDateRight);
|
||||
var yearDiff = dateLeft.getFullYear() - dateRight.getFullYear();
|
||||
var monthDiff = dateLeft.getMonth() - dateRight.getMonth();
|
||||
return yearDiff * 12 + monthDiff;
|
||||
}
|
||||
|
||||
module.exports = exports.default;
|
||||
+41
@@ -0,0 +1,41 @@
|
||||
// @flow
|
||||
// This file is generated automatically by `scripts/build/typings.js`. Please, don't change it.
|
||||
|
||||
export type Interval = {
|
||||
start: Date | number,
|
||||
end: Date | number
|
||||
}
|
||||
|
||||
export type Locale = {
|
||||
formatDistance: (...args: Array<any>) => any,
|
||||
formatRelative: (...args: Array<any>) => any,
|
||||
localize: {
|
||||
ordinalNumber: (...args: Array<any>) => any,
|
||||
era: (...args: Array<any>) => any,
|
||||
quarter: (...args: Array<any>) => any,
|
||||
month: (...args: Array<any>) => any,
|
||||
day: (...args: Array<any>) => any,
|
||||
dayPeriod: (...args: Array<any>) => any
|
||||
},
|
||||
formatLong: Object,
|
||||
date: (...args: Array<any>) => any,
|
||||
time: (...args: Array<any>) => any,
|
||||
dateTime: (...args: Array<any>) => any,
|
||||
match: {
|
||||
ordinalNumber: (...args: Array<any>) => any,
|
||||
era: (...args: Array<any>) => any,
|
||||
quarter: (...args: Array<any>) => any,
|
||||
month: (...args: Array<any>) => any,
|
||||
day: (...args: Array<any>) => any,
|
||||
dayPeriod: (...args: Array<any>) => any
|
||||
},
|
||||
options?: {
|
||||
weekStartsOn?: 0 | 1 | 2 | 3 | 4 | 5 | 6,
|
||||
firstWeekContainsDate?: 1 | 2 | 3 | 4 | 5 | 6 | 7
|
||||
}
|
||||
}
|
||||
|
||||
declare module.exports: (
|
||||
dateLeft: Date | number,
|
||||
dateRight: Date | number
|
||||
) => number
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"sideEffects": false,
|
||||
"module": "../esm/differenceInCalendarMonths/index.js",
|
||||
"typings": "../typings.d.ts"
|
||||
}
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
// This file is generated automatically by `scripts/build/typings.js`. Please, don't change it.
|
||||
|
||||
import { differenceInCalendarQuarters } from 'date-fns'
|
||||
export default differenceInCalendarQuarters
|
||||
+51
@@ -0,0 +1,51 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.default = differenceInCalendarQuarters;
|
||||
|
||||
var _index = _interopRequireDefault(require("../getQuarter/index.js"));
|
||||
|
||||
var _index2 = _interopRequireDefault(require("../toDate/index.js"));
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
|
||||
/**
|
||||
* @name differenceInCalendarQuarters
|
||||
* @category Quarter Helpers
|
||||
* @summary Get the number of calendar quarters between the given dates.
|
||||
*
|
||||
* @description
|
||||
* Get the number of calendar quarters between the given dates.
|
||||
*
|
||||
* ### v2.0.0 breaking changes:
|
||||
*
|
||||
* - [Changes that are common for the whole library](https://github.com/date-fns/date-fns/blob/master/docs/upgradeGuide.md#Common-Changes).
|
||||
*
|
||||
* @param {Date|Number} dateLeft - the later date
|
||||
* @param {Date|Number} dateRight - the earlier date
|
||||
* @returns {Number} the number of calendar quarters
|
||||
* @throws {TypeError} 2 arguments required
|
||||
*
|
||||
* @example
|
||||
* // How many calendar quarters are between 31 December 2013 and 2 July 2014?
|
||||
* var result = differenceInCalendarQuarters(
|
||||
* new Date(2014, 6, 2),
|
||||
* new Date(2013, 11, 31)
|
||||
* )
|
||||
* //=> 3
|
||||
*/
|
||||
function differenceInCalendarQuarters(dirtyDateLeft, dirtyDateRight) {
|
||||
if (arguments.length < 2) {
|
||||
throw new TypeError('2 arguments required, but only ' + arguments.length + ' present');
|
||||
}
|
||||
|
||||
var dateLeft = (0, _index2.default)(dirtyDateLeft);
|
||||
var dateRight = (0, _index2.default)(dirtyDateRight);
|
||||
var yearDiff = dateLeft.getFullYear() - dateRight.getFullYear();
|
||||
var quarterDiff = (0, _index.default)(dateLeft) - (0, _index.default)(dateRight);
|
||||
return yearDiff * 4 + quarterDiff;
|
||||
}
|
||||
|
||||
module.exports = exports.default;
|
||||
+41
@@ -0,0 +1,41 @@
|
||||
// @flow
|
||||
// This file is generated automatically by `scripts/build/typings.js`. Please, don't change it.
|
||||
|
||||
export type Interval = {
|
||||
start: Date | number,
|
||||
end: Date | number
|
||||
}
|
||||
|
||||
export type Locale = {
|
||||
formatDistance: (...args: Array<any>) => any,
|
||||
formatRelative: (...args: Array<any>) => any,
|
||||
localize: {
|
||||
ordinalNumber: (...args: Array<any>) => any,
|
||||
era: (...args: Array<any>) => any,
|
||||
quarter: (...args: Array<any>) => any,
|
||||
month: (...args: Array<any>) => any,
|
||||
day: (...args: Array<any>) => any,
|
||||
dayPeriod: (...args: Array<any>) => any
|
||||
},
|
||||
formatLong: Object,
|
||||
date: (...args: Array<any>) => any,
|
||||
time: (...args: Array<any>) => any,
|
||||
dateTime: (...args: Array<any>) => any,
|
||||
match: {
|
||||
ordinalNumber: (...args: Array<any>) => any,
|
||||
era: (...args: Array<any>) => any,
|
||||
quarter: (...args: Array<any>) => any,
|
||||
month: (...args: Array<any>) => any,
|
||||
day: (...args: Array<any>) => any,
|
||||
dayPeriod: (...args: Array<any>) => any
|
||||
},
|
||||
options?: {
|
||||
weekStartsOn?: 0 | 1 | 2 | 3 | 4 | 5 | 6,
|
||||
firstWeekContainsDate?: 1 | 2 | 3 | 4 | 5 | 6 | 7
|
||||
}
|
||||
}
|
||||
|
||||
declare module.exports: (
|
||||
dateLeft: Date | number,
|
||||
dateRight: Date | number
|
||||
) => number
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"sideEffects": false,
|
||||
"module": "../esm/differenceInCalendarQuarters/index.js",
|
||||
"typings": "../typings.d.ts"
|
||||
}
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
// This file is generated automatically by `scripts/build/typings.js`. Please, don't change it.
|
||||
|
||||
import { differenceInCalendarWeeks } from 'date-fns'
|
||||
export default differenceInCalendarWeeks
|
||||
+70
@@ -0,0 +1,70 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.default = differenceInCalendarWeeks;
|
||||
|
||||
var _index = _interopRequireDefault(require("../startOfWeek/index.js"));
|
||||
|
||||
var _index2 = _interopRequireDefault(require("../_lib/getTimezoneOffsetInMilliseconds/index.js"));
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
|
||||
var MILLISECONDS_IN_WEEK = 604800000;
|
||||
/**
|
||||
* @name differenceInCalendarWeeks
|
||||
* @category Week Helpers
|
||||
* @summary Get the number of calendar weeks between the given dates.
|
||||
*
|
||||
* @description
|
||||
* Get the number of calendar weeks between the given dates.
|
||||
*
|
||||
* ### v2.0.0 breaking changes:
|
||||
*
|
||||
* - [Changes that are common for the whole library](https://github.com/date-fns/date-fns/blob/master/docs/upgradeGuide.md#Common-Changes).
|
||||
*
|
||||
* @param {Date|Number} dateLeft - the later date
|
||||
* @param {Date|Number} dateRight - the earlier date
|
||||
* @param {Object} [options] - an object with options.
|
||||
* @param {Locale} [options.locale=defaultLocale] - the locale object. See [Locale]{@link https://date-fns.org/docs/Locale}
|
||||
* @param {0|1|2|3|4|5|6} [options.weekStartsOn=0] - the index of the first day of the week (0 - Sunday)
|
||||
* @returns {Number} the number of calendar weeks
|
||||
* @throws {TypeError} 2 arguments required
|
||||
* @throws {RangeError} `options.weekStartsOn` must be between 0 and 6
|
||||
*
|
||||
* @example
|
||||
* // How many calendar weeks are between 5 July 2014 and 20 July 2014?
|
||||
* var result = differenceInCalendarWeeks(
|
||||
* new Date(2014, 6, 20),
|
||||
* new Date(2014, 6, 5)
|
||||
* )
|
||||
* //=> 3
|
||||
*
|
||||
* @example
|
||||
* // If the week starts on Monday,
|
||||
* // how many calendar weeks are between 5 July 2014 and 20 July 2014?
|
||||
* var result = differenceInCalendarWeeks(
|
||||
* new Date(2014, 6, 20),
|
||||
* new Date(2014, 6, 5),
|
||||
* { weekStartsOn: 1 }
|
||||
* )
|
||||
* //=> 2
|
||||
*/
|
||||
|
||||
function differenceInCalendarWeeks(dirtyDateLeft, dirtyDateRight, dirtyOptions) {
|
||||
if (arguments.length < 2) {
|
||||
throw new TypeError('2 arguments required, but only ' + arguments.length + ' present');
|
||||
}
|
||||
|
||||
var startOfWeekLeft = (0, _index.default)(dirtyDateLeft, dirtyOptions);
|
||||
var startOfWeekRight = (0, _index.default)(dirtyDateRight, dirtyOptions);
|
||||
var timestampLeft = startOfWeekLeft.getTime() - (0, _index2.default)(startOfWeekLeft);
|
||||
var timestampRight = startOfWeekRight.getTime() - (0, _index2.default)(startOfWeekRight); // Round the number of days to the nearest integer
|
||||
// because the number of milliseconds in a week is not constant
|
||||
// (e.g. it's different in the week of the daylight saving time clock shift)
|
||||
|
||||
return Math.round((timestampLeft - timestampRight) / MILLISECONDS_IN_WEEK);
|
||||
}
|
||||
|
||||
module.exports = exports.default;
|
||||
+45
@@ -0,0 +1,45 @@
|
||||
// @flow
|
||||
// This file is generated automatically by `scripts/build/typings.js`. Please, don't change it.
|
||||
|
||||
export type Interval = {
|
||||
start: Date | number,
|
||||
end: Date | number
|
||||
}
|
||||
|
||||
export type Locale = {
|
||||
formatDistance: (...args: Array<any>) => any,
|
||||
formatRelative: (...args: Array<any>) => any,
|
||||
localize: {
|
||||
ordinalNumber: (...args: Array<any>) => any,
|
||||
era: (...args: Array<any>) => any,
|
||||
quarter: (...args: Array<any>) => any,
|
||||
month: (...args: Array<any>) => any,
|
||||
day: (...args: Array<any>) => any,
|
||||
dayPeriod: (...args: Array<any>) => any
|
||||
},
|
||||
formatLong: Object,
|
||||
date: (...args: Array<any>) => any,
|
||||
time: (...args: Array<any>) => any,
|
||||
dateTime: (...args: Array<any>) => any,
|
||||
match: {
|
||||
ordinalNumber: (...args: Array<any>) => any,
|
||||
era: (...args: Array<any>) => any,
|
||||
quarter: (...args: Array<any>) => any,
|
||||
month: (...args: Array<any>) => any,
|
||||
day: (...args: Array<any>) => any,
|
||||
dayPeriod: (...args: Array<any>) => any
|
||||
},
|
||||
options?: {
|
||||
weekStartsOn?: 0 | 1 | 2 | 3 | 4 | 5 | 6,
|
||||
firstWeekContainsDate?: 1 | 2 | 3 | 4 | 5 | 6 | 7
|
||||
}
|
||||
}
|
||||
|
||||
declare module.exports: (
|
||||
dateLeft: Date | number,
|
||||
dateRight: Date | number,
|
||||
options?: {
|
||||
locale?: Locale,
|
||||
weekStartsOn?: 0 | 1 | 2 | 3 | 4 | 5 | 6
|
||||
}
|
||||
) => number
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"sideEffects": false,
|
||||
"module": "../esm/differenceInCalendarWeeks/index.js",
|
||||
"typings": "../typings.d.ts"
|
||||
}
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
// This file is generated automatically by `scripts/build/typings.js`. Please, don't change it.
|
||||
|
||||
import { differenceInCalendarYears } from 'date-fns'
|
||||
export default differenceInCalendarYears
|
||||
+47
@@ -0,0 +1,47 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.default = differenceInCalendarYears;
|
||||
|
||||
var _index = _interopRequireDefault(require("../toDate/index.js"));
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
|
||||
/**
|
||||
* @name differenceInCalendarYears
|
||||
* @category Year Helpers
|
||||
* @summary Get the number of calendar years between the given dates.
|
||||
*
|
||||
* @description
|
||||
* Get the number of calendar years between the given dates.
|
||||
*
|
||||
* ### v2.0.0 breaking changes:
|
||||
*
|
||||
* - [Changes that are common for the whole library](https://github.com/date-fns/date-fns/blob/master/docs/upgradeGuide.md#Common-Changes).
|
||||
*
|
||||
* @param {Date|Number} dateLeft - the later date
|
||||
* @param {Date|Number} dateRight - the earlier date
|
||||
* @returns {Number} the number of calendar years
|
||||
* @throws {TypeError} 2 arguments required
|
||||
*
|
||||
* @example
|
||||
* // How many calendar years are between 31 December 2013 and 11 February 2015?
|
||||
* var result = differenceInCalendarYears(
|
||||
* new Date(2015, 1, 11),
|
||||
* new Date(2013, 11, 31)
|
||||
* )
|
||||
* //=> 2
|
||||
*/
|
||||
function differenceInCalendarYears(dirtyDateLeft, dirtyDateRight) {
|
||||
if (arguments.length < 2) {
|
||||
throw new TypeError('2 arguments required, but only ' + arguments.length + ' present');
|
||||
}
|
||||
|
||||
var dateLeft = (0, _index.default)(dirtyDateLeft);
|
||||
var dateRight = (0, _index.default)(dirtyDateRight);
|
||||
return dateLeft.getFullYear() - dateRight.getFullYear();
|
||||
}
|
||||
|
||||
module.exports = exports.default;
|
||||
+41
@@ -0,0 +1,41 @@
|
||||
// @flow
|
||||
// This file is generated automatically by `scripts/build/typings.js`. Please, don't change it.
|
||||
|
||||
export type Interval = {
|
||||
start: Date | number,
|
||||
end: Date | number
|
||||
}
|
||||
|
||||
export type Locale = {
|
||||
formatDistance: (...args: Array<any>) => any,
|
||||
formatRelative: (...args: Array<any>) => any,
|
||||
localize: {
|
||||
ordinalNumber: (...args: Array<any>) => any,
|
||||
era: (...args: Array<any>) => any,
|
||||
quarter: (...args: Array<any>) => any,
|
||||
month: (...args: Array<any>) => any,
|
||||
day: (...args: Array<any>) => any,
|
||||
dayPeriod: (...args: Array<any>) => any
|
||||
},
|
||||
formatLong: Object,
|
||||
date: (...args: Array<any>) => any,
|
||||
time: (...args: Array<any>) => any,
|
||||
dateTime: (...args: Array<any>) => any,
|
||||
match: {
|
||||
ordinalNumber: (...args: Array<any>) => any,
|
||||
era: (...args: Array<any>) => any,
|
||||
quarter: (...args: Array<any>) => any,
|
||||
month: (...args: Array<any>) => any,
|
||||
day: (...args: Array<any>) => any,
|
||||
dayPeriod: (...args: Array<any>) => any
|
||||
},
|
||||
options?: {
|
||||
weekStartsOn?: 0 | 1 | 2 | 3 | 4 | 5 | 6,
|
||||
firstWeekContainsDate?: 1 | 2 | 3 | 4 | 5 | 6 | 7
|
||||
}
|
||||
}
|
||||
|
||||
declare module.exports: (
|
||||
dateLeft: Date | number,
|
||||
dateRight: Date | number
|
||||
) => number
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"sideEffects": false,
|
||||
"module": "../esm/differenceInCalendarYears/index.js",
|
||||
"typings": "../typings.d.ts"
|
||||
}
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
// This file is generated automatically by `scripts/build/typings.js`. Please, don't change it.
|
||||
|
||||
import { differenceInDays } from 'date-fns'
|
||||
export default differenceInDays
|
||||
+67
@@ -0,0 +1,67 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.default = differenceInDays;
|
||||
|
||||
var _index = _interopRequireDefault(require("../toDate/index.js"));
|
||||
|
||||
var _index2 = _interopRequireDefault(require("../differenceInCalendarDays/index.js"));
|
||||
|
||||
var _index3 = _interopRequireDefault(require("../compareAsc/index.js"));
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
|
||||
/**
|
||||
* @name differenceInDays
|
||||
* @category Day Helpers
|
||||
* @summary Get the number of full days between the given dates.
|
||||
*
|
||||
* @description
|
||||
* Get the number of full day periods between the given dates.
|
||||
*
|
||||
* ### v2.0.0 breaking changes:
|
||||
*
|
||||
* - [Changes that are common for the whole library](https://github.com/date-fns/date-fns/blob/master/docs/upgradeGuide.md#Common-Changes).
|
||||
*
|
||||
* @param {Date|Number} dateLeft - the later date
|
||||
* @param {Date|Number} dateRight - the earlier date
|
||||
* @returns {Number} the number of full days
|
||||
* @throws {TypeError} 2 arguments required
|
||||
*
|
||||
* @example
|
||||
* // How many full days are between
|
||||
* // 2 July 2011 23:00:00 and 2 July 2012 00:00:00?
|
||||
* var result = differenceInDays(
|
||||
* new Date(2012, 6, 2, 0, 0),
|
||||
* new Date(2011, 6, 2, 23, 0)
|
||||
* )
|
||||
* //=> 365
|
||||
* // How many days are between
|
||||
* // 2 July 2011 23:59:00 and 3 July 2011 00:01:00?
|
||||
* var result = differenceInDays(
|
||||
* new Date(2011, 6, 3, 0, 1),
|
||||
* new Date(2011, 6, 2, 23, 59)
|
||||
* )
|
||||
* //=> 0
|
||||
*/
|
||||
function differenceInDays(dirtyDateLeft, dirtyDateRight) {
|
||||
if (arguments.length < 2) {
|
||||
throw new TypeError('2 arguments required, but only ' + arguments.length + ' present');
|
||||
}
|
||||
|
||||
var dateLeft = (0, _index.default)(dirtyDateLeft);
|
||||
var dateRight = (0, _index.default)(dirtyDateRight);
|
||||
var sign = (0, _index3.default)(dateLeft, dateRight);
|
||||
var difference = Math.abs((0, _index2.default)(dateLeft, dateRight));
|
||||
dateLeft.setDate(dateLeft.getDate() - sign * difference); // Math.abs(diff in full days - diff in calendar days) === 1 if last calendar day is not full
|
||||
// If so, result must be decreased by 1 in absolute value
|
||||
|
||||
var isLastDayNotFull = (0, _index3.default)(dateLeft, dateRight) === -sign;
|
||||
var result = sign * (difference - isLastDayNotFull); // Prevent negative zero
|
||||
|
||||
return result === 0 ? 0 : result;
|
||||
}
|
||||
|
||||
module.exports = exports.default;
|
||||
+41
@@ -0,0 +1,41 @@
|
||||
// @flow
|
||||
// This file is generated automatically by `scripts/build/typings.js`. Please, don't change it.
|
||||
|
||||
export type Interval = {
|
||||
start: Date | number,
|
||||
end: Date | number
|
||||
}
|
||||
|
||||
export type Locale = {
|
||||
formatDistance: (...args: Array<any>) => any,
|
||||
formatRelative: (...args: Array<any>) => any,
|
||||
localize: {
|
||||
ordinalNumber: (...args: Array<any>) => any,
|
||||
era: (...args: Array<any>) => any,
|
||||
quarter: (...args: Array<any>) => any,
|
||||
month: (...args: Array<any>) => any,
|
||||
day: (...args: Array<any>) => any,
|
||||
dayPeriod: (...args: Array<any>) => any
|
||||
},
|
||||
formatLong: Object,
|
||||
date: (...args: Array<any>) => any,
|
||||
time: (...args: Array<any>) => any,
|
||||
dateTime: (...args: Array<any>) => any,
|
||||
match: {
|
||||
ordinalNumber: (...args: Array<any>) => any,
|
||||
era: (...args: Array<any>) => any,
|
||||
quarter: (...args: Array<any>) => any,
|
||||
month: (...args: Array<any>) => any,
|
||||
day: (...args: Array<any>) => any,
|
||||
dayPeriod: (...args: Array<any>) => any
|
||||
},
|
||||
options?: {
|
||||
weekStartsOn?: 0 | 1 | 2 | 3 | 4 | 5 | 6,
|
||||
firstWeekContainsDate?: 1 | 2 | 3 | 4 | 5 | 6 | 7
|
||||
}
|
||||
}
|
||||
|
||||
declare module.exports: (
|
||||
dateLeft: Date | number,
|
||||
dateRight: Date | number
|
||||
) => number
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"sideEffects": false,
|
||||
"module": "../esm/differenceInDays/index.js",
|
||||
"typings": "../typings.d.ts"
|
||||
}
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
// This file is generated automatically by `scripts/build/typings.js`. Please, don't change it.
|
||||
|
||||
import { differenceInHours } from 'date-fns'
|
||||
export default differenceInHours
|
||||
+48
@@ -0,0 +1,48 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.default = differenceInHours;
|
||||
|
||||
var _index = _interopRequireDefault(require("../differenceInMilliseconds/index.js"));
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
|
||||
var MILLISECONDS_IN_HOUR = 3600000;
|
||||
/**
|
||||
* @name differenceInHours
|
||||
* @category Hour Helpers
|
||||
* @summary Get the number of hours between the given dates.
|
||||
*
|
||||
* @description
|
||||
* Get the number of hours between the given dates.
|
||||
*
|
||||
* ### v2.0.0 breaking changes:
|
||||
*
|
||||
* - [Changes that are common for the whole library](https://github.com/date-fns/date-fns/blob/master/docs/upgradeGuide.md#Common-Changes).
|
||||
*
|
||||
* @param {Date|Number} dateLeft - the later date
|
||||
* @param {Date|Number} dateRight - the earlier date
|
||||
* @returns {Number} the number of hours
|
||||
* @throws {TypeError} 2 arguments required
|
||||
*
|
||||
* @example
|
||||
* // How many hours are between 2 July 2014 06:50:00 and 2 July 2014 19:00:00?
|
||||
* var result = differenceInHours(
|
||||
* new Date(2014, 6, 2, 19, 0),
|
||||
* new Date(2014, 6, 2, 6, 50)
|
||||
* )
|
||||
* //=> 12
|
||||
*/
|
||||
|
||||
function differenceInHours(dirtyDateLeft, dirtyDateRight) {
|
||||
if (arguments.length < 2) {
|
||||
throw new TypeError('2 arguments required, but only ' + arguments.length + ' present');
|
||||
}
|
||||
|
||||
var diff = (0, _index.default)(dirtyDateLeft, dirtyDateRight) / MILLISECONDS_IN_HOUR;
|
||||
return diff > 0 ? Math.floor(diff) : Math.ceil(diff);
|
||||
}
|
||||
|
||||
module.exports = exports.default;
|
||||
+41
@@ -0,0 +1,41 @@
|
||||
// @flow
|
||||
// This file is generated automatically by `scripts/build/typings.js`. Please, don't change it.
|
||||
|
||||
export type Interval = {
|
||||
start: Date | number,
|
||||
end: Date | number
|
||||
}
|
||||
|
||||
export type Locale = {
|
||||
formatDistance: (...args: Array<any>) => any,
|
||||
formatRelative: (...args: Array<any>) => any,
|
||||
localize: {
|
||||
ordinalNumber: (...args: Array<any>) => any,
|
||||
era: (...args: Array<any>) => any,
|
||||
quarter: (...args: Array<any>) => any,
|
||||
month: (...args: Array<any>) => any,
|
||||
day: (...args: Array<any>) => any,
|
||||
dayPeriod: (...args: Array<any>) => any
|
||||
},
|
||||
formatLong: Object,
|
||||
date: (...args: Array<any>) => any,
|
||||
time: (...args: Array<any>) => any,
|
||||
dateTime: (...args: Array<any>) => any,
|
||||
match: {
|
||||
ordinalNumber: (...args: Array<any>) => any,
|
||||
era: (...args: Array<any>) => any,
|
||||
quarter: (...args: Array<any>) => any,
|
||||
month: (...args: Array<any>) => any,
|
||||
day: (...args: Array<any>) => any,
|
||||
dayPeriod: (...args: Array<any>) => any
|
||||
},
|
||||
options?: {
|
||||
weekStartsOn?: 0 | 1 | 2 | 3 | 4 | 5 | 6,
|
||||
firstWeekContainsDate?: 1 | 2 | 3 | 4 | 5 | 6 | 7
|
||||
}
|
||||
}
|
||||
|
||||
declare module.exports: (
|
||||
dateLeft: Date | number,
|
||||
dateRight: Date | number
|
||||
) => number
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"sideEffects": false,
|
||||
"module": "../esm/differenceInHours/index.js",
|
||||
"typings": "../typings.d.ts"
|
||||
}
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
// This file is generated automatically by `scripts/build/typings.js`. Please, don't change it.
|
||||
|
||||
import { differenceInISOWeekYears } from 'date-fns'
|
||||
export default differenceInISOWeekYears
|
||||
+69
@@ -0,0 +1,69 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.default = differenceInISOWeekYears;
|
||||
|
||||
var _index = _interopRequireDefault(require("../toDate/index.js"));
|
||||
|
||||
var _index2 = _interopRequireDefault(require("../differenceInCalendarISOWeekYears/index.js"));
|
||||
|
||||
var _index3 = _interopRequireDefault(require("../compareAsc/index.js"));
|
||||
|
||||
var _index4 = _interopRequireDefault(require("../subISOWeekYears/index.js"));
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
|
||||
/**
|
||||
* @name differenceInISOWeekYears
|
||||
* @category ISO Week-Numbering Year Helpers
|
||||
* @summary Get the number of full ISO week-numbering years between the given dates.
|
||||
*
|
||||
* @description
|
||||
* Get the number of full ISO week-numbering years between the given dates.
|
||||
*
|
||||
* ISO week-numbering year: http://en.wikipedia.org/wiki/ISO_week_date
|
||||
*
|
||||
* ### v2.0.0 breaking changes:
|
||||
*
|
||||
* - [Changes that are common for the whole library](https://github.com/date-fns/date-fns/blob/master/docs/upgradeGuide.md#Common-Changes).
|
||||
*
|
||||
* - The function was renamed from `differenceInISOYears` to `differenceInISOWeekYears`.
|
||||
* "ISO week year" is short for [ISO week-numbering year](https://en.wikipedia.org/wiki/ISO_week_date).
|
||||
* This change makes the name consistent with
|
||||
* locale-dependent week-numbering year helpers, e.g., `addWeekYears`.
|
||||
*
|
||||
* @param {Date|Number} dateLeft - the later date
|
||||
* @param {Date|Number} dateRight - the earlier date
|
||||
* @returns {Number} the number of full ISO week-numbering years
|
||||
* @throws {TypeError} 2 arguments required
|
||||
*
|
||||
* @example
|
||||
* // How many full ISO week-numbering years are between 1 January 2010 and 1 January 2012?
|
||||
* var result = differenceInISOWeekYears(
|
||||
* new Date(2012, 0, 1),
|
||||
* new Date(2010, 0, 1)
|
||||
* )
|
||||
* //=> 1
|
||||
*/
|
||||
function differenceInISOWeekYears(dirtyDateLeft, dirtyDateRight) {
|
||||
if (arguments.length < 2) {
|
||||
throw new TypeError('2 arguments required, but only ' + arguments.length + ' present');
|
||||
}
|
||||
|
||||
var dateLeft = (0, _index.default)(dirtyDateLeft);
|
||||
var dateRight = (0, _index.default)(dirtyDateRight);
|
||||
var sign = (0, _index3.default)(dateLeft, dateRight);
|
||||
var difference = Math.abs((0, _index2.default)(dateLeft, dateRight));
|
||||
dateLeft = (0, _index4.default)(dateLeft, sign * difference); // Math.abs(diff in full ISO years - diff in calendar ISO years) === 1
|
||||
// if last calendar ISO year is not full
|
||||
// If so, result must be decreased by 1 in absolute value
|
||||
|
||||
var isLastISOWeekYearNotFull = (0, _index3.default)(dateLeft, dateRight) === -sign;
|
||||
var result = sign * (difference - isLastISOWeekYearNotFull); // Prevent negative zero
|
||||
|
||||
return result === 0 ? 0 : result;
|
||||
}
|
||||
|
||||
module.exports = exports.default;
|
||||
+41
@@ -0,0 +1,41 @@
|
||||
// @flow
|
||||
// This file is generated automatically by `scripts/build/typings.js`. Please, don't change it.
|
||||
|
||||
export type Interval = {
|
||||
start: Date | number,
|
||||
end: Date | number
|
||||
}
|
||||
|
||||
export type Locale = {
|
||||
formatDistance: (...args: Array<any>) => any,
|
||||
formatRelative: (...args: Array<any>) => any,
|
||||
localize: {
|
||||
ordinalNumber: (...args: Array<any>) => any,
|
||||
era: (...args: Array<any>) => any,
|
||||
quarter: (...args: Array<any>) => any,
|
||||
month: (...args: Array<any>) => any,
|
||||
day: (...args: Array<any>) => any,
|
||||
dayPeriod: (...args: Array<any>) => any
|
||||
},
|
||||
formatLong: Object,
|
||||
date: (...args: Array<any>) => any,
|
||||
time: (...args: Array<any>) => any,
|
||||
dateTime: (...args: Array<any>) => any,
|
||||
match: {
|
||||
ordinalNumber: (...args: Array<any>) => any,
|
||||
era: (...args: Array<any>) => any,
|
||||
quarter: (...args: Array<any>) => any,
|
||||
month: (...args: Array<any>) => any,
|
||||
day: (...args: Array<any>) => any,
|
||||
dayPeriod: (...args: Array<any>) => any
|
||||
},
|
||||
options?: {
|
||||
weekStartsOn?: 0 | 1 | 2 | 3 | 4 | 5 | 6,
|
||||
firstWeekContainsDate?: 1 | 2 | 3 | 4 | 5 | 6 | 7
|
||||
}
|
||||
}
|
||||
|
||||
declare module.exports: (
|
||||
dateLeft: Date | number,
|
||||
dateRight: Date | number
|
||||
) => number
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"sideEffects": false,
|
||||
"module": "../esm/differenceInISOWeekYears/index.js",
|
||||
"typings": "../typings.d.ts"
|
||||
}
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
// This file is generated automatically by `scripts/build/typings.js`. Please, don't change it.
|
||||
|
||||
import { differenceInMilliseconds } from 'date-fns'
|
||||
export default differenceInMilliseconds
|
||||
+48
@@ -0,0 +1,48 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.default = differenceInMilliseconds;
|
||||
|
||||
var _index = _interopRequireDefault(require("../toDate/index.js"));
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
|
||||
/**
|
||||
* @name differenceInMilliseconds
|
||||
* @category Millisecond Helpers
|
||||
* @summary Get the number of milliseconds between the given dates.
|
||||
*
|
||||
* @description
|
||||
* Get the number of milliseconds between the given dates.
|
||||
*
|
||||
* ### v2.0.0 breaking changes:
|
||||
*
|
||||
* - [Changes that are common for the whole library](https://github.com/date-fns/date-fns/blob/master/docs/upgradeGuide.md#Common-Changes).
|
||||
*
|
||||
* @param {Date|Number} dateLeft - the later date
|
||||
* @param {Date|Number} dateRight - the earlier date
|
||||
* @returns {Number} the number of milliseconds
|
||||
* @throws {TypeError} 2 arguments required
|
||||
*
|
||||
* @example
|
||||
* // How many milliseconds are between
|
||||
* // 2 July 2014 12:30:20.600 and 2 July 2014 12:30:21.700?
|
||||
* var result = differenceInMilliseconds(
|
||||
* new Date(2014, 6, 2, 12, 30, 21, 700),
|
||||
* new Date(2014, 6, 2, 12, 30, 20, 600)
|
||||
* )
|
||||
* //=> 1100
|
||||
*/
|
||||
function differenceInMilliseconds(dirtyDateLeft, dirtyDateRight) {
|
||||
if (arguments.length < 2) {
|
||||
throw new TypeError('2 arguments required, but only ' + arguments.length + ' present');
|
||||
}
|
||||
|
||||
var dateLeft = (0, _index.default)(dirtyDateLeft);
|
||||
var dateRight = (0, _index.default)(dirtyDateRight);
|
||||
return dateLeft.getTime() - dateRight.getTime();
|
||||
}
|
||||
|
||||
module.exports = exports.default;
|
||||
+41
@@ -0,0 +1,41 @@
|
||||
// @flow
|
||||
// This file is generated automatically by `scripts/build/typings.js`. Please, don't change it.
|
||||
|
||||
export type Interval = {
|
||||
start: Date | number,
|
||||
end: Date | number
|
||||
}
|
||||
|
||||
export type Locale = {
|
||||
formatDistance: (...args: Array<any>) => any,
|
||||
formatRelative: (...args: Array<any>) => any,
|
||||
localize: {
|
||||
ordinalNumber: (...args: Array<any>) => any,
|
||||
era: (...args: Array<any>) => any,
|
||||
quarter: (...args: Array<any>) => any,
|
||||
month: (...args: Array<any>) => any,
|
||||
day: (...args: Array<any>) => any,
|
||||
dayPeriod: (...args: Array<any>) => any
|
||||
},
|
||||
formatLong: Object,
|
||||
date: (...args: Array<any>) => any,
|
||||
time: (...args: Array<any>) => any,
|
||||
dateTime: (...args: Array<any>) => any,
|
||||
match: {
|
||||
ordinalNumber: (...args: Array<any>) => any,
|
||||
era: (...args: Array<any>) => any,
|
||||
quarter: (...args: Array<any>) => any,
|
||||
month: (...args: Array<any>) => any,
|
||||
day: (...args: Array<any>) => any,
|
||||
dayPeriod: (...args: Array<any>) => any
|
||||
},
|
||||
options?: {
|
||||
weekStartsOn?: 0 | 1 | 2 | 3 | 4 | 5 | 6,
|
||||
firstWeekContainsDate?: 1 | 2 | 3 | 4 | 5 | 6 | 7
|
||||
}
|
||||
}
|
||||
|
||||
declare module.exports: (
|
||||
dateLeft: Date | number,
|
||||
dateRight: Date | number
|
||||
) => number
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"sideEffects": false,
|
||||
"module": "../esm/differenceInMilliseconds/index.js",
|
||||
"typings": "../typings.d.ts"
|
||||
}
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
// This file is generated automatically by `scripts/build/typings.js`. Please, don't change it.
|
||||
|
||||
import { differenceInMinutes } from 'date-fns'
|
||||
export default differenceInMinutes
|
||||
+56
@@ -0,0 +1,56 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.default = differenceInMinutes;
|
||||
|
||||
var _index = _interopRequireDefault(require("../differenceInMilliseconds/index.js"));
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
|
||||
var MILLISECONDS_IN_MINUTE = 60000;
|
||||
/**
|
||||
* @name differenceInMinutes
|
||||
* @category Minute Helpers
|
||||
* @summary Get the number of minutes between the given dates.
|
||||
*
|
||||
* @description
|
||||
* Get the signed number of full (rounded towards 0) minutes between the given dates.
|
||||
*
|
||||
* ### v2.0.0 breaking changes:
|
||||
*
|
||||
* - [Changes that are common for the whole library](https://github.com/date-fns/date-fns/blob/master/docs/upgradeGuide.md#Common-Changes).
|
||||
*
|
||||
* @param {Date|Number} dateLeft - the later date
|
||||
* @param {Date|Number} dateRight - the earlier date
|
||||
* @returns {Number} the number of minutes
|
||||
* @throws {TypeError} 2 arguments required
|
||||
*
|
||||
* @example
|
||||
* // How many minutes are between 2 July 2014 12:07:59 and 2 July 2014 12:20:00?
|
||||
* var result = differenceInMinutes(
|
||||
* new Date(2014, 6, 2, 12, 20, 0),
|
||||
* new Date(2014, 6, 2, 12, 7, 59)
|
||||
* )
|
||||
* //=> 12
|
||||
*
|
||||
* @example
|
||||
* // How many minutes are from 10:01:59 to 10:00:00
|
||||
* var result = differenceInMinutes(
|
||||
* new Date(2000, 0, 1, 10, 0, 0),
|
||||
* new Date(2000, 0, 1, 10, 1, 59)
|
||||
* )
|
||||
* //=> -1
|
||||
*/
|
||||
|
||||
function differenceInMinutes(dirtyDateLeft, dirtyDateRight) {
|
||||
if (arguments.length < 2) {
|
||||
throw new TypeError('2 arguments required, but only ' + arguments.length + ' present');
|
||||
}
|
||||
|
||||
var diff = (0, _index.default)(dirtyDateLeft, dirtyDateRight) / MILLISECONDS_IN_MINUTE;
|
||||
return diff > 0 ? Math.floor(diff) : Math.ceil(diff);
|
||||
}
|
||||
|
||||
module.exports = exports.default;
|
||||
+41
@@ -0,0 +1,41 @@
|
||||
// @flow
|
||||
// This file is generated automatically by `scripts/build/typings.js`. Please, don't change it.
|
||||
|
||||
export type Interval = {
|
||||
start: Date | number,
|
||||
end: Date | number
|
||||
}
|
||||
|
||||
export type Locale = {
|
||||
formatDistance: (...args: Array<any>) => any,
|
||||
formatRelative: (...args: Array<any>) => any,
|
||||
localize: {
|
||||
ordinalNumber: (...args: Array<any>) => any,
|
||||
era: (...args: Array<any>) => any,
|
||||
quarter: (...args: Array<any>) => any,
|
||||
month: (...args: Array<any>) => any,
|
||||
day: (...args: Array<any>) => any,
|
||||
dayPeriod: (...args: Array<any>) => any
|
||||
},
|
||||
formatLong: Object,
|
||||
date: (...args: Array<any>) => any,
|
||||
time: (...args: Array<any>) => any,
|
||||
dateTime: (...args: Array<any>) => any,
|
||||
match: {
|
||||
ordinalNumber: (...args: Array<any>) => any,
|
||||
era: (...args: Array<any>) => any,
|
||||
quarter: (...args: Array<any>) => any,
|
||||
month: (...args: Array<any>) => any,
|
||||
day: (...args: Array<any>) => any,
|
||||
dayPeriod: (...args: Array<any>) => any
|
||||
},
|
||||
options?: {
|
||||
weekStartsOn?: 0 | 1 | 2 | 3 | 4 | 5 | 6,
|
||||
firstWeekContainsDate?: 1 | 2 | 3 | 4 | 5 | 6 | 7
|
||||
}
|
||||
}
|
||||
|
||||
declare module.exports: (
|
||||
dateLeft: Date | number,
|
||||
dateRight: Date | number
|
||||
) => number
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"sideEffects": false,
|
||||
"module": "../esm/differenceInMinutes/index.js",
|
||||
"typings": "../typings.d.ts"
|
||||
}
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
// This file is generated automatically by `scripts/build/typings.js`. Please, don't change it.
|
||||
|
||||
import { differenceInMonths } from 'date-fns'
|
||||
export default differenceInMonths
|
||||
+56
@@ -0,0 +1,56 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.default = differenceInMonths;
|
||||
|
||||
var _index = _interopRequireDefault(require("../toDate/index.js"));
|
||||
|
||||
var _index2 = _interopRequireDefault(require("../differenceInCalendarMonths/index.js"));
|
||||
|
||||
var _index3 = _interopRequireDefault(require("../compareAsc/index.js"));
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
|
||||
/**
|
||||
* @name differenceInMonths
|
||||
* @category Month Helpers
|
||||
* @summary Get the number of full months between the given dates.
|
||||
*
|
||||
* @description
|
||||
* Get the number of full months between the given dates.
|
||||
*
|
||||
* ### v2.0.0 breaking changes:
|
||||
*
|
||||
* - [Changes that are common for the whole library](https://github.com/date-fns/date-fns/blob/master/docs/upgradeGuide.md#Common-Changes).
|
||||
*
|
||||
* @param {Date|Number} dateLeft - the later date
|
||||
* @param {Date|Number} dateRight - the earlier date
|
||||
* @returns {Number} the number of full months
|
||||
* @throws {TypeError} 2 arguments required
|
||||
*
|
||||
* @example
|
||||
* // How many full months are between 31 January 2014 and 1 September 2014?
|
||||
* var result = differenceInMonths(new Date(2014, 8, 1), new Date(2014, 0, 31))
|
||||
* //=> 7
|
||||
*/
|
||||
function differenceInMonths(dirtyDateLeft, dirtyDateRight) {
|
||||
if (arguments.length < 2) {
|
||||
throw new TypeError('2 arguments required, but only ' + arguments.length + ' present');
|
||||
}
|
||||
|
||||
var dateLeft = (0, _index.default)(dirtyDateLeft);
|
||||
var dateRight = (0, _index.default)(dirtyDateRight);
|
||||
var sign = (0, _index3.default)(dateLeft, dateRight);
|
||||
var difference = Math.abs((0, _index2.default)(dateLeft, dateRight));
|
||||
dateLeft.setMonth(dateLeft.getMonth() - sign * difference); // Math.abs(diff in full months - diff in calendar months) === 1 if last calendar month is not full
|
||||
// If so, result must be decreased by 1 in absolute value
|
||||
|
||||
var isLastMonthNotFull = (0, _index3.default)(dateLeft, dateRight) === -sign;
|
||||
var result = sign * (difference - isLastMonthNotFull); // Prevent negative zero
|
||||
|
||||
return result === 0 ? 0 : result;
|
||||
}
|
||||
|
||||
module.exports = exports.default;
|
||||
+41
@@ -0,0 +1,41 @@
|
||||
// @flow
|
||||
// This file is generated automatically by `scripts/build/typings.js`. Please, don't change it.
|
||||
|
||||
export type Interval = {
|
||||
start: Date | number,
|
||||
end: Date | number
|
||||
}
|
||||
|
||||
export type Locale = {
|
||||
formatDistance: (...args: Array<any>) => any,
|
||||
formatRelative: (...args: Array<any>) => any,
|
||||
localize: {
|
||||
ordinalNumber: (...args: Array<any>) => any,
|
||||
era: (...args: Array<any>) => any,
|
||||
quarter: (...args: Array<any>) => any,
|
||||
month: (...args: Array<any>) => any,
|
||||
day: (...args: Array<any>) => any,
|
||||
dayPeriod: (...args: Array<any>) => any
|
||||
},
|
||||
formatLong: Object,
|
||||
date: (...args: Array<any>) => any,
|
||||
time: (...args: Array<any>) => any,
|
||||
dateTime: (...args: Array<any>) => any,
|
||||
match: {
|
||||
ordinalNumber: (...args: Array<any>) => any,
|
||||
era: (...args: Array<any>) => any,
|
||||
quarter: (...args: Array<any>) => any,
|
||||
month: (...args: Array<any>) => any,
|
||||
day: (...args: Array<any>) => any,
|
||||
dayPeriod: (...args: Array<any>) => any
|
||||
},
|
||||
options?: {
|
||||
weekStartsOn?: 0 | 1 | 2 | 3 | 4 | 5 | 6,
|
||||
firstWeekContainsDate?: 1 | 2 | 3 | 4 | 5 | 6 | 7
|
||||
}
|
||||
}
|
||||
|
||||
declare module.exports: (
|
||||
dateLeft: Date | number,
|
||||
dateRight: Date | number
|
||||
) => number
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"sideEffects": false,
|
||||
"module": "../esm/differenceInMonths/index.js",
|
||||
"typings": "../typings.d.ts"
|
||||
}
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
// This file is generated automatically by `scripts/build/typings.js`. Please, don't change it.
|
||||
|
||||
import { differenceInQuarters } from 'date-fns'
|
||||
export default differenceInQuarters
|
||||
+43
@@ -0,0 +1,43 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.default = differenceInQuarters;
|
||||
|
||||
var _index = _interopRequireDefault(require("../differenceInMonths/index.js"));
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
|
||||
/**
|
||||
* @name differenceInQuarters
|
||||
* @category Quarter Helpers
|
||||
* @summary Get the number of full quarters between the given dates.
|
||||
*
|
||||
* @description
|
||||
* Get the number of full quarters between the given dates.
|
||||
*
|
||||
* ### v2.0.0 breaking changes:
|
||||
*
|
||||
* - [Changes that are common for the whole library](https://github.com/date-fns/date-fns/blob/master/docs/upgradeGuide.md#Common-Changes).
|
||||
*
|
||||
* @param {Date|Number} dateLeft - the later date
|
||||
* @param {Date|Number} dateRight - the earlier date
|
||||
* @returns {Number} the number of full quarters
|
||||
* @throws {TypeError} 2 arguments required
|
||||
*
|
||||
* @example
|
||||
* // How many full quarters are between 31 December 2013 and 2 July 2014?
|
||||
* var result = differenceInQuarters(new Date(2014, 6, 2), new Date(2013, 11, 31))
|
||||
* //=> 2
|
||||
*/
|
||||
function differenceInQuarters(dirtyDateLeft, dirtyDateRight) {
|
||||
if (arguments.length < 2) {
|
||||
throw new TypeError('2 arguments required, but only ' + arguments.length + ' present');
|
||||
}
|
||||
|
||||
var diff = (0, _index.default)(dirtyDateLeft, dirtyDateRight) / 3;
|
||||
return diff > 0 ? Math.floor(diff) : Math.ceil(diff);
|
||||
}
|
||||
|
||||
module.exports = exports.default;
|
||||
+41
@@ -0,0 +1,41 @@
|
||||
// @flow
|
||||
// This file is generated automatically by `scripts/build/typings.js`. Please, don't change it.
|
||||
|
||||
export type Interval = {
|
||||
start: Date | number,
|
||||
end: Date | number
|
||||
}
|
||||
|
||||
export type Locale = {
|
||||
formatDistance: (...args: Array<any>) => any,
|
||||
formatRelative: (...args: Array<any>) => any,
|
||||
localize: {
|
||||
ordinalNumber: (...args: Array<any>) => any,
|
||||
era: (...args: Array<any>) => any,
|
||||
quarter: (...args: Array<any>) => any,
|
||||
month: (...args: Array<any>) => any,
|
||||
day: (...args: Array<any>) => any,
|
||||
dayPeriod: (...args: Array<any>) => any
|
||||
},
|
||||
formatLong: Object,
|
||||
date: (...args: Array<any>) => any,
|
||||
time: (...args: Array<any>) => any,
|
||||
dateTime: (...args: Array<any>) => any,
|
||||
match: {
|
||||
ordinalNumber: (...args: Array<any>) => any,
|
||||
era: (...args: Array<any>) => any,
|
||||
quarter: (...args: Array<any>) => any,
|
||||
month: (...args: Array<any>) => any,
|
||||
day: (...args: Array<any>) => any,
|
||||
dayPeriod: (...args: Array<any>) => any
|
||||
},
|
||||
options?: {
|
||||
weekStartsOn?: 0 | 1 | 2 | 3 | 4 | 5 | 6,
|
||||
firstWeekContainsDate?: 1 | 2 | 3 | 4 | 5 | 6 | 7
|
||||
}
|
||||
}
|
||||
|
||||
declare module.exports: (
|
||||
dateLeft: Date | number,
|
||||
dateRight: Date | number
|
||||
) => number
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"sideEffects": false,
|
||||
"module": "../esm/differenceInQuarters/index.js",
|
||||
"typings": "../typings.d.ts"
|
||||
}
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
// This file is generated automatically by `scripts/build/typings.js`. Please, don't change it.
|
||||
|
||||
import { differenceInSeconds } from 'date-fns'
|
||||
export default differenceInSeconds
|
||||
+47
@@ -0,0 +1,47 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.default = differenceInSeconds;
|
||||
|
||||
var _index = _interopRequireDefault(require("../differenceInMilliseconds/index.js"));
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
|
||||
/**
|
||||
* @name differenceInSeconds
|
||||
* @category Second Helpers
|
||||
* @summary Get the number of seconds between the given dates.
|
||||
*
|
||||
* @description
|
||||
* Get the number of seconds between the given dates.
|
||||
*
|
||||
* ### v2.0.0 breaking changes:
|
||||
*
|
||||
* - [Changes that are common for the whole library](https://github.com/date-fns/date-fns/blob/master/docs/upgradeGuide.md#Common-Changes).
|
||||
*
|
||||
* @param {Date|Number} dateLeft - the later date
|
||||
* @param {Date|Number} dateRight - the earlier date
|
||||
* @returns {Number} the number of seconds
|
||||
* @throws {TypeError} 2 arguments required
|
||||
*
|
||||
* @example
|
||||
* // How many seconds are between
|
||||
* // 2 July 2014 12:30:07.999 and 2 July 2014 12:30:20.000?
|
||||
* var result = differenceInSeconds(
|
||||
* new Date(2014, 6, 2, 12, 30, 20, 0),
|
||||
* new Date(2014, 6, 2, 12, 30, 7, 999)
|
||||
* )
|
||||
* //=> 12
|
||||
*/
|
||||
function differenceInSeconds(dirtyDateLeft, dirtyDateRight) {
|
||||
if (arguments.length < 2) {
|
||||
throw new TypeError('2 arguments required, but only ' + arguments.length + ' present');
|
||||
}
|
||||
|
||||
var diff = (0, _index.default)(dirtyDateLeft, dirtyDateRight) / 1000;
|
||||
return diff > 0 ? Math.floor(diff) : Math.ceil(diff);
|
||||
}
|
||||
|
||||
module.exports = exports.default;
|
||||
+41
@@ -0,0 +1,41 @@
|
||||
// @flow
|
||||
// This file is generated automatically by `scripts/build/typings.js`. Please, don't change it.
|
||||
|
||||
export type Interval = {
|
||||
start: Date | number,
|
||||
end: Date | number
|
||||
}
|
||||
|
||||
export type Locale = {
|
||||
formatDistance: (...args: Array<any>) => any,
|
||||
formatRelative: (...args: Array<any>) => any,
|
||||
localize: {
|
||||
ordinalNumber: (...args: Array<any>) => any,
|
||||
era: (...args: Array<any>) => any,
|
||||
quarter: (...args: Array<any>) => any,
|
||||
month: (...args: Array<any>) => any,
|
||||
day: (...args: Array<any>) => any,
|
||||
dayPeriod: (...args: Array<any>) => any
|
||||
},
|
||||
formatLong: Object,
|
||||
date: (...args: Array<any>) => any,
|
||||
time: (...args: Array<any>) => any,
|
||||
dateTime: (...args: Array<any>) => any,
|
||||
match: {
|
||||
ordinalNumber: (...args: Array<any>) => any,
|
||||
era: (...args: Array<any>) => any,
|
||||
quarter: (...args: Array<any>) => any,
|
||||
month: (...args: Array<any>) => any,
|
||||
day: (...args: Array<any>) => any,
|
||||
dayPeriod: (...args: Array<any>) => any
|
||||
},
|
||||
options?: {
|
||||
weekStartsOn?: 0 | 1 | 2 | 3 | 4 | 5 | 6,
|
||||
firstWeekContainsDate?: 1 | 2 | 3 | 4 | 5 | 6 | 7
|
||||
}
|
||||
}
|
||||
|
||||
declare module.exports: (
|
||||
dateLeft: Date | number,
|
||||
dateRight: Date | number
|
||||
) => number
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"sideEffects": false,
|
||||
"module": "../esm/differenceInSeconds/index.js",
|
||||
"typings": "../typings.d.ts"
|
||||
}
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
// This file is generated automatically by `scripts/build/typings.js`. Please, don't change it.
|
||||
|
||||
import { differenceInWeeks } from 'date-fns'
|
||||
export default differenceInWeeks
|
||||
+43
@@ -0,0 +1,43 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.default = differenceInWeeks;
|
||||
|
||||
var _index = _interopRequireDefault(require("../differenceInDays/index.js"));
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
|
||||
/**
|
||||
* @name differenceInWeeks
|
||||
* @category Week Helpers
|
||||
* @summary Get the number of full weeks between the given dates.
|
||||
*
|
||||
* @description
|
||||
* Get the number of full weeks between the given dates.
|
||||
*
|
||||
* ### v2.0.0 breaking changes:
|
||||
*
|
||||
* - [Changes that are common for the whole library](https://github.com/date-fns/date-fns/blob/master/docs/upgradeGuide.md#Common-Changes).
|
||||
*
|
||||
* @param {Date|Number} dateLeft - the later date
|
||||
* @param {Date|Number} dateRight - the earlier date
|
||||
* @returns {Number} the number of full weeks
|
||||
* @throws {TypeError} 2 arguments required
|
||||
*
|
||||
* @example
|
||||
* // How many full weeks are between 5 July 2014 and 20 July 2014?
|
||||
* var result = differenceInWeeks(new Date(2014, 6, 20), new Date(2014, 6, 5))
|
||||
* //=> 2
|
||||
*/
|
||||
function differenceInWeeks(dirtyDateLeft, dirtyDateRight) {
|
||||
if (arguments.length < 2) {
|
||||
throw new TypeError('2 arguments required, but only ' + arguments.length + ' present');
|
||||
}
|
||||
|
||||
var diff = (0, _index.default)(dirtyDateLeft, dirtyDateRight) / 7;
|
||||
return diff > 0 ? Math.floor(diff) : Math.ceil(diff);
|
||||
}
|
||||
|
||||
module.exports = exports.default;
|
||||
+41
@@ -0,0 +1,41 @@
|
||||
// @flow
|
||||
// This file is generated automatically by `scripts/build/typings.js`. Please, don't change it.
|
||||
|
||||
export type Interval = {
|
||||
start: Date | number,
|
||||
end: Date | number
|
||||
}
|
||||
|
||||
export type Locale = {
|
||||
formatDistance: (...args: Array<any>) => any,
|
||||
formatRelative: (...args: Array<any>) => any,
|
||||
localize: {
|
||||
ordinalNumber: (...args: Array<any>) => any,
|
||||
era: (...args: Array<any>) => any,
|
||||
quarter: (...args: Array<any>) => any,
|
||||
month: (...args: Array<any>) => any,
|
||||
day: (...args: Array<any>) => any,
|
||||
dayPeriod: (...args: Array<any>) => any
|
||||
},
|
||||
formatLong: Object,
|
||||
date: (...args: Array<any>) => any,
|
||||
time: (...args: Array<any>) => any,
|
||||
dateTime: (...args: Array<any>) => any,
|
||||
match: {
|
||||
ordinalNumber: (...args: Array<any>) => any,
|
||||
era: (...args: Array<any>) => any,
|
||||
quarter: (...args: Array<any>) => any,
|
||||
month: (...args: Array<any>) => any,
|
||||
day: (...args: Array<any>) => any,
|
||||
dayPeriod: (...args: Array<any>) => any
|
||||
},
|
||||
options?: {
|
||||
weekStartsOn?: 0 | 1 | 2 | 3 | 4 | 5 | 6,
|
||||
firstWeekContainsDate?: 1 | 2 | 3 | 4 | 5 | 6 | 7
|
||||
}
|
||||
}
|
||||
|
||||
declare module.exports: (
|
||||
dateLeft: Date | number,
|
||||
dateRight: Date | number
|
||||
) => number
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"sideEffects": false,
|
||||
"module": "../esm/differenceInWeeks/index.js",
|
||||
"typings": "../typings.d.ts"
|
||||
}
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
// This file is generated automatically by `scripts/build/typings.js`. Please, don't change it.
|
||||
|
||||
import { differenceInYears } from 'date-fns'
|
||||
export default differenceInYears
|
||||
+56
@@ -0,0 +1,56 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.default = differenceInYears;
|
||||
|
||||
var _index = _interopRequireDefault(require("../toDate/index.js"));
|
||||
|
||||
var _index2 = _interopRequireDefault(require("../differenceInCalendarYears/index.js"));
|
||||
|
||||
var _index3 = _interopRequireDefault(require("../compareAsc/index.js"));
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
|
||||
/**
|
||||
* @name differenceInYears
|
||||
* @category Year Helpers
|
||||
* @summary Get the number of full years between the given dates.
|
||||
*
|
||||
* @description
|
||||
* Get the number of full years between the given dates.
|
||||
*
|
||||
* ### v2.0.0 breaking changes:
|
||||
*
|
||||
* - [Changes that are common for the whole library](https://github.com/date-fns/date-fns/blob/master/docs/upgradeGuide.md#Common-Changes).
|
||||
*
|
||||
* @param {Date|Number} dateLeft - the later date
|
||||
* @param {Date|Number} dateRight - the earlier date
|
||||
* @returns {Number} the number of full years
|
||||
* @throws {TypeError} 2 arguments required
|
||||
*
|
||||
* @example
|
||||
* // How many full years are between 31 December 2013 and 11 February 2015?
|
||||
* var result = differenceInYears(new Date(2015, 1, 11), new Date(2013, 11, 31))
|
||||
* //=> 1
|
||||
*/
|
||||
function differenceInYears(dirtyDateLeft, dirtyDateRight) {
|
||||
if (arguments.length < 2) {
|
||||
throw new TypeError('2 arguments required, but only ' + arguments.length + ' present');
|
||||
}
|
||||
|
||||
var dateLeft = (0, _index.default)(dirtyDateLeft);
|
||||
var dateRight = (0, _index.default)(dirtyDateRight);
|
||||
var sign = (0, _index3.default)(dateLeft, dateRight);
|
||||
var difference = Math.abs((0, _index2.default)(dateLeft, dateRight));
|
||||
dateLeft.setFullYear(dateLeft.getFullYear() - sign * difference); // Math.abs(diff in full years - diff in calendar years) === 1 if last calendar year is not full
|
||||
// If so, result must be decreased by 1 in absolute value
|
||||
|
||||
var isLastYearNotFull = (0, _index3.default)(dateLeft, dateRight) === -sign;
|
||||
var result = sign * (difference - isLastYearNotFull); // Prevent negative zero
|
||||
|
||||
return result === 0 ? 0 : result;
|
||||
}
|
||||
|
||||
module.exports = exports.default;
|
||||
+41
@@ -0,0 +1,41 @@
|
||||
// @flow
|
||||
// This file is generated automatically by `scripts/build/typings.js`. Please, don't change it.
|
||||
|
||||
export type Interval = {
|
||||
start: Date | number,
|
||||
end: Date | number
|
||||
}
|
||||
|
||||
export type Locale = {
|
||||
formatDistance: (...args: Array<any>) => any,
|
||||
formatRelative: (...args: Array<any>) => any,
|
||||
localize: {
|
||||
ordinalNumber: (...args: Array<any>) => any,
|
||||
era: (...args: Array<any>) => any,
|
||||
quarter: (...args: Array<any>) => any,
|
||||
month: (...args: Array<any>) => any,
|
||||
day: (...args: Array<any>) => any,
|
||||
dayPeriod: (...args: Array<any>) => any
|
||||
},
|
||||
formatLong: Object,
|
||||
date: (...args: Array<any>) => any,
|
||||
time: (...args: Array<any>) => any,
|
||||
dateTime: (...args: Array<any>) => any,
|
||||
match: {
|
||||
ordinalNumber: (...args: Array<any>) => any,
|
||||
era: (...args: Array<any>) => any,
|
||||
quarter: (...args: Array<any>) => any,
|
||||
month: (...args: Array<any>) => any,
|
||||
day: (...args: Array<any>) => any,
|
||||
dayPeriod: (...args: Array<any>) => any
|
||||
},
|
||||
options?: {
|
||||
weekStartsOn?: 0 | 1 | 2 | 3 | 4 | 5 | 6,
|
||||
firstWeekContainsDate?: 1 | 2 | 3 | 4 | 5 | 6 | 7
|
||||
}
|
||||
}
|
||||
|
||||
declare module.exports: (
|
||||
dateLeft: Date | number,
|
||||
dateRight: Date | number
|
||||
) => number
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"sideEffects": false,
|
||||
"module": "../esm/differenceInYears/index.js",
|
||||
"typings": "../typings.d.ts"
|
||||
}
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
module.exports = {
|
||||
rules: {
|
||||
'no-console': 'off'
|
||||
}
|
||||
}
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
/**
|
||||
* @category Types
|
||||
* @summary An object that combines two dates to represent the time interval.
|
||||
*
|
||||
* @description
|
||||
* An object that combines two dates to represent the time interval.
|
||||
*
|
||||
* @typedef {Object} Interval
|
||||
* @property {Date|Number} start - the start of the interval
|
||||
* @property {Date|Number} end - the end of the interval
|
||||
* @throws {RangeError} The start of an interval cannot be after its end
|
||||
* @throws {RangeError} Date in interval cannot be `Invalid Date`
|
||||
*/
|
||||
var Interval = {}
|
||||
|
||||
module.exports = Interval
|
||||
+63
@@ -0,0 +1,63 @@
|
||||
/**
|
||||
* @category Types
|
||||
* @summary A locale object.
|
||||
*
|
||||
* @description
|
||||
* A locale object.
|
||||
*
|
||||
* If you don't specify a locale in options, default locale is `en-US`.
|
||||
*
|
||||
* @typedef {Object} Locale
|
||||
*
|
||||
* @property {Function} formatDistance - the function that takes a token
|
||||
* passed by `formatDistance` or `formatDistanceStrict` and payload,
|
||||
* and returns localized distance in words.
|
||||
* Required by `formatDistance` and `formatDistanceStrict`
|
||||
*
|
||||
* @property {Function} formatRelative - the function that takes a token
|
||||
* passed by `formatRelative` and two dates and returns the localized relative date format.
|
||||
* Required by `formatRelative`
|
||||
*
|
||||
* @property {Object} localize - the object with functions used to localize various values.
|
||||
* Required by `format` and `formatRelative`
|
||||
* @property {Function} localize.ordinalNumber - the function that localizes an ordinal number
|
||||
* @property {Function} localize.era - the function that takes 0 or 1 and returns localized era
|
||||
* @property {Function} localize.quarter - the function that localizes a quarter
|
||||
* @property {Function} localize.month - the function that localizes a month
|
||||
* @property {Function} localize.day - the function that localizes a day of the week
|
||||
* @property {Function} localize.dayPeriod - the function that takes one of the strings
|
||||
* 'am', 'pm', 'midnight', 'noon', 'morning', 'afternoon', 'evening' or 'night'
|
||||
* and returns localized time of the day
|
||||
*
|
||||
* @property {Object} formatLong - the object with functions that return localized formats
|
||||
* @property {Function} date - the function that returns a localized long date format
|
||||
* @property {Function} time - the function that returns a localized long time format
|
||||
* @property {Function} dateTime - the function that returns a localized format of date and time combined
|
||||
*
|
||||
* @property {Object} match — the object with functions used to match and parse various localized values.
|
||||
* Required by `parse`
|
||||
* @property {Function} match.ordinalNumber - the function that parses a localized ordinal number
|
||||
* @property {Function} match.era - the function that parses a localized era
|
||||
* @property {Function} match.quarter - the function that parses a localized quarter
|
||||
* @property {Function} match.month - the function that parses a localized month
|
||||
* @property {Function} match.day - the function that parses a localized day of the week
|
||||
* @property {Function} match.dayPeriod - the function that parses a localized time of the day
|
||||
*
|
||||
* @property {Object} [options] - an object with locale options.
|
||||
* @property {0|1|2|3|4|5|6} [options.weekStartsOn=0] - the index of the first day of the week (0 - Sunday).
|
||||
* Used by `differenceInCalendarWeeks`, `endOfWeek`, `format`, `getWeek`, `getWeekOfMonth`,
|
||||
* `getWeeksInMonth`, `isSameWeek`, `isSameWeek`, `lastDayOfWeek`, `parse`, `setDay`,
|
||||
* `setWeek`, `startOfWeek` and `startOfWeekYear`
|
||||
* @property {1|2|3|4|5|6|7} [options.firstWeekContainsDate=1] - the day of January,
|
||||
* which is always in the first week of the year.
|
||||
* Used by `format`, `getWeek`, `getWeekYear`, `parse`, `setWeek`, `setWeekYear` and `startOfWeekYear`.
|
||||
*
|
||||
* @throws {RangeError} `locale` must contain `localize` property. Thrown by `format` and `formatRelative`
|
||||
* @throws {RangeError} `locale` must contain `formatLong` property. Thrown by `format` and `formatRelative`
|
||||
* @throws {RangeError} `locale` must contain `formatRelative` property. Thrown by `formatRelative`
|
||||
* @throws {RangeError} `locale` must contain `formatDistance` property. Thrown by `formatDistance` and `formatDistanceStrict`
|
||||
* @throws {RangeError} `locale` must contain `match` property. Thrown by `parse`
|
||||
*/
|
||||
var Locale = {}
|
||||
|
||||
module.exports = Locale
|
||||
+47
@@ -0,0 +1,47 @@
|
||||
# Constants
|
||||
|
||||
date-fns provides with a number of useful constants.
|
||||
|
||||
## Usage
|
||||
|
||||
The constants could be imported from `date-fns/constants` or directly
|
||||
from `date-fns`:
|
||||
|
||||
```js
|
||||
import { maxTime } from 'date-fns/constants'
|
||||
import { minTime } from 'date-fns'
|
||||
|
||||
function isAllowedTime(time) {
|
||||
return time <= maxTime && time >= minTime
|
||||
}
|
||||
```
|
||||
|
||||
## Constants
|
||||
|
||||
### `maxTime`
|
||||
|
||||
Maximum allowed time:
|
||||
|
||||
```js
|
||||
import { maxTime } from 'date-fns'
|
||||
|
||||
const isValid = 8640000000000001 <= maxTime
|
||||
//=> false
|
||||
|
||||
new Date(8640000000000001)
|
||||
//=> Invalid Date
|
||||
```
|
||||
|
||||
### `minTime`
|
||||
|
||||
Minimum allowed time:
|
||||
|
||||
```js
|
||||
import { minTime } from 'date-fns'
|
||||
|
||||
const isValid = -8640000000000001 >= minTime
|
||||
//=> false
|
||||
|
||||
new Date(-8640000000000001)
|
||||
//=> Invalid Date
|
||||
```
|
||||
+24
@@ -0,0 +1,24 @@
|
||||
# ECMAScript Modules
|
||||
|
||||
**date-fns** v2.x provides support for
|
||||
[ECMAScript Modules](http://www.ecma-international.org/ecma-262/6.0/#sec-modules)
|
||||
that enables tree-shaking for bundlers, like [rollup.js](http://rollupjs.org)
|
||||
and [webpack](https://webpack.js.org).
|
||||
|
||||
If you have tree-shaking enabled in your browser, just import functions normally:
|
||||
|
||||
```javascript
|
||||
import { format, parse } from 'date-fns'
|
||||
import { enUS, eo } from 'date-fns/locale'
|
||||
import { addDays, addHours } from 'date-fns/fp'
|
||||
```
|
||||
|
||||
In TypeScript, now you can import individual functions in more idiomatic way:
|
||||
|
||||
```typescript
|
||||
// Before
|
||||
import * as format from 'date-fns/format'
|
||||
|
||||
// Now
|
||||
import format from 'date-fns/format'
|
||||
```
|
||||
+70
@@ -0,0 +1,70 @@
|
||||
# FP Guide
|
||||
|
||||
**date-fns** v2.x provides [functional programming](https://en.wikipedia.org/wiki/Functional_programming) (FP)
|
||||
friendly functions, like those in [lodash](https://github.com/lodash/lodash/wiki/FP-Guide),
|
||||
that support [currying](https://en.wikipedia.org/wiki/Currying).
|
||||
|
||||
## Table of Contents
|
||||
|
||||
- [Usage](#usage)
|
||||
|
||||
- [Using Function Composition](#using-function-composition)
|
||||
|
||||
## Usage
|
||||
|
||||
FP functions are provided via `'date-fns/fp'` submodule.
|
||||
|
||||
Functions with options (`format`, `parse`, etc.) have two FP counterparts:
|
||||
one that has the options object as its first argument and one that hasn't.
|
||||
The name of the former has `WithOptions` added to the end of its name.
|
||||
|
||||
In **date-fns'** FP functions, the order of arguments is reversed.
|
||||
|
||||
```javascript
|
||||
import { addYears, formatWithOptions } from 'date-fns/fp'
|
||||
import { eo } from 'date-fns/locale'
|
||||
import toUpper from 'lodash/fp/toUpper' // 'date-fns/fp' is compatible with 'lodash/fp'!
|
||||
|
||||
// If FP function has not received enough arguments, it returns another function
|
||||
const addFiveYears = addYears(5)
|
||||
|
||||
// Several arguments can be curried at once
|
||||
const dateToString = formatWithOptions({ locale: eo }, 'd MMMM yyyy')
|
||||
|
||||
const dates = [
|
||||
new Date(2017, 0 /* Jan */, 1),
|
||||
new Date(2017, 1 /* Feb */, 11),
|
||||
new Date(2017, 6 /* Jul */, 2)
|
||||
]
|
||||
|
||||
const formattedDates = dates.map(addFiveYears).map(dateToString).map(toUpper)
|
||||
//=> ['1 JANUARO 2022', '11 FEBRUARO 2022', '2 JULIO 2022']
|
||||
```
|
||||
|
||||
## Using Function Composition
|
||||
|
||||
The main advantage of FP functions is support of functional-style
|
||||
[function composing](https://medium.com/making-internets/why-using-chain-is-a-mistake-9bc1f80d51ba).
|
||||
|
||||
In the example above, you can compose `addFiveYears`, `dateToString` and `toUpper` into a single function:
|
||||
|
||||
```javascript
|
||||
const formattedDates = dates.map((date) => toUpper(dateToString(addFiveYears(date))))
|
||||
```
|
||||
|
||||
Or you can use `compose` function provided by [lodash](https://lodash.com) to do the same in more idiomatic way:
|
||||
|
||||
```javascript
|
||||
import compose from 'lodash/fp/compose'
|
||||
|
||||
const formattedDates = dates.map(compose(toUpper, dateToString, addFiveYears))
|
||||
```
|
||||
|
||||
Or if you prefer natural direction of composing (as opposed to the computationally correct order),
|
||||
you can use lodash' `flow` instead:
|
||||
|
||||
```javascript
|
||||
import flow from 'lodash/fp/flow'
|
||||
|
||||
const formattedDates = dates.map(flow(addFiveYears, dateToString, toUpper))
|
||||
```
|
||||
+83
@@ -0,0 +1,83 @@
|
||||
# Getting Started
|
||||
|
||||
## Table of Contents
|
||||
|
||||
- [Introduction](#introduction)
|
||||
|
||||
- [Submodules](#submodules)
|
||||
|
||||
- [Installation](#installation)
|
||||
|
||||
## Introduction
|
||||
|
||||
**date-fns** provides the most comprehensive, yet simple and consistent toolset
|
||||
for manipulating **JavaScript dates** in **a browser** & **Node.js**.
|
||||
|
||||
**date-fns** is like [lodash](https://lodash.com) for dates. It has
|
||||
[**140+ functions** for all occasions](https://date-fns.org/docs/).
|
||||
|
||||
```js
|
||||
import { format, compareAsc } from 'date-fns'
|
||||
|
||||
format(new Date(2014, 1, 11), 'MM/dd/yyyy')
|
||||
//=> '02/11/2014'
|
||||
|
||||
const dates = [new Date(1995, 6, 2), new Date(1987, 1, 11), new Date(1989, 6, 10)]
|
||||
dates.sort(compareAsc)
|
||||
//=> [
|
||||
// Wed Feb 11 1987 00:00:00,
|
||||
// Mon Jul 10 1989 00:00:00,
|
||||
// Sun Jul 02 1995 00:00:00
|
||||
// ]
|
||||
```
|
||||
|
||||
## Submodules
|
||||
|
||||
**date-fns** includes some optional features as submodules in the npm package.
|
||||
Here is the list of them, in order of nesting:
|
||||
|
||||
- FP — functional programming-friendly variations of the functions. See [FP Guide](https://date-fns.org/docs/FP-Guide);
|
||||
|
||||
- UTC (in development) — variations of the functions which calculate dates in UTC±00:00 timezone.
|
||||
|
||||
The later submodules are also included inside the former if you want to use multiple features from the list.
|
||||
|
||||
To use submodule features, [install the npm package](#npm) and then import a function from a submodule:
|
||||
|
||||
```js
|
||||
// The main submodule:
|
||||
import addDays from 'date-fns/addDays'
|
||||
|
||||
// FP variation:
|
||||
import addDays from 'date-fns/fp/addDays'
|
||||
|
||||
// UTC variation:
|
||||
import addDays from 'date-fns/utc/addDays'
|
||||
|
||||
// Both FP and UTC:
|
||||
import addDays from 'date-fns/fp/utc/addDays'
|
||||
|
||||
// With tree-shaking enabled:
|
||||
import { addDays, format } from 'date-fns/fp'
|
||||
```
|
||||
|
||||
## Installation
|
||||
|
||||
The library is available as an [npm package](https://www.npmjs.com/package/date-fns).
|
||||
|
||||
To install the package, run:
|
||||
|
||||
```bash
|
||||
npm install date-fns --save
|
||||
# or
|
||||
yarn add date-fns
|
||||
```
|
||||
|
||||
Start using:
|
||||
|
||||
```js
|
||||
import { formatDistance, subDays } from 'date-fns'
|
||||
|
||||
formatDistance(subDays(new Date(), 3), new Date())
|
||||
//=> "3 days ago"
|
||||
```
|
||||
+92
@@ -0,0 +1,92 @@
|
||||
# Internationalization
|
||||
|
||||
## Table of Contents
|
||||
|
||||
- [Usage](#usage)
|
||||
|
||||
- [Adding New Language](#adding-new-language)
|
||||
|
||||
## Usage
|
||||
|
||||
There are just a few functions that support I18n:
|
||||
|
||||
- [`format`](https://date-fns.org/docs/format)
|
||||
- [`formatDistance`](https://date-fns.org/docs/formatDistance)
|
||||
- [`formatDistanceStrict`](https://date-fns.org/docs/formatDistanceStrict)
|
||||
- [`formatRelative`](https://date-fns.org/docs/formatRelative)
|
||||
|
||||
To use a locale, you need to require it and then pass
|
||||
as an option to a function:
|
||||
|
||||
```js
|
||||
import { formatDistance } from 'date-fns'
|
||||
// Require Esperanto locale
|
||||
import { eo } from 'date-fns/locale'
|
||||
|
||||
const result = formatDistance(
|
||||
new Date(2016, 7, 1),
|
||||
new Date(2015, 0, 1),
|
||||
{locale: eo} // Pass the locale as an option
|
||||
)
|
||||
//=> 'pli ol 1 jaro'
|
||||
```
|
||||
|
||||
It might seem complicated to require and pass locales as options,
|
||||
but unlike Moment.js which bloats your build with all the locales
|
||||
by default date-fns forces developer to manually require locales when needed.
|
||||
To make API simple, we encourage you to write tiny wrappers and use those
|
||||
instead of original functions:
|
||||
|
||||
```js
|
||||
// app/_lib/format.js
|
||||
|
||||
import { format } from 'date-fns'
|
||||
import { enGB, eo, ru } from 'date-fns/locale'
|
||||
|
||||
const locales = {enGB, eo, ru}
|
||||
|
||||
// by providing a default string of 'PP' or any of its variants for `formatStr`
|
||||
// it will format dates in whichever way is appropriate to the locale
|
||||
export default function (date, formatStr = 'PP') {
|
||||
return format(date, formatStr, {
|
||||
locale: locales[window.__localeId__] // or global.__localeId__
|
||||
})
|
||||
}
|
||||
|
||||
// Later:
|
||||
|
||||
import format from 'app/_lib/format'
|
||||
|
||||
window.__localeId__ = 'en'
|
||||
format(friday13, 'EEEE d')
|
||||
//=> 'Friday 13'
|
||||
|
||||
window.__localeId__ = 'eo'
|
||||
format(friday13, 'EEEE d')
|
||||
//=> 'vendredo 13'
|
||||
|
||||
// If the format string is omitted, it will take the default for the locale.
|
||||
window.__localeId__ = 'en'
|
||||
format(friday13)
|
||||
//=> Jul 13, 2019
|
||||
|
||||
window.__localeId__ = 'eo'
|
||||
format(friday13)
|
||||
//=> 2019-jul-13
|
||||
|
||||
```
|
||||
|
||||
## Adding New Language
|
||||
|
||||
At the moment there is no definitive guide, so if you feel brave enough,
|
||||
use this quick guide:
|
||||
|
||||
- First of all, [create an issue](https://github.com/date-fns/date-fns/issues/new?title=XXX%20language%20support)
|
||||
so you won't overlap with others.
|
||||
- A detailed explanation of how to [add a new locale](https://github.com/date-fns/date-fns/blob/master/docs/i18nContributionGuide.md#adding-a-new-locale).
|
||||
- Use [English locale](https://github.com/date-fns/date-fns/tree/master/src/locale/en-US)
|
||||
as the basis and then incrementally adjust the tests and the code.
|
||||
- Directions on [adding a locale with the same language as another locale](https://github.com/date-fns/date-fns/blob/master/docs/i18nContributionGuide.md#creating-a-locale-with-the-same-language-as-another-locale).
|
||||
- If you have questions or need guidance, leave a comment in the issue.
|
||||
|
||||
Thank you for your support!
|
||||
+921
@@ -0,0 +1,921 @@
|
||||
# I18n Contribution Guide
|
||||
|
||||
## Table of Contents
|
||||
|
||||
- [Adding a new locale](#adding-a-new-locale)
|
||||
|
||||
- [Choosing a directory name for a locale](#choosing-a-directory-name-for-a-locale)
|
||||
|
||||
- [index.js](#index.js)
|
||||
|
||||
- [localize](#localize)
|
||||
|
||||
- [localize.ordinalNumber](#localize.ordinalnumber)
|
||||
|
||||
- [localize.era and using buildLocalizeFn function](#localize.era-and-using-buildlocalizefn-function)
|
||||
|
||||
- [Formatting localizers](#formatting-localizers)
|
||||
|
||||
- [localize.quarter](#localize.quarter)
|
||||
|
||||
- [localize.month](#localize.month)
|
||||
|
||||
- [localize.day](#localize.day)
|
||||
|
||||
- [localize.dayPeriod](#localize.dayperiod)
|
||||
|
||||
- [formatLong](#formatlong)
|
||||
|
||||
- [formatLong.dateFormats](#formatlong.dateformats)
|
||||
|
||||
- [formatLong.timeFormats](#formatlong.timeformats)
|
||||
|
||||
- [formatLong.dateTimeFormats](#formatlong.datetimeformats)
|
||||
|
||||
- [formatRelative](#formatrelative)
|
||||
|
||||
- [match](#match)
|
||||
|
||||
- [formatDistance](#formatdistance)
|
||||
|
||||
- [Tests](#tests)
|
||||
|
||||
- [Creating a locale with the same language as another locale](#creating-a-locale-with-the-same-language-as-another-locale)
|
||||
|
||||
## Adding a new locale
|
||||
|
||||
To add a new locale:
|
||||
|
||||
- [Choose a directory name for it](#choosing-a-directory-name-for-a-locale).
|
||||
|
||||
- Copy the content of an existing locale (e.g. `en-US`) into the newly created directory.
|
||||
|
||||
- Replace the values in the content with yours file-by-file.
|
||||
Use [CLDR data](https://www.unicode.org/cldr/charts/32/summary/root.html)
|
||||
as a point of reference which values to choose.
|
||||
|
||||
All locales contain a number of properties:
|
||||
|
||||
- [`formatDistance`](#formatdistance) — distance localizer function used by `formatDistance` and `formatDistanceStrict`.
|
||||
- [`formatLong`](#formatlong) — contains long date localizer functions used by `format` and `formatRelative`.
|
||||
- [`formatRelative`](#formatrelative) — relative date localizer function used by `formatRelative`.
|
||||
- [`localize`](#localize) — contains functions, which localize the various date values. Required by `format` and `formatRelative`.
|
||||
- [`match`](#match) — contains functions to parse date values. Required by `parse`.
|
||||
- [`options`](#indexjs) — contains the index of the first day of the week for functions such as `startOfWeek`,
|
||||
and the value which determines the first week of the year
|
||||
for functions like `setWeek`.
|
||||
|
||||
### Choosing a directory name for a locale
|
||||
|
||||
Use the four letter code for the directory name (e.g. `en-GB`),
|
||||
|
||||
Use the two/three letter code:
|
||||
|
||||
- if the language code and the country code are the same (e.g. `pt` instead of `pt-PT`).
|
||||
|
||||
- if the language is used in only one country (e.g. `fil` instead of `fil-PH`).
|
||||
|
||||
- if all countries who use the language
|
||||
also use the same regional standards: the first day of the week,
|
||||
the week numbering (see: https://en.wikipedia.org/wiki/Week#Week_numbering),
|
||||
calendar date format (see: https://en.wikipedia.org/wiki/Calendar_date)
|
||||
and date representation (see: https://en.wikipedia.org/wiki/Date_and_time_representation_by_country
|
||||
and: https://en.wikipedia.org/wiki/Date_format_by_country)
|
||||
(e.g. `ca` instead of `ca-ES` and `ca-AD`).
|
||||
|
||||
### index.js
|
||||
|
||||
Locale's `index.js` is where all the properties of the locale are combined in a single file,
|
||||
documented in JSDoc format.
|
||||
|
||||
```javascript
|
||||
import formatDistance from './_lib/formatDistance/index.js'
|
||||
import formatLong from './_lib/formatLong/index.js'
|
||||
import formatRelative from './_lib/formatRelative/index.js'
|
||||
import localize from './_lib/localize/index.js'
|
||||
import match from './_lib/match/index.js'
|
||||
|
||||
/**
|
||||
* @type {Locale}
|
||||
* @category Locales
|
||||
*
|
||||
* // Name of the locale.
|
||||
* // Inside the parentheses - name of the country - if the locale uses the four letter code, e.g. en-US, fr-CA or pt-BR.
|
||||
* @summary English locale (United States).
|
||||
*
|
||||
* // Name of the language (used by https://date-fns.org/ website)
|
||||
* @language English
|
||||
*
|
||||
* // ISO 639-2 code. See the list here:
|
||||
* // https://www.loc.gov/standards/iso639-2/php/code_list.php
|
||||
* // Used by https://date-fns.org/ to detect the list of the countries that uses the language.
|
||||
* @iso-639-2 eng
|
||||
*
|
||||
* // Authors of the locale (including anyone who corrected or fixed the locale)
|
||||
* @author Sasha Koss [@kossnocorp]{@link https://github.com/kossnocorp}
|
||||
* @author Lesha Koss [@leshakoss]{@link https://github.com/leshakoss}
|
||||
*/
|
||||
var locale = {
|
||||
code: 'en',
|
||||
formatDistance: formatDistance,
|
||||
formatLong: formatLong,
|
||||
formatRelative: formatRelative,
|
||||
localize: localize,
|
||||
match: match,
|
||||
options: {
|
||||
// Index of the first day of the week.
|
||||
// Sunday is 0, Monday is 1, Saturday is 6.
|
||||
weekStartsOn: 0,
|
||||
|
||||
// Nth of January which is always in the first week of the year. See:
|
||||
// https://en.wikipedia.org/wiki/Week#Week_numbering
|
||||
// http://www.pjh2.de/datetime/weeknumber/wnd.php?l=en
|
||||
firstWeekContainsDate: 1
|
||||
}
|
||||
}
|
||||
|
||||
export default locale
|
||||
```
|
||||
|
||||
### localize
|
||||
|
||||
Put this object in `_lib/localize/index.js` inside your locale directory.
|
||||
Contains a number of functions for used by `format`:
|
||||
|
||||
```js
|
||||
var localize = {
|
||||
ordinalNumber,
|
||||
era,
|
||||
quarter,
|
||||
month,
|
||||
day,
|
||||
dayPeriod
|
||||
}
|
||||
|
||||
export default localize
|
||||
```
|
||||
|
||||
#### localize.ordinalNumber
|
||||
|
||||
Function that takes a numeric argument and returns a string with ordinal number:
|
||||
|
||||
```js
|
||||
// In `en-US` locale:
|
||||
function ordinalNumber (dirtyNumber, dirtyOptions) {
|
||||
var number = Number(dirtyNumber)
|
||||
|
||||
var rem100 = number % 100
|
||||
if (rem100 > 20 || rem100 < 10) {
|
||||
switch (rem100 % 10) {
|
||||
case 1:
|
||||
return number + 'st'
|
||||
case 2:
|
||||
return number + 'nd'
|
||||
case 3:
|
||||
return number + 'rd'
|
||||
}
|
||||
}
|
||||
return number + 'th'
|
||||
}
|
||||
|
||||
var localize = {
|
||||
ordinalNumber: ordinalNumber,
|
||||
// ...
|
||||
}
|
||||
```
|
||||
|
||||
If the form of the ordinal number depends on the grammatical case (or other grammatical structures),
|
||||
use `options.unit` argument which could be one of the values 'year', 'quarter', 'month', 'week',
|
||||
'date', 'dayOfYear', 'day', 'hour', 'minute' or 'second':
|
||||
|
||||
```js
|
||||
// In `ru` locale:
|
||||
function ordinalNumber (dirtyNumber, dirtyOptions) {
|
||||
var options = dirtyOptions || {}
|
||||
var unit = String(options.unit)
|
||||
var suffix
|
||||
|
||||
if (unit === 'date') {
|
||||
suffix = '-е'
|
||||
} else if (unit === 'week' || unit === 'minute' || unit === 'second') {
|
||||
suffix = '-я'
|
||||
} else {
|
||||
suffix = '-й'
|
||||
}
|
||||
|
||||
return dirtyNumber + suffix
|
||||
}
|
||||
```
|
||||
|
||||
#### localize.era and using buildLocalizeFn function
|
||||
|
||||
Localizes a numeric era. Takes either 0 or 1 as the first argument.
|
||||
As with many of the `localize` functions, they can be generated by built-in
|
||||
`buildLocalizeFn` function.
|
||||
|
||||
From CLDR chart, use ['Date & Time'/'Gregorian'/'Eras'](https://www.unicode.org/cldr/charts/32/summary/en.html#1771) values.
|
||||
|
||||
```js
|
||||
// In `en-US` locale:
|
||||
import buildLocalizeFn from '../../../_lib/buildLocalizeFn/index.js'
|
||||
|
||||
var eraValues = {
|
||||
narrow: ['B', 'A'],
|
||||
abbreviated: ['BC', 'AD'],
|
||||
wide: ['Before Christ', 'Anno Domini']
|
||||
}
|
||||
|
||||
var localize = {
|
||||
// ...
|
||||
era: buildLocalizeFn({
|
||||
values: eraValues,
|
||||
defaultWidth: 'wide'
|
||||
}),
|
||||
// ...
|
||||
}
|
||||
|
||||
export default localize
|
||||
```
|
||||
|
||||
General usage of the function:
|
||||
|
||||
```js
|
||||
var result = locale.localize.era(1, {width: 'abbreviated'})
|
||||
//=> 'AD'
|
||||
```
|
||||
|
||||
If `width` is not provided or the `values` object does not contain values for the provided width,
|
||||
`defaultWidth` will be used. `defaultWidth` should indicate the longest form of the localized value.
|
||||
The same is true for all other `localize` functions.
|
||||
`width` for `localize.era` function could be either 'narrow', 'abbreviated' or 'wide'.
|
||||
|
||||
```js
|
||||
var result = locale.localize.era(1, {width: 'foobar'})
|
||||
//=> 'Anno Domini'
|
||||
```
|
||||
|
||||
#### Formatting localizers
|
||||
|
||||
For some languages, there is a difference for "stand-alone" localizers and "formatting" localizers.
|
||||
"Stand-alone" means that the resulting value should make grammatical sense without context.
|
||||
"Formatting" means that the resulting value should be declined using the grammar rules of the language
|
||||
as if the value was a part of a date.
|
||||
For example, for languages with grammatical cases, stand-alone month could be in the nominative case ("January"),
|
||||
and formatting month could decline as a part of phrase "1st of January".
|
||||
In this case, use parameters `formattingValues` and `defaultFormattingWidth` of `buildLocalizeFn` function.
|
||||
|
||||
Any localizer could be stand-alone and formatting.
|
||||
Check the CLDR chart for the unit to see if stand-alone and formatting values are different for a certain unit.
|
||||
If there's no difference (usually it happens in languages without grammatical cases),
|
||||
parameters `formattingValues` and `defaultFormattingWidth` are not needed.
|
||||
|
||||
In this example, in Russian language a stand-alone month is in the nominative case ("январь"),
|
||||
and formatting month is in the genitive case ("января" as in "1-е января"). Notice the different endings:
|
||||
|
||||
```js
|
||||
// In `ru` locale:
|
||||
var monthValues = {
|
||||
narrow: ['Я', 'Ф', 'М', 'А', 'М', 'И', 'И', 'А', 'С', 'О', 'Н', 'Д'],
|
||||
abbreviated: ['янв.', 'фев.', 'март', 'апр.', 'май', 'июнь', 'июль', 'авг.', 'сент.', 'окт.', 'нояб.', 'дек.'],
|
||||
wide: ['январь', 'февраль', 'март', 'апрель', 'май', 'июнь', 'июль', 'август', 'сентябрь', 'октябрь', 'ноябрь', 'декабрь']
|
||||
}
|
||||
var formattingMonthValues = {
|
||||
narrow: ['Я', 'Ф', 'М', 'А', 'М', 'И', 'И', 'А', 'С', 'О', 'Н', 'Д'],
|
||||
abbreviated: ['янв.', 'фев.', 'мар.', 'апр.', 'мая', 'июн.', 'июл.', 'авг.', 'сент.', 'окт.', 'нояб.', 'дек.'],
|
||||
wide: ['января', 'февраля', 'марта', 'апреля', 'мая', 'июня', 'июля', 'августа', 'сентября', 'октября', 'ноября', 'декабря']
|
||||
}
|
||||
|
||||
var localize = {
|
||||
// ...
|
||||
month: buildLocalizeFn({
|
||||
values: monthValues,
|
||||
defaultWidth: 'wide',
|
||||
formattingValues: formattingMonthValues,
|
||||
defaultFormattingWidth: 'wide'
|
||||
}),
|
||||
// ...
|
||||
}
|
||||
|
||||
export default localize
|
||||
```
|
||||
|
||||
#### localize.quarter
|
||||
|
||||
Localizes a quarter. Takes 1, 2, 3 or 4 as the first argument.
|
||||
`width` could be either 'narrow', 'abbreviated' or 'wide'.
|
||||
From CLDR chart, use ['Date & Time'/'Gregorian'/'Quarters'](https://www.unicode.org/cldr/charts/32/summary/en.html#1781) values.
|
||||
|
||||
```js
|
||||
// In `en-US` locale:
|
||||
import buildLocalizeFn from '../../../_lib/buildLocalizeFn/index.js'
|
||||
|
||||
var quarterValues = {
|
||||
narrow: ['1', '2', '3', '4'],
|
||||
abbreviated: ['Q1', 'Q2', 'Q3', 'Q4'],
|
||||
wide: ['1st quarter', '2nd quarter', '3rd quarter', '4th quarter']
|
||||
}
|
||||
|
||||
var localize = {
|
||||
// ...
|
||||
quarter: buildLocalizeFn({
|
||||
values: quarterValues,
|
||||
defaultWidth: 'wide',
|
||||
argumentCallback: function (quarter) {
|
||||
return Number(quarter) - 1
|
||||
}
|
||||
}),
|
||||
// ...
|
||||
}
|
||||
|
||||
export default localize
|
||||
```
|
||||
|
||||
Note the usage of `argumentCallback` here. It converts the value passed into `localize.quarter` function
|
||||
(one of 1, 2, 3 or 4) into the index of the values array inside `quarterValues` (one of 0, 1, 2 or 3).
|
||||
|
||||
#### localize.month
|
||||
|
||||
Localizes a month. Takes numbers between 0 (for January) and 11 (for December).
|
||||
`width` could be either 'narrow', 'abbreviated' or 'wide'.
|
||||
From CLDR chart, use ['Date & Time'/'Gregorian'/'Months'](https://www.unicode.org/cldr/charts/32/summary/en.html#1793) values.
|
||||
|
||||
```js
|
||||
// In `en-US` locale:
|
||||
import buildLocalizeFn from '../../../_lib/buildLocalizeFn/index.js'
|
||||
|
||||
var monthValues = {
|
||||
narrow: ['J', 'F', 'M', 'A', 'M', 'J', 'J', 'A', 'S', 'O', 'N', 'D'],
|
||||
abbreviated: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'],
|
||||
wide: ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December']
|
||||
}
|
||||
|
||||
var localize = {
|
||||
// ...
|
||||
month: buildLocalizeFn({
|
||||
values: monthValues,
|
||||
defaultWidth: 'wide'
|
||||
}),
|
||||
// ...
|
||||
}
|
||||
|
||||
export default localize
|
||||
```
|
||||
|
||||
**NOTE**: in English, the names of days of the week and months are capitalized.
|
||||
Check if the same is true for the language you're working on.
|
||||
Generally, formatted dates should look like they are in the middle of a sentence,
|
||||
e.g. in Spanish language the weekdays and months should be in the lowercase:
|
||||
|
||||
```js
|
||||
// In `es` locale:
|
||||
var monthValues = {
|
||||
narrow: ['E', 'F', 'M', 'A', 'M', 'J', 'J', 'A', 'S', 'O', 'N', 'D'],
|
||||
abbreviated: ['ene.', 'feb.', 'mar.', 'abr.', 'may.', 'jun.', 'jul.', 'ago.', 'sep.', 'oct.', 'nov.', 'dic.'],
|
||||
wide: ['enero', 'febrero', 'marzo', 'abril', 'mayo', 'junio', 'julio', 'agosto', 'septiembre', 'octubre', 'noviembre', 'diciembre']
|
||||
}
|
||||
```
|
||||
|
||||
`monthValues.narrow` are usually capitalized in every language. Check the CLDR chart for your language.
|
||||
|
||||
#### localize.day
|
||||
|
||||
Localizes a week day. Takes numbers between 0 (for Sunday) and 6 (for Saturday).
|
||||
`width` could be either 'narrow', 'short', 'abbreviated' or 'wide'.
|
||||
From CLDR chart, use ['Date & Time'/'Gregorian'/'Days'](https://www.unicode.org/cldr/charts/32/summary/en.html#1829) values.
|
||||
|
||||
```js
|
||||
// In `en-US` locale:
|
||||
import buildLocalizeFn from '../../../_lib/buildLocalizeFn/index.js'
|
||||
|
||||
var dayValues = {
|
||||
narrow: ['S', 'M', 'T', 'W', 'T', 'F', 'S'],
|
||||
short: ['Su', 'Mo', 'Tu', 'We', 'Th', 'Fr', 'Sa'],
|
||||
abbreviated: ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'],
|
||||
wide: ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday']
|
||||
}
|
||||
|
||||
var localize = {
|
||||
// ...
|
||||
day: buildLocalizeFn({
|
||||
values: dayValues,
|
||||
defaultWidth: 'wide'
|
||||
}),
|
||||
// ...
|
||||
}
|
||||
|
||||
export default localize
|
||||
```
|
||||
|
||||
**NOTE**: the rules of capitalization from `localize.month` are also true for `localize.day`.
|
||||
|
||||
#### localize.dayPeriod
|
||||
|
||||
Localizes a certain day period.
|
||||
Could take of these strings as the argument: 'am', 'pm', 'midnight', 'noon', 'morning', 'afternoon', 'evening', 'night'.
|
||||
`width` could be either 'narrow', 'abbreviated' or 'wide'.
|
||||
From CLDR chart, use ['Date & Time'/'Gregorian'/'Day periods'](https://www.unicode.org/cldr/charts/32/summary/en.html#1857) values.
|
||||
|
||||
```js
|
||||
// In `en-US` locale:
|
||||
import buildLocalizeFn from '../../../_lib/buildLocalizeFn/index.js'
|
||||
|
||||
var dayPeriodValues = {
|
||||
narrow: {
|
||||
am: 'a',
|
||||
pm: 'p',
|
||||
midnight: 'mi',
|
||||
noon: 'n',
|
||||
morning: 'in the morning',
|
||||
afternoon: 'in the afternoon',
|
||||
evening: 'in the evening',
|
||||
night: 'at night'
|
||||
},
|
||||
abbreviated: {
|
||||
am: 'AM',
|
||||
pm: 'PM',
|
||||
midnight: 'midnight',
|
||||
noon: 'noon',
|
||||
morning: 'in the morning',
|
||||
afternoon: 'in the afternoon',
|
||||
evening: 'in the evening',
|
||||
night: 'at night'
|
||||
},
|
||||
wide: {
|
||||
am: 'a.m.',
|
||||
pm: 'p.m.',
|
||||
midnight: 'midnight',
|
||||
noon: 'noon',
|
||||
morning: 'in the morning',
|
||||
afternoon: 'in the afternoon',
|
||||
evening: 'in the evening',
|
||||
night: 'at night'
|
||||
}
|
||||
}
|
||||
|
||||
var localize = {
|
||||
// ...
|
||||
dayPeriod: buildLocalizeFn({
|
||||
values: dayPeriodValues,
|
||||
defaultWidth: 'wide'
|
||||
})
|
||||
}
|
||||
|
||||
export default localize
|
||||
```
|
||||
|
||||
### formatLong
|
||||
|
||||
Put this object in `_lib/formatLong/index.js` inside your locale directory.
|
||||
Locale date formats written in `format` token string format.
|
||||
See the list of tokens: https://date-fns.org/docs/format
|
||||
Use https://en.wikipedia.org/wiki/Date_format_by_country and CLDR chart as the reference.
|
||||
|
||||
#### formatLong.dateFormats
|
||||
|
||||
Use ['Date & Time'/'Gregorian'/'Formats - Standard - Date Formats'](https://www.unicode.org/cldr/charts/32/summary/en.html#1901) values
|
||||
from the CLDR chart as a reference.
|
||||
|
||||
```js
|
||||
// In `en-US` locale
|
||||
import buildFormatLongFn from '../../../_lib/buildFormatLongFn/index.js'
|
||||
|
||||
var dateFormats = {
|
||||
full: 'EEEE, MMMM do, y',
|
||||
long: 'MMMM do, y',
|
||||
medium: 'MMM d, y',
|
||||
short: 'MM/dd/yyyy'
|
||||
}
|
||||
|
||||
var formatLong = {
|
||||
date: buildFormatLongFn({
|
||||
formats: dateFormats,
|
||||
defaultWidth: 'full'
|
||||
}),
|
||||
// ...
|
||||
}
|
||||
|
||||
export default formatLong
|
||||
```
|
||||
|
||||
`dateFormats.long` usually contains the longest form of writing the year, the month, and the day of the month.
|
||||
Use ordinal day of the month ('do' token) where applicable (date-fns, unlike CLDR supports ordinal numbers).
|
||||
|
||||
`dateFormats.full` contains the same but with the day of the week.
|
||||
|
||||
`dateFormats.medium` contains the same values as `dateFormats.long`, but with short form of month and non-ordinal day.
|
||||
|
||||
`dateFormats.short` usually contains strictly numerical form of the date.
|
||||
Pay attention to the order of units (big-, little- or middle-endian)
|
||||
|
||||
#### formatLong.timeFormats
|
||||
|
||||
Use ['Date & Time'/'Gregorian'/'Formats - Standard - Time Formats'](https://www.unicode.org/cldr/charts/32/summary/en.html#1906) values
|
||||
from the CLDR chart as a reference.
|
||||
|
||||
Use some variation of 'h:mm aa' for 12-hour clock locales or 'H:mm' for 24-hour clock locales. Use the local time separator.
|
||||
|
||||
```js
|
||||
// In `en-US` locale
|
||||
import buildFormatLongFn from '../../../_lib/buildFormatLongFn/index.js'
|
||||
|
||||
var timeFormats = {
|
||||
full: 'h:mm:ss a zzzz',
|
||||
long: 'h:mm:ss a z',
|
||||
medium: 'h:mm:ss a',
|
||||
short: 'h:mm a'
|
||||
}
|
||||
|
||||
var formatLong = {
|
||||
// ...
|
||||
time: buildFormatLongFn({
|
||||
formats: timeFormats,
|
||||
defaultWidth: 'full'
|
||||
}),
|
||||
// ...
|
||||
}
|
||||
|
||||
export default formatLong
|
||||
```
|
||||
|
||||
#### formatLong.dateTimeFormats
|
||||
|
||||
Use
|
||||
['Date & Time'/'Gregorian'/'Formats - Standard - Date & Time Combination Formats'](https://www.unicode.org/cldr/charts/32/summary/en.html#1910)
|
||||
values from the CLDR chart.
|
||||
|
||||
```js
|
||||
// In `en-US` locale
|
||||
import buildFormatLongFn from '../../../_lib/buildFormatLongFn/index.js'
|
||||
|
||||
var dateTimeFormats = {
|
||||
full: "{{date}} 'at' {{time}}",
|
||||
long: "{{date}} 'at' {{time}}",
|
||||
medium: '{{date}}, {{time}}',
|
||||
short: '{{date}}, {{time}}'
|
||||
}
|
||||
|
||||
var formatLong = {
|
||||
// ...
|
||||
dateTime: buildFormatLongFn({
|
||||
formats: dateTimeFormats,
|
||||
defaultWidth: 'full'
|
||||
})
|
||||
}
|
||||
|
||||
export default formatLong
|
||||
```
|
||||
|
||||
'{{date}}' and '{{time}}' from the strings will be replaced with the date and time respectively.
|
||||
|
||||
### formatRelative
|
||||
|
||||
Put this function in `_lib/formatRelative/index.js` inside your locale directory.
|
||||
Relative date formats written in `format` token string format.
|
||||
See the list of tokens: https://date-fns.org/docs/format.
|
||||
Has to process `lastWeek`, `yesterday`, `today`, `tomorrow`, `nextWeek` and `other` tokens.
|
||||
|
||||
```javascript
|
||||
// In `en-US` locale
|
||||
var formatRelativeLocale = {
|
||||
lastWeek: "'last' eeee 'at' p",
|
||||
yesterday: "'yesterday at' p",
|
||||
today: "'today at' p",
|
||||
tomorrow: "'tomorrow at' p",
|
||||
nextWeek: "eeee 'at' p",
|
||||
other: 'P'
|
||||
}
|
||||
|
||||
export default function formatRelative (token, date, baseDate, options) {
|
||||
return formatRelativeLocale[token]
|
||||
}
|
||||
```
|
||||
|
||||
You can use `date` and `baseDate` supplied to the function for the difficult situations
|
||||
(e.g. grammatical genders and cases of the days of the week)
|
||||
Both `date` and `baseDate` are converted to UTC timezone, which means
|
||||
that you should use UTC methods to take the date values (i.e. `date.getUTCDay()` instead of `date.getDay()`).
|
||||
You can use UTC functions from `src/_lib` in date-fns root directory if they are available.
|
||||
Don't forget to pass `options` object to them!
|
||||
Example is below. Note the different grammatical case for weekdays (accusative instead of nominative)
|
||||
and declension of word "прошлый" which depends on the grammatical gender of the weekday:
|
||||
|
||||
```javascript
|
||||
// In `ru` locale
|
||||
import isSameUTCWeek from '../../../../_lib/isSameUTCWeek/index.js'
|
||||
|
||||
var accusativeWeekdays = ['воскресенье', 'понедельник', 'вторник', 'среду', 'четверг', 'пятницу', 'субботу']
|
||||
|
||||
function lastWeek (day) {
|
||||
var weekday = accusativeWeekdays[day]
|
||||
|
||||
switch (day) {
|
||||
case 0:
|
||||
return "'в прошлое " + weekday + " в' p"
|
||||
case 1:
|
||||
case 2:
|
||||
case 4:
|
||||
return "'в прошлый " + weekday + " в' p"
|
||||
case 3:
|
||||
case 5:
|
||||
case 6:
|
||||
return "'в прошлую " + weekday + " в' p"
|
||||
}
|
||||
}
|
||||
|
||||
function thisWeek (day) {
|
||||
// ...
|
||||
}
|
||||
|
||||
function nextWeek (day) {
|
||||
// ...
|
||||
}
|
||||
|
||||
var formatRelativeLocale = {
|
||||
lastWeek: function (date, baseDate, options) {
|
||||
var day = date.getUTCDay()
|
||||
if (isSameUTCWeek(date, baseDate, options)) {
|
||||
return thisWeek(day)
|
||||
} else {
|
||||
return lastWeek(day)
|
||||
}
|
||||
},
|
||||
yesterday: "'вчера в' p",
|
||||
today: "'сегодня в' p",
|
||||
tomorrow: "'завтра в' p",
|
||||
nextWeek: function (date, baseDate, options) {
|
||||
var day = date.getUTCDay()
|
||||
if (isSameUTCWeek(date, baseDate, options)) {
|
||||
return thisWeek(day)
|
||||
} else {
|
||||
return nextWeek(day)
|
||||
}
|
||||
},
|
||||
other: 'P'
|
||||
}
|
||||
|
||||
export default function formatRelative (token, date, baseDate, options) {
|
||||
var format = formatRelativeLocale[token]
|
||||
|
||||
if (typeof format === 'function') {
|
||||
return format(date, baseDate, options)
|
||||
}
|
||||
|
||||
return format
|
||||
}
|
||||
```
|
||||
|
||||
### match
|
||||
|
||||
Put this object in `_lib/match/index.js` inside your locale directory.
|
||||
Contains the functions used by `parse` to parse a localized value:
|
||||
|
||||
```js
|
||||
// In `en-US` locale:
|
||||
import buildMatchPatternFn from '../../../_lib/buildMatchPatternFn/index.js'
|
||||
import buildMatchFn from '../../../_lib/buildMatchFn/index.js'
|
||||
|
||||
var matchOrdinalNumberPattern = /^(\d+)(th|st|nd|rd)?/i
|
||||
var parseOrdinalNumberPattern = /\d+/i
|
||||
|
||||
var matchEraPatterns = {
|
||||
narrow: /^(b|a)/i,
|
||||
abbreviated: /^(b\.?\s?c\.?|b\.?\s?c\.?\s?e\.?|a\.?\s?d\.?|c\.?\s?e\.?)/i,
|
||||
wide: /^(before christ|before common era|anno domini|common era)/i
|
||||
}
|
||||
var parseEraPatterns = {
|
||||
any: [/^b/i, /^(a|c)/i]
|
||||
}
|
||||
|
||||
var matchQuarterPatterns = {
|
||||
narrow: /^[1234]/i,
|
||||
abbreviated: /^q[1234]/i,
|
||||
wide: /^[1234](th|st|nd|rd)? quarter/i
|
||||
}
|
||||
var parseQuarterPatterns = {
|
||||
any: [/1/i, /2/i, /3/i, /4/i]
|
||||
}
|
||||
|
||||
var matchMonthPatterns = {
|
||||
narrow: /^[jfmasond]/i,
|
||||
abbreviated: /^(jan|feb|mar|apr|may|jun|jul|aug|sep|oct|nov|dec)/i,
|
||||
wide: /^(january|february|march|april|may|june|july|august|september|october|november|december)/i
|
||||
}
|
||||
var parseMonthPatterns = {
|
||||
narrow: [/^j/i, /^f/i, /^m/i, /^a/i, /^m/i, /^j/i, /^j/i, /^a/i, /^s/i, /^o/i, /^n/i, /^d/i],
|
||||
any: [/^ja/i, /^f/i, /^mar/i, /^ap/i, /^may/i, /^jun/i, /^jul/i, /^au/i, /^s/i, /^o/i, /^n/i, /^d/i]
|
||||
}
|
||||
|
||||
var matchDayPatterns = {
|
||||
narrow: /^[smtwf]/i,
|
||||
short: /^(su|mo|tu|we|th|fr|sa)/i,
|
||||
abbreviated: /^(sun|mon|tue|wed|thu|fri|sat)/i,
|
||||
wide: /^(sunday|monday|tuesday|wednesday|thursday|friday|saturday)/i
|
||||
}
|
||||
var parseDayPatterns = {
|
||||
narrow: [/^s/i, /^m/i, /^t/i, /^w/i, /^t/i, /^f/i, /^s/i],
|
||||
any: [/^su/i, /^m/i, /^tu/i, /^w/i, /^th/i, /^f/i, /^sa/i]
|
||||
}
|
||||
|
||||
var matchDayPeriodPatterns = {
|
||||
narrow: /^(a|p|mi|n|(in the|at) (morning|afternoon|evening|night))/i,
|
||||
any: /^([ap]\.?\s?m\.?|midnight|noon|(in the|at) (morning|afternoon|evening|night))/i
|
||||
}
|
||||
var parseDayPeriodPatterns = {
|
||||
any: {
|
||||
am: /^a/i,
|
||||
pm: /^p/i,
|
||||
midnight: /^mi/i,
|
||||
noon: /^no/i,
|
||||
morning: /morning/i,
|
||||
afternoon: /afternoon/i,
|
||||
evening: /evening/i,
|
||||
night: /night/i
|
||||
}
|
||||
}
|
||||
|
||||
var match = {
|
||||
ordinalNumber: buildMatchPatternFn({
|
||||
matchPattern: matchOrdinalNumberPattern,
|
||||
parsePattern: parseOrdinalNumberPattern,
|
||||
valueCallback: function (value) {
|
||||
return parseInt(value, 10)
|
||||
}
|
||||
}),
|
||||
|
||||
era: buildMatchFn({
|
||||
matchPatterns: matchEraPatterns,
|
||||
defaultMatchWidth: 'wide',
|
||||
parsePatterns: parseEraPatterns,
|
||||
defaultParseWidth: 'any'
|
||||
}),
|
||||
|
||||
quarter: buildMatchFn({
|
||||
matchPatterns: matchQuarterPatterns,
|
||||
defaultMatchWidth: 'wide',
|
||||
parsePatterns: parseQuarterPatterns,
|
||||
defaultParseWidth: 'any',
|
||||
valueCallback: function (index) {
|
||||
return index + 1
|
||||
}
|
||||
}),
|
||||
|
||||
month: buildMatchFn({
|
||||
matchPatterns: matchMonthPatterns,
|
||||
defaultMatchWidth: 'wide',
|
||||
parsePatterns: parseMonthPatterns,
|
||||
defaultParseWidth: 'any'
|
||||
}),
|
||||
|
||||
day: buildMatchFn({
|
||||
matchPatterns: matchDayPatterns,
|
||||
defaultMatchWidth: 'wide',
|
||||
parsePatterns: parseDayPatterns,
|
||||
defaultParseWidth: 'any'
|
||||
}),
|
||||
|
||||
dayPeriod: buildMatchFn({
|
||||
matchPatterns: matchDayPeriodPatterns,
|
||||
defaultMatchWidth: 'any',
|
||||
parsePatterns: parseDayPeriodPatterns,
|
||||
defaultParseWidth: 'any'
|
||||
})
|
||||
}
|
||||
|
||||
export default match
|
||||
```
|
||||
|
||||
These functions mirror those in `localize`.
|
||||
|
||||
For `matchPatterns` the patterns should match the whole meaningful word for the parsed value
|
||||
(which will be cut from the string in the process of parsing).
|
||||
`parsePatterns` contains patterns to detect one of the values from the result of `matchPatterns`
|
||||
Note that the patterns for `parsePatterns` don't necessary contain the whole word:
|
||||
|
||||
```javascript
|
||||
// In `en-US` locale:
|
||||
var parseDayPatterns = {
|
||||
narrow: [/^s/i, /^m/i, /^t/i, /^w/i, /^t/i, /^f/i, /^s/i],
|
||||
any: [/^su/i, /^m/i, /^tu/i, /^w/i, /^th/i, /^f/i, /^sa/i]
|
||||
}
|
||||
```
|
||||
|
||||
but only the bare minimum to parse the value.
|
||||
|
||||
Also note that all patterns have "case-insensitive" flags
|
||||
to match as much arbitrary user input as possible. For the same reason, try to match
|
||||
any variation of diacritical marks:
|
||||
|
||||
```javascript
|
||||
// In `eo` locale:
|
||||
var matchDayPatterns = {
|
||||
narrow: /^[dlmĵjvs]/i,
|
||||
short: /^(di|lu|ma|me|(ĵ|jx|jh|j)a|ve|sa)/i,
|
||||
abbreviated: /^(dim|lun|mar|mer|(ĵ|jx|jh|j)a(ŭ|ux|uh|u)|ven|sab)/i,
|
||||
wide: /^(diman(ĉ|cx|ch|c)o|lundo|mardo|merkredo|(ĵ|jx|jh|j)a(ŭ|ux|uh|u)do|vendredo|sabato)/i
|
||||
}
|
||||
var parseDayPatterns = {
|
||||
narrow: [/^d/i, /^l/i, /^m/i, /^m/i, /^(j|ĵ)/i, /^v/i, /^s/i],
|
||||
any: [/^d/i, /^l/i, /^ma/i, /^me/i, /^(j|ĵ)/i, /^v/i, /^s/i]
|
||||
}
|
||||
```
|
||||
|
||||
Here, for the word "dimanĉo" the functions will match also "dimancxo", "dimancho"
|
||||
and even grammatically incorrect "dimanco".
|
||||
|
||||
Try to match any possible way of writing the word. Don't forget the grammatical cases:
|
||||
|
||||
```javascript
|
||||
// In `ru` locale:
|
||||
var matchMonthPatterns = {
|
||||
narrow: /^[яфмаисонд]/i,
|
||||
abbreviated: /^(янв|фев|март?|апр|ма[йя]|июн[ья]?|июл[ья]?|авг|сент?|окт|нояб?|дек)/i,
|
||||
wide: /^(январ[ья]|феврал[ья]|марта?|апрел[ья]|ма[йя]|июн[ья]|июл[ья]|августа?|сентябр[ья]|октябр[ья]|октябр[ья]|ноябр[ья]|декабр[ья])/i
|
||||
}
|
||||
```
|
||||
|
||||
and variations of short weekdays and months:
|
||||
|
||||
```javascript
|
||||
// In `ru` locale:
|
||||
var matchDayPatterns = {
|
||||
narrow: /^[впсч]/i,
|
||||
short: /^(вс|во|пн|по|вт|ср|чт|че|пт|пя|сб|су)\.?/i,
|
||||
abbreviated: /^(вск|вос|пнд|пон|втр|вто|срд|сре|чтв|чет|птн|пят|суб).?/i,
|
||||
wide: /^(воскресень[ея]|понедельника?|вторника?|сред[аы]|четверга?|пятниц[аы]|суббот[аы])/i
|
||||
}
|
||||
```
|
||||
|
||||
(here, the `abbreviated` pattern will match both `вск` and `вос` as the short of `воскресенье` {Sunday})
|
||||
|
||||
In `match.ordinalNumber` match ordinal numbers as well as non-ordinal numbers:
|
||||
|
||||
```javascript
|
||||
// In `en-US` locale:
|
||||
var matchOrdinalNumberPattern = /^(\d+)(th|st|nd|rd)?/i
|
||||
```
|
||||
|
||||
Don't forget the grammatical genders:
|
||||
|
||||
```javascript
|
||||
// In `ru` locale:
|
||||
var matchOrdinalNumberPattern = /^(\d+)(-?(е|я|й|ое|ье|ая|ья|ый|ой|ий|ый))?/i
|
||||
```
|
||||
|
||||
### formatDistance
|
||||
|
||||
`formatDistance` property of locale is a function which takes three arguments:
|
||||
token passed by date-fns' `formatDistance` function (e.g. 'lessThanXMinutes'),
|
||||
a number of units to be displayed by the function
|
||||
(e.g. `locale.formatDistance('lessThanXMinutes', 5)` would display localized 'less than 5 minutes')
|
||||
and object with options.
|
||||
|
||||
Your best guess is to copy `formatDistance` property from another locale and change the values.
|
||||
|
||||
### Tests
|
||||
|
||||
To test locales we use snapshots. See [`en-US` snapshot](https://github.com/date-fns/date-fns/blob/master/src/locale/en-US/snapshot.md) for an example.
|
||||
|
||||
To generate snapshots, run `yarn locale-snapshots`. The snapshot for the locale
|
||||
you're working on will appear in the root locale directory (e.g. `src/locales/ru/snapshot.md`).
|
||||
|
||||
Once you are done with the locale, generate the snapshot and review the output values.
|
||||
|
||||
## Creating a locale with the same language as another locale
|
||||
|
||||
Import the locale properties already implemented for the language,
|
||||
but replace unique properties.
|
||||
|
||||
```javascript
|
||||
// Same as en-US
|
||||
import formatDistance from '../en-US/_lib/formatDistance/index.js'
|
||||
import formatRelative from '../en-US/_lib/formatRelative/index.js'
|
||||
import localize from '../en-US/_lib/localize/index.js'
|
||||
import match from '../en-US/_lib/match/index.js'
|
||||
|
||||
// Unique for en-GB
|
||||
import formatLong from './_lib/formatLong/index.js'
|
||||
|
||||
/**
|
||||
* @type {Locale}
|
||||
* @category Locales
|
||||
* @summary English locale (United Kingdom).
|
||||
* @language English
|
||||
* @iso-639-2 eng
|
||||
* @author John Doe [@example]{@link https://github.com/example}
|
||||
*/
|
||||
var locale = {
|
||||
formatDistance: formatDistance,
|
||||
formatLong: formatLong,
|
||||
formatRelative: formatRelative,
|
||||
localize: localize,
|
||||
match: match,
|
||||
|
||||
// Unique for en-GB
|
||||
options: {
|
||||
weekStartsOn: 1,
|
||||
firstWeekContainsDate: 4
|
||||
}
|
||||
}
|
||||
|
||||
export default locale
|
||||
```
|
||||
+140
@@ -0,0 +1,140 @@
|
||||
const path = require('path')
|
||||
|
||||
module.exports = {
|
||||
groups: [
|
||||
'General',
|
||||
'Types',
|
||||
'Common Helpers',
|
||||
'Interval Helpers',
|
||||
'Timestamp Helpers',
|
||||
'Millisecond Helpers',
|
||||
'Second Helpers',
|
||||
'Minute Helpers',
|
||||
'Hour Helpers',
|
||||
'Day Helpers',
|
||||
'Weekday Helpers',
|
||||
'Week Helpers',
|
||||
'ISO Week Helpers',
|
||||
'Month Helpers',
|
||||
'Quarter Helpers',
|
||||
'Year Helpers',
|
||||
'ISO Week-Numbering Year Helpers',
|
||||
'Decade Helpers'
|
||||
],
|
||||
|
||||
staticDocs: [
|
||||
{
|
||||
type: 'markdown',
|
||||
urlId: 'Getting-Started',
|
||||
category: 'General',
|
||||
title: 'Getting Started',
|
||||
description: 'Introduction & installation instructions',
|
||||
path: path.join(__dirname, 'gettingStarted.md')
|
||||
},
|
||||
{
|
||||
type: 'markdown',
|
||||
urlId: 'Change-Log',
|
||||
category: 'General',
|
||||
title: 'Change Log',
|
||||
description: 'Changes for each version of the library',
|
||||
path: path.join(__dirname, '..', 'CHANGELOG.md')
|
||||
},
|
||||
{
|
||||
type: 'markdown',
|
||||
urlId: 'Contributing',
|
||||
category: 'General',
|
||||
title: 'Contributing',
|
||||
description: 'Contribution manual',
|
||||
path: path.join(__dirname, '..', 'CONTRIBUTING.md')
|
||||
},
|
||||
{
|
||||
type: 'markdown',
|
||||
urlId: 'Constants',
|
||||
category: 'General',
|
||||
title: 'Constants',
|
||||
description: 'Useful constants',
|
||||
path: path.join(__dirname, 'constants.md')
|
||||
},
|
||||
{
|
||||
type: 'markdown',
|
||||
urlId: 'I18n',
|
||||
category: 'General',
|
||||
title: 'I18n',
|
||||
description: 'Internationalization',
|
||||
path: path.join(__dirname, 'i18n.md')
|
||||
},
|
||||
{
|
||||
type: 'markdown',
|
||||
urlId: 'I18n-Contribution-Guide',
|
||||
category: 'General',
|
||||
title: 'I18n Contribution Guide',
|
||||
description: 'Locales manual',
|
||||
path: path.join(__dirname, 'i18nContributionGuide.md')
|
||||
},
|
||||
{
|
||||
type: 'markdown',
|
||||
urlId: 'Time-Zones',
|
||||
category: 'General',
|
||||
title: 'Time Zones',
|
||||
description: 'Time zone functions',
|
||||
path: path.join(__dirname, 'timeZones.md')
|
||||
},
|
||||
{
|
||||
type: 'markdown',
|
||||
urlId: 'ECMAScript-Modules',
|
||||
category: 'General',
|
||||
title: 'ECMAScript Modules',
|
||||
description: 'Tree-shaking guide',
|
||||
path: path.join(__dirname, 'esm.md')
|
||||
},
|
||||
{
|
||||
type: 'markdown',
|
||||
urlId: 'webpack',
|
||||
category: 'General',
|
||||
title: 'webpack',
|
||||
description: 'Using date-fns with webpack',
|
||||
path: path.join(__dirname, 'webpack.md')
|
||||
},
|
||||
{
|
||||
type: 'markdown',
|
||||
urlId: 'FP-Guide',
|
||||
category: 'General',
|
||||
title: 'FP Guide',
|
||||
description: 'Curried functions',
|
||||
path: path.join(__dirname, 'fp.md')
|
||||
},
|
||||
{
|
||||
type: 'markdown',
|
||||
urlId: 'Unicode-Tokens',
|
||||
category: 'General',
|
||||
title: 'Unicode Tokens',
|
||||
description: 'Usage of the Unicode tokens in parse and format',
|
||||
path: path.join(__dirname, 'unicodeTokens.md')
|
||||
},
|
||||
{
|
||||
type: 'markdown',
|
||||
urlId: 'Upgrade-Guide',
|
||||
category: 'General',
|
||||
title: 'Upgrade guide',
|
||||
description: 'Changes from v1 to v2',
|
||||
path: path.join(__dirname, 'upgradeGuide.md')
|
||||
},
|
||||
{
|
||||
type: 'markdown',
|
||||
urlId: 'License',
|
||||
category: 'General',
|
||||
title: 'License',
|
||||
description: 'MIT © Sasha Koss',
|
||||
path: path.join(__dirname, '..', 'LICENSE.md')
|
||||
}
|
||||
],
|
||||
|
||||
sharedDocs: [
|
||||
{
|
||||
fullPath: path.join(__dirname, 'Interval.js')
|
||||
},
|
||||
{
|
||||
fullPath: path.join(__dirname, 'Locale.js')
|
||||
}
|
||||
]
|
||||
}
|
||||
+26
@@ -0,0 +1,26 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<svg width="32px" height="26px" viewBox="0 0 32 26" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
|
||||
<!-- Generator: Sketch 3.7.1 (28215) - http://www.bohemiancoding.com/sketch -->
|
||||
<title>Slice 1</title>
|
||||
<desc>Created with Sketch.</desc>
|
||||
<defs></defs>
|
||||
<g id="Page-1" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">
|
||||
<g id="date-fns-mini-logo" fill="#770C56">
|
||||
<g id="Page-1">
|
||||
<g id="logo">
|
||||
<g id="Page-1">
|
||||
<g id="Solid-logo">
|
||||
<g id="White-logo">
|
||||
<path d="M0.0773377951,12.9617647 C0.0773377951,10.4657522 0.541359926,8.11201106 1.46941811,5.90047059 C2.39747629,3.68893013 3.73386003,1.72977324 5.47860941,0.0229411764 L8.98665179,0.0229411764 C5.34866372,3.58342956 3.52969697,7.89632761 3.52969697,12.9617647 C3.52969697,18.0272018 5.34866372,22.3400999 8.98665179,25.9005883 L5.47860941,25.9005883 C3.73386003,24.1937561 2.39747629,22.2345993 1.46941811,20.0230588 C0.541359926,17.8115184 0.0773377951,15.4577772 0.0773377951,12.9617647 L0.0773377951,12.9617647 L0.0773377951,12.9617647 L0.0773377951,12.9617647 Z M31.4378137,12.9617647 C31.4378137,15.4577772 30.9737916,17.8115184 30.0457334,20.0230588 C29.1176752,22.2345993 27.7812915,24.1937561 26.0365421,25.9005883 L22.5284998,25.9005883 C26.1664878,22.3400999 27.9854545,18.0272018 27.9854545,12.9617647 C27.9854545,7.89632761 26.1664878,3.58342956 22.5284998,0.0229411764 L26.0365421,0.0229411764 C27.7812915,1.72977324 29.1176752,3.68893013 30.0457334,5.90047059 C30.9737916,8.11201106 31.4378137,10.4657522 31.4378137,12.9617647 L31.4378137,12.9617647 L31.4378137,12.9617647 L31.4378137,12.9617647 Z" id="Parans"></path>
|
||||
<g id="Hands" transform="translate(12.954081, 1.720588)">
|
||||
<rect id="Hand" x="0" y="0" width="2.32013386" height="13.1911764"></rect>
|
||||
<polygon id="Hand" points="2.3189551 13.1499342 0.815087916 11.6629302 10.2484366 2.3353599 11.7523038 3.82236388 2.3189551 13.1499342"></polygon>
|
||||
</g>
|
||||
</g>
|
||||
</g>
|
||||
</g>
|
||||
</g>
|
||||
</g>
|
||||
</g>
|
||||
</g>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 2.4 KiB |
+62
@@ -0,0 +1,62 @@
|
||||
# Time Zones
|
||||
|
||||
## Table of Contents
|
||||
|
||||
- [Overview](#overview)
|
||||
|
||||
- [`date-fns-tz`](#date-fns-tz)
|
||||
|
||||
## Overview
|
||||
|
||||
Working with UTC or ISO date strings is easy, and so is working with JS dates when all times
|
||||
are displayed in a user's local time in the browser. The difficulty comes when working with another
|
||||
time zone's local time, other than the current system's, like showing the local time of an event in LA
|
||||
at 8pm PST on a Node server in Europe or a user's machine set to EST.
|
||||
|
||||
In this case there are two relevant pieces of information:
|
||||
- a fixed moment in time in the form of a timestamp, UTC or ISO date string, and
|
||||
- the time zone descriptor, usually an offset or IANA time zone name (e.g. `America/Los_Angeles`).
|
||||
|
||||
Libraries like Moment and Luxon, which provide their own date time classes, manage these timestamp and time
|
||||
zone values internally. Since `date-fns` always returns a plain JS Date, which implicitly has the current
|
||||
system's time zone, helper functions are needed for handling common time zone related use cases.
|
||||
|
||||
## [`date-fns-tz`](https://www.npmjs.com/package/date-fns-tz)
|
||||
|
||||
Dependency free IANA time zone support is implemented via the
|
||||
[Intl API](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl) to keep
|
||||
actual time zone data out of code bundles. Modern browsers all support the
|
||||
[necessary features](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DateTimeFormat#Browser_compatibility),
|
||||
and for those that don't a [polyfill](https://github.com/yahoo/date-time-format-timezone) can be used.
|
||||
|
||||
Functions are provided for converting to and from a Date instance which will have the internal UTC time
|
||||
adjusted so it prints to the correct time value in the associated time zone, regardless of the current
|
||||
system time zone. The `date-fns` `format` function is extended with support for the `z...zzzz` tokens to
|
||||
format long and short time zone names.
|
||||
|
||||
Compatible with `date-fns` version 2
|
||||
|
||||
License: MIT
|
||||
|
||||
### Synopsis
|
||||
|
||||
```js
|
||||
const { zonedTimeToUtc, utcToZonedTime, format } = require('date-fns-tz')
|
||||
|
||||
// Set the date to "2018-09-01T16:01:36.386Z"
|
||||
const utcDate = zonedTimeToUtc('2018-09-01 18:01:36.386', 'Europe/Berlin')
|
||||
|
||||
// Obtain a Date instance that will render the equivalent Berlin time for the UTC date
|
||||
const date = new Date('2018-09-01Z16:01:36.386Z')
|
||||
const timeZone = 'Europe/Berlin'
|
||||
const zonedDate = utcToZonedTime(date, timeZone)
|
||||
// zonedDate could be used to initialize a date picker or display the formatted local date/time
|
||||
|
||||
// Set the output to "1.9.2018 18:01:36.386 GMT+02:00 (CEST)"
|
||||
const pattern = 'D.M.YYYY HH:mm:ss.SSS [GMT]Z (z)'
|
||||
const output = format(zonedDate, pattern, { timeZone })
|
||||
```
|
||||
|
||||
### Links
|
||||
|
||||
- [API / Usage Scenarios](https://github.com/marnusw/date-fns-tz#time-zone-helpers)
|
||||
+54
@@ -0,0 +1,54 @@
|
||||
# Unicode Tokens
|
||||
|
||||
Starting with v2 `format` and `parse` uses [Unicode tokens].
|
||||
|
||||
The tokens are different from Moment.js and other libraries that opted to use
|
||||
custom formatting rules. While usage of a standard ensures compatibility and
|
||||
the future of the library it causes confusion that this document intended
|
||||
to resolve.
|
||||
|
||||
## Popular mistakes
|
||||
|
||||
There are 4 tokens that causes the most of confusion:
|
||||
|
||||
- `D` and `DD` that represent the day of a year (1, 2, ..., 365, 366)
|
||||
are often confused with `d` and `dd` that represent the day of a month
|
||||
(1, 2, ..., 31).
|
||||
|
||||
- `YY` and `YYYY` that represent the local week-numbering year (44, 01, 00, 17)
|
||||
are often confused with `yy` and `yyyy` that represent the the calendar year.
|
||||
|
||||
```js
|
||||
// ❌ Wrong!
|
||||
format(new Date(), 'YYYY-MM-DD')
|
||||
//=> 2018-10-283
|
||||
|
||||
// ✅ Correct
|
||||
format(new Date(), 'yyyy-MM-dd')
|
||||
//=> 2018-10-10
|
||||
|
||||
// ❌ Wrong!
|
||||
parse('11.02.87', 'D.MM.YY', new Date()).toString()
|
||||
//=> 'Sat Jan 11 1986 00:00:00 GMT+0200 (EET)'
|
||||
|
||||
// ✅ Correct
|
||||
parse('11.02.87', 'd.MM.yy', new Date()).toString()
|
||||
//=> 'Wed Feb 11 1987 00:00:00 GMT+0200 (EET)'
|
||||
```
|
||||
|
||||
To help with the issue, `format` and `parse` functions won't accept
|
||||
these tokens without `useAdditionalDayOfYearTokens` option for `D` and `DD` and
|
||||
`useAdditionalWeekYearTokens` options for `YY` and `YYYY`:
|
||||
|
||||
```js
|
||||
format(new Date(), 'D', { useAdditionalDayOfYearTokens: true })
|
||||
//=> '283'
|
||||
|
||||
parse('365+1987', 'DD+YYYY', new Date(), {
|
||||
useAdditionalDayOfYearTokens: true,
|
||||
useAdditionalWeekYearTokens: true
|
||||
}).toString()
|
||||
//=> 'Wed Dec 31 1986 00:00:00 GMT+0200 (EET)'
|
||||
```
|
||||
|
||||
[Unicode tokens]: https://www.unicode.org/reports/tr35/tr35-dates.html#Date_Field_Symbol_Table
|
||||
+116
@@ -0,0 +1,116 @@
|
||||
# v2 Upgrade Guide
|
||||
|
||||
## Common changes
|
||||
|
||||
### Camel case naming schema
|
||||
|
||||
Function submodules now use camelCase naming schema:
|
||||
|
||||
```javascript
|
||||
// Before v2.0.0
|
||||
import differenceInCalendarISOYears from 'date-fns/difference_in_calendar_iso_years'
|
||||
|
||||
// v2.0.0 onward
|
||||
import differenceInCalendarISOYears from 'date-fns/differenceInCalendarISOYears'
|
||||
```
|
||||
|
||||
### New formatting tokens
|
||||
|
||||
Starting with v2 `format` and `parse` uses [Unicode tokens].
|
||||
|
||||
See [Unicode Tokens doc](./unicodeTokens.md) for more details.
|
||||
|
||||
### String arguments
|
||||
|
||||
Functions now don't accept strings as arguments. Strings should
|
||||
be parsed using `parseISO` (ISO 8601) or `parse`.
|
||||
|
||||
See [this post](https://blog.date-fns.org/post/we-cut-date-fns-v2-minimal-build-size-down-to-300-bytes-and-now-its-the-smallest-date-library-18f2nvh2z0yal) for more details.
|
||||
|
||||
```javascript
|
||||
// Before v2.0.0
|
||||
addDays('2016-01-01', 1)
|
||||
|
||||
// v2.0.0 onward
|
||||
addDays(parseISO('2016-01-01'), 1)
|
||||
```
|
||||
|
||||
### Arguments conversion
|
||||
|
||||
All functions now implicitly convert arguments by following rules:
|
||||
|
||||
| | date | number | string | boolean |
|
||||
| --------- | ------------ | ------ | ----------- | ------- |
|
||||
| 0 | new Date(0) | 0 | '0' | false |
|
||||
| '0' | Invalid Date | 0 | '0' | false |
|
||||
| 1 | new Date(1) | 1 | '1' | true |
|
||||
| '1' | Invalid Date | 1 | '1' | true |
|
||||
| true | Invalid Date | NaN | 'true' | true |
|
||||
| false | Invalid Date | NaN | 'false' | false |
|
||||
| null | Invalid Date | NaN | 'null' | false |
|
||||
| undefined | Invalid Date | NaN | 'undefined' | false |
|
||||
| NaN | Invalid Date | NaN | 'NaN' | false |
|
||||
|
||||
Notes:
|
||||
|
||||
- as before, arguments expected to be `Date` are converted to `Date` using _date-fns'_ `toDate` function;
|
||||
- arguments expected to be numbers are converted to integer numbers using our custom `toInteger` implementation
|
||||
(see [#765](https://github.com/date-fns/date-fns/pull/765));
|
||||
- arguments expected to be strings are converted to strings using JavaScript's `String` function;
|
||||
- arguments expected to be booleans are converted to boolean using JavaScript's `Boolean` function.
|
||||
|
||||
`null` and `undefined` passed to optional arguments (i.e. properties of `options` argument)
|
||||
are ignored as if no argument was passed.
|
||||
|
||||
If any argument is invalid (i.e. `NaN` for numbers and `Invalid Date` for dates),
|
||||
an invalid value will be returned:
|
||||
|
||||
- `false` for functions that return booleans (expect `isValid`);
|
||||
- `Invalid Date` for functions that return dates;
|
||||
- `NaN` for functions that return numbers;
|
||||
- and `String('Invalid Date')` for functions that return strings.
|
||||
|
||||
See tests and PRs [#460](https://github.com/date-fns/date-fns/pull/460) and
|
||||
[#765](https://github.com/date-fns/date-fns/pull/765) for exact behavior.
|
||||
|
||||
### `null`
|
||||
|
||||
`null` now is not a valid date. `isValid(null)` returns `false`;
|
||||
`toDate(null)` returns an invalid date. Since `toDate` is used internally
|
||||
by all the functions, operations over `null` will also return an invalid date.
|
||||
[See #537](https://github.com/date-fns/date-fns/issues/537) for the reasoning.
|
||||
|
||||
### `RangeError`
|
||||
|
||||
Functions now throw `RangeError` if optional values passed to `options`
|
||||
are not `undefined` or have expected values.
|
||||
This change is introduced for consistency with ECMAScript standard library which does the same.
|
||||
|
||||
### `TypeError`
|
||||
|
||||
All functions now check if the passed number of arguments is less
|
||||
than the number of required arguments and throw `TypeError` exception if so.
|
||||
|
||||
### UMD/CDN
|
||||
|
||||
The Bower & UMD/CDN package versions are no longer supported.
|
||||
|
||||
### New locale format
|
||||
|
||||
See [docs/Locale](https://date-fns.org/docs/Locale).
|
||||
|
||||
Locales renamed:
|
||||
|
||||
- `en` → `en-US`
|
||||
- `zh_cn` → `zh-CN`
|
||||
- `zh_tw` → `zh-TW`
|
||||
|
||||
```javascript
|
||||
// Before v2.0.0
|
||||
import locale from 'date-fns/locale/zh_cn'
|
||||
|
||||
// v2.0.0 onward
|
||||
import locale from 'date-fns/locale/zh-CN'
|
||||
```
|
||||
|
||||
[unicode tokens]: https://www.unicode.org/reports/tr35/tr35-dates.html#Date_Field_Symbol_Table
|
||||
+47
@@ -0,0 +1,47 @@
|
||||
# webpack
|
||||
|
||||
## Removing unused languages from dynamic import
|
||||
|
||||
If locale is required dynamically all languages in the date-fns are loaded by webpack into bundle (~160kb) or split across the chunks. This prolongs the build process and increases the amount of space taken. However, it is possible to use webpack to trim down languages using [ContextReplacementPlugin].
|
||||
|
||||
Let's assume that we have a single point in which supported locales are present:
|
||||
|
||||
`config.js`:
|
||||
|
||||
```js
|
||||
export const supportedLocales = ['en', 'de', 'pl', 'it']
|
||||
```
|
||||
|
||||
We could also have a function that formats the date:
|
||||
|
||||
```js
|
||||
const getLocale = locale => require(`date-fns/locale/${locale}/index.js`)
|
||||
|
||||
const formatDate = (date, formatStyle, locale) => {
|
||||
return format(date, formatStyle, {
|
||||
locale: getLocale(locale)
|
||||
})
|
||||
}
|
||||
```
|
||||
|
||||
In order to exclude unused languages we can use webpacks [ContextReplacementPlugin].
|
||||
|
||||
`webpack.config.js`:
|
||||
|
||||
```js
|
||||
import webpack from 'webpack'
|
||||
import { supportedLocales } from './config.js'
|
||||
|
||||
export default const config = {
|
||||
plugins: [
|
||||
new webpack.ContextReplacementPlugin(
|
||||
/date\-fns[\/\\]/,
|
||||
new RegExp(`[/\\\\\](${supportedLocales.join('|')})[/\\\\\]`)
|
||||
)
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
This results in a language bundle of ~23kb .
|
||||
|
||||
[ContextReplacementPlugin]: https://webpack.js.org/plugins/context-replacement-plugin/
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
// This file is generated automatically by `scripts/build/typings.js`. Please, don't change it.
|
||||
|
||||
import { eachDayOfInterval } from 'date-fns'
|
||||
export default eachDayOfInterval
|
||||
+102
@@ -0,0 +1,102 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.default = eachDayOfInterval;
|
||||
|
||||
var _index = _interopRequireDefault(require("../toDate/index.js"));
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
|
||||
/**
|
||||
* @name eachDayOfInterval
|
||||
* @category Interval Helpers
|
||||
* @summary Return the array of dates within the specified time interval.
|
||||
*
|
||||
* @description
|
||||
* Return the array of dates within the specified time interval.
|
||||
*
|
||||
* ### v2.0.0 breaking changes:
|
||||
*
|
||||
* - [Changes that are common for the whole library](https://github.com/date-fns/date-fns/blob/master/docs/upgradeGuide.md#Common-Changes).
|
||||
*
|
||||
* - The function was renamed from `eachDay` to `eachDayOfInterval`.
|
||||
* This change was made to mirror the use of the word "interval" in standard ISO 8601:2004 terminology:
|
||||
*
|
||||
* ```
|
||||
* 2.1.3
|
||||
* time interval
|
||||
* part of the time axis limited by two instants
|
||||
* ```
|
||||
*
|
||||
* Also, this function now accepts an object with `start` and `end` properties
|
||||
* instead of two arguments as an interval.
|
||||
* This function now throws `RangeError` if the start of the interval is after its end
|
||||
* or if any date in the interval is `Invalid Date`.
|
||||
*
|
||||
* ```javascript
|
||||
* // Before v2.0.0
|
||||
*
|
||||
* eachDay(new Date(2014, 0, 10), new Date(2014, 0, 20))
|
||||
*
|
||||
* // v2.0.0 onward
|
||||
*
|
||||
* eachDayOfInterval(
|
||||
* { start: new Date(2014, 0, 10), end: new Date(2014, 0, 20) }
|
||||
* )
|
||||
* ```
|
||||
*
|
||||
* @param {Interval} interval - the interval. See [Interval]{@link docs/types/Interval}
|
||||
* @param {Object} [options] - an object with options.
|
||||
* @param {Number} [options.step=1] - the step to increment by. The value should be more than 1.
|
||||
* @returns {Date[]} the array with starts of days from the day of the interval start to the day of the interval end
|
||||
* @throws {TypeError} 1 argument required
|
||||
* @throws {RangeError} `options.step` must be a number greater than 1
|
||||
* @throws {RangeError} The start of an interval cannot be after its end
|
||||
* @throws {RangeError} Date in interval cannot be `Invalid Date`
|
||||
*
|
||||
* @example
|
||||
* // Each day between 6 October 2014 and 10 October 2014:
|
||||
* var result = eachDayOfInterval({
|
||||
* start: new Date(2014, 9, 6),
|
||||
* end: new Date(2014, 9, 10)
|
||||
* })
|
||||
* //=> [
|
||||
* // Mon Oct 06 2014 00:00:00,
|
||||
* // Tue Oct 07 2014 00:00:00,
|
||||
* // Wed Oct 08 2014 00:00:00,
|
||||
* // Thu Oct 09 2014 00:00:00,
|
||||
* // Fri Oct 10 2014 00:00:00
|
||||
* // ]
|
||||
*/
|
||||
function eachDayOfInterval(dirtyInterval, options) {
|
||||
if (arguments.length < 1) {
|
||||
throw new TypeError('1 argument required, but only ' + arguments.length + ' present');
|
||||
}
|
||||
|
||||
var interval = dirtyInterval || {};
|
||||
var startDate = (0, _index.default)(interval.start);
|
||||
var endDate = (0, _index.default)(interval.end);
|
||||
var endTime = endDate.getTime(); // Throw an exception if start date is after end date or if any date is `Invalid Date`
|
||||
|
||||
if (!(startDate.getTime() <= endTime)) {
|
||||
throw new RangeError('Invalid interval');
|
||||
}
|
||||
|
||||
var dates = [];
|
||||
var currentDate = startDate;
|
||||
currentDate.setHours(0, 0, 0, 0);
|
||||
var step = options && 'step' in options ? Number(options.step) : 1;
|
||||
if (step < 1 || isNaN(step)) throw new RangeError('`options.step` must be a number greater than 1');
|
||||
|
||||
while (currentDate.getTime() <= endTime) {
|
||||
dates.push((0, _index.default)(currentDate));
|
||||
currentDate.setDate(currentDate.getDate() + step);
|
||||
currentDate.setHours(0, 0, 0, 0);
|
||||
}
|
||||
|
||||
return dates;
|
||||
}
|
||||
|
||||
module.exports = exports.default;
|
||||
+43
@@ -0,0 +1,43 @@
|
||||
// @flow
|
||||
// This file is generated automatically by `scripts/build/typings.js`. Please, don't change it.
|
||||
|
||||
export type Interval = {
|
||||
start: Date | number,
|
||||
end: Date | number
|
||||
}
|
||||
|
||||
export type Locale = {
|
||||
formatDistance: (...args: Array<any>) => any,
|
||||
formatRelative: (...args: Array<any>) => any,
|
||||
localize: {
|
||||
ordinalNumber: (...args: Array<any>) => any,
|
||||
era: (...args: Array<any>) => any,
|
||||
quarter: (...args: Array<any>) => any,
|
||||
month: (...args: Array<any>) => any,
|
||||
day: (...args: Array<any>) => any,
|
||||
dayPeriod: (...args: Array<any>) => any
|
||||
},
|
||||
formatLong: Object,
|
||||
date: (...args: Array<any>) => any,
|
||||
time: (...args: Array<any>) => any,
|
||||
dateTime: (...args: Array<any>) => any,
|
||||
match: {
|
||||
ordinalNumber: (...args: Array<any>) => any,
|
||||
era: (...args: Array<any>) => any,
|
||||
quarter: (...args: Array<any>) => any,
|
||||
month: (...args: Array<any>) => any,
|
||||
day: (...args: Array<any>) => any,
|
||||
dayPeriod: (...args: Array<any>) => any
|
||||
},
|
||||
options?: {
|
||||
weekStartsOn?: 0 | 1 | 2 | 3 | 4 | 5 | 6,
|
||||
firstWeekContainsDate?: 1 | 2 | 3 | 4 | 5 | 6 | 7
|
||||
}
|
||||
}
|
||||
|
||||
declare module.exports: (
|
||||
interval: Interval,
|
||||
options?: {
|
||||
step?: number
|
||||
}
|
||||
) => Date[]
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"sideEffects": false,
|
||||
"module": "../esm/eachDayOfInterval/index.js",
|
||||
"typings": "../typings.d.ts"
|
||||
}
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
// This file is generated automatically by `scripts/build/typings.js`. Please, don't change it.
|
||||
|
||||
import { eachWeekOfInterval } from 'date-fns'
|
||||
export default eachWeekOfInterval
|
||||
+88
@@ -0,0 +1,88 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.default = eachWeekOfInterval;
|
||||
|
||||
var _index = _interopRequireDefault(require("../addWeeks/index.js"));
|
||||
|
||||
var _index2 = _interopRequireDefault(require("../startOfWeek/index.js"));
|
||||
|
||||
var _index3 = _interopRequireDefault(require("../toDate/index.js"));
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
|
||||
/**
|
||||
* @name eachWeekOfInterval
|
||||
* @category Interval Helpers
|
||||
* @summary Return the array of weeks within the specified time interval.
|
||||
*
|
||||
* @description
|
||||
* Return the array of weeks within the specified time interval.
|
||||
*
|
||||
* ### v2.0.0 breaking changes:
|
||||
*
|
||||
* - [Changes that are common for the whole library](https://github.com/date-fns/date-fns/blob/master/docs/upgradeGuide.md#Common-Changes).
|
||||
*
|
||||
* @param {Interval} interval - the interval. See [Interval]{@link docs/types/Interval}
|
||||
* @param {Object} [options] - an object with options.
|
||||
* @param {Locale} [options.locale=defaultLocale] - the locale object. See [Locale]{@link https://date-fns.org/docs/Locale}
|
||||
* @param {0|1|2|3|4|5|6} [options.weekStartsOn=0] - the index of the first day of the week (0 - Sunday)
|
||||
* @returns {Date[]} the array with starts of weeks from the week of the interval start to the week of the interval end
|
||||
* @throws {TypeError} 1 argument required
|
||||
* @throws {RangeError} `options.weekStartsOn` must be 0, 1, ..., 6
|
||||
* @throws {RangeError} The start of an interval cannot be after its end
|
||||
* @throws {RangeError} Date in interval cannot be `Invalid Date`
|
||||
*
|
||||
* @example
|
||||
* // Each week within interval 6 October 2014 - 23 November 2014:
|
||||
* var result = eachWeekOfInterval({
|
||||
* start: new Date(2014, 9, 6),
|
||||
* end: new Date(2014, 10, 23)
|
||||
* })
|
||||
* //=> [
|
||||
* // Sun Oct 05 2014 00:00:00,
|
||||
* // Sun Oct 12 2014 00:00:00,
|
||||
* // Sun Oct 19 2014 00:00:00,
|
||||
* // Sun Oct 26 2014 00:00:00,
|
||||
* // Sun Nov 02 2014 00:00:00,
|
||||
* // Sun Nov 09 2014 00:00:00,
|
||||
* // Sun Nov 16 2014 00:00:00,
|
||||
* // Sun Nov 23 2014 00:00:00
|
||||
* // ]
|
||||
*/
|
||||
function eachWeekOfInterval(dirtyInterval, options) {
|
||||
if (arguments.length < 1) {
|
||||
throw new TypeError('1 argument required, but only ' + arguments.length + ' present');
|
||||
}
|
||||
|
||||
var interval = dirtyInterval || {};
|
||||
var startDate = (0, _index3.default)(interval.start);
|
||||
var endDate = (0, _index3.default)(interval.end);
|
||||
var endTime = endDate.getTime(); // Throw an exception if start date is after end date or if any date is `Invalid Date`
|
||||
|
||||
if (!(startDate.getTime() <= endTime)) {
|
||||
throw new RangeError('Invalid interval');
|
||||
}
|
||||
|
||||
var startDateWeek = (0, _index2.default)(startDate, options);
|
||||
var endDateWeek = (0, _index2.default)(endDate, options); // Some timezones switch DST at midnight, making start of day unreliable in these timezones, 3pm is a safe bet
|
||||
|
||||
startDateWeek.setHours(15);
|
||||
endDateWeek.setHours(15);
|
||||
endTime = endDateWeek.getTime();
|
||||
var weeks = [];
|
||||
var currentWeek = startDateWeek;
|
||||
|
||||
while (currentWeek.getTime() <= endTime) {
|
||||
currentWeek.setHours(0);
|
||||
weeks.push((0, _index3.default)(currentWeek));
|
||||
currentWeek = (0, _index.default)(currentWeek, 1);
|
||||
currentWeek.setHours(15);
|
||||
}
|
||||
|
||||
return weeks;
|
||||
}
|
||||
|
||||
module.exports = exports.default;
|
||||
+44
@@ -0,0 +1,44 @@
|
||||
// @flow
|
||||
// This file is generated automatically by `scripts/build/typings.js`. Please, don't change it.
|
||||
|
||||
export type Interval = {
|
||||
start: Date | number,
|
||||
end: Date | number
|
||||
}
|
||||
|
||||
export type Locale = {
|
||||
formatDistance: (...args: Array<any>) => any,
|
||||
formatRelative: (...args: Array<any>) => any,
|
||||
localize: {
|
||||
ordinalNumber: (...args: Array<any>) => any,
|
||||
era: (...args: Array<any>) => any,
|
||||
quarter: (...args: Array<any>) => any,
|
||||
month: (...args: Array<any>) => any,
|
||||
day: (...args: Array<any>) => any,
|
||||
dayPeriod: (...args: Array<any>) => any
|
||||
},
|
||||
formatLong: Object,
|
||||
date: (...args: Array<any>) => any,
|
||||
time: (...args: Array<any>) => any,
|
||||
dateTime: (...args: Array<any>) => any,
|
||||
match: {
|
||||
ordinalNumber: (...args: Array<any>) => any,
|
||||
era: (...args: Array<any>) => any,
|
||||
quarter: (...args: Array<any>) => any,
|
||||
month: (...args: Array<any>) => any,
|
||||
day: (...args: Array<any>) => any,
|
||||
dayPeriod: (...args: Array<any>) => any
|
||||
},
|
||||
options?: {
|
||||
weekStartsOn?: 0 | 1 | 2 | 3 | 4 | 5 | 6,
|
||||
firstWeekContainsDate?: 1 | 2 | 3 | 4 | 5 | 6 | 7
|
||||
}
|
||||
}
|
||||
|
||||
declare module.exports: (
|
||||
interval: Interval,
|
||||
options?: {
|
||||
locale?: Locale,
|
||||
weekStartsOn?: 0 | 1 | 2 | 3 | 4 | 5 | 6
|
||||
}
|
||||
) => Date[]
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"sideEffects": false,
|
||||
"module": "../esm/eachWeekOfInterval/index.js",
|
||||
"typings": "../typings.d.ts"
|
||||
}
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
// This file is generated automatically by `scripts/build/typings.js`. Please, don't change it.
|
||||
|
||||
import { eachWeekendOfInterval } from 'date-fns'
|
||||
export default eachWeekendOfInterval
|
||||
+64
@@ -0,0 +1,64 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.default = eachWeekendOfInterval;
|
||||
|
||||
var _index = _interopRequireDefault(require("../eachDayOfInterval/index.js"));
|
||||
|
||||
var _index2 = _interopRequireDefault(require("../isSunday/index.js"));
|
||||
|
||||
var _index3 = _interopRequireDefault(require("../isWeekend/index.js"));
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
|
||||
/**
|
||||
* @name eachWeekendOfInterval
|
||||
* @category Interval Helpers
|
||||
* @summary List all the Saturdays and Sundays in the given date interval.
|
||||
*
|
||||
* @description
|
||||
* Get all the Saturdays and Sundays in the given date interval.
|
||||
*
|
||||
* @param {Interval} interval - the given interval. See [Interval]{@link docs/types/Interval}
|
||||
* @returns {Date[]} an array containing all the Saturdays and Sundays
|
||||
* @throws {TypeError} 1 argument required
|
||||
* @throws {RangeError} The start of an interval cannot be after its end
|
||||
* @throws {RangeError} Date in interval cannot be `Invalid Date`
|
||||
*
|
||||
* @example
|
||||
* // Lists all Saturdays and Sundays in the given date interval
|
||||
* var result = eachWeekendOfInterval({
|
||||
* start: new Date(2018, 8, 17),
|
||||
* end: new Date(2018, 8, 30)
|
||||
* })
|
||||
* //=> [
|
||||
* // Sat Sep 22 2018 00:00:00,
|
||||
* // Sun Sep 23 2018 00:00:00,
|
||||
* // Sat Sep 29 2018 00:00:00,
|
||||
* // Sun Sep 30 2018 00:00:00
|
||||
* // ]
|
||||
*/
|
||||
function eachWeekendOfInterval(interval) {
|
||||
if (arguments.length < 1) {
|
||||
throw new TypeError('1 argument required, but only ' + arguments.length + ' present');
|
||||
}
|
||||
|
||||
var dateInterval = (0, _index.default)(interval);
|
||||
var weekends = [];
|
||||
var index = 0;
|
||||
|
||||
while (index < dateInterval.length) {
|
||||
var date = dateInterval[index++];
|
||||
|
||||
if ((0, _index3.default)(date)) {
|
||||
weekends.push(date);
|
||||
if ((0, _index2.default)(date)) index = index + 5;
|
||||
}
|
||||
}
|
||||
|
||||
return weekends;
|
||||
}
|
||||
|
||||
module.exports = exports.default;
|
||||
+38
@@ -0,0 +1,38 @@
|
||||
// @flow
|
||||
// This file is generated automatically by `scripts/build/typings.js`. Please, don't change it.
|
||||
|
||||
export type Interval = {
|
||||
start: Date | number,
|
||||
end: Date | number
|
||||
}
|
||||
|
||||
export type Locale = {
|
||||
formatDistance: (...args: Array<any>) => any,
|
||||
formatRelative: (...args: Array<any>) => any,
|
||||
localize: {
|
||||
ordinalNumber: (...args: Array<any>) => any,
|
||||
era: (...args: Array<any>) => any,
|
||||
quarter: (...args: Array<any>) => any,
|
||||
month: (...args: Array<any>) => any,
|
||||
day: (...args: Array<any>) => any,
|
||||
dayPeriod: (...args: Array<any>) => any
|
||||
},
|
||||
formatLong: Object,
|
||||
date: (...args: Array<any>) => any,
|
||||
time: (...args: Array<any>) => any,
|
||||
dateTime: (...args: Array<any>) => any,
|
||||
match: {
|
||||
ordinalNumber: (...args: Array<any>) => any,
|
||||
era: (...args: Array<any>) => any,
|
||||
quarter: (...args: Array<any>) => any,
|
||||
month: (...args: Array<any>) => any,
|
||||
day: (...args: Array<any>) => any,
|
||||
dayPeriod: (...args: Array<any>) => any
|
||||
},
|
||||
options?: {
|
||||
weekStartsOn?: 0 | 1 | 2 | 3 | 4 | 5 | 6,
|
||||
firstWeekContainsDate?: 1 | 2 | 3 | 4 | 5 | 6 | 7
|
||||
}
|
||||
}
|
||||
|
||||
declare module.exports: (interval: Interval) => Date[]
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"sideEffects": false,
|
||||
"module": "../esm/eachWeekendOfInterval/index.js",
|
||||
"typings": "../typings.d.ts"
|
||||
}
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
// This file is generated automatically by `scripts/build/typings.js`. Please, don't change it.
|
||||
|
||||
import { eachWeekendOfMonth } from 'date-fns'
|
||||
export default eachWeekendOfMonth
|
||||
+57
@@ -0,0 +1,57 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.default = eachWeekendOfMonth;
|
||||
|
||||
var _index = _interopRequireDefault(require("../eachWeekendOfInterval/index.js"));
|
||||
|
||||
var _index2 = _interopRequireDefault(require("../startOfMonth/index.js"));
|
||||
|
||||
var _index3 = _interopRequireDefault(require("../endOfMonth/index.js"));
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
|
||||
/**
|
||||
* @name eachWeekendOfMonth
|
||||
* @category Month Helpers
|
||||
* @summary List all the Saturdays and Sundays in the given month.
|
||||
*
|
||||
* @description
|
||||
* Get all the Saturdays and Sundays in the given month.
|
||||
*
|
||||
* @param {Date|Number} date - the given month
|
||||
* @returns {Date[]} an array containing all the Saturdays and Sundays
|
||||
* @throws {TypeError} 1 argument required
|
||||
* @throws {RangeError} The passed date is invalid
|
||||
*
|
||||
* @example
|
||||
* // Lists all Saturdays and Sundays in the given month
|
||||
* var result = eachWeekendOfMonth(new Date(2022, 1, 1))
|
||||
* //=> [
|
||||
* // Sat Feb 05 2022 00:00:00,
|
||||
* // Sun Feb 06 2022 00:00:00,
|
||||
* // Sat Feb 12 2022 00:00:00,
|
||||
* // Sun Feb 13 2022 00:00:00,
|
||||
* // Sat Feb 19 2022 00:00:00,
|
||||
* // Sun Feb 20 2022 00:00:00,
|
||||
* // Sat Feb 26 2022 00:00:00,
|
||||
* // Sun Feb 27 2022 00:00:00
|
||||
* // ]
|
||||
*/
|
||||
function eachWeekendOfMonth(dirtyDate) {
|
||||
if (arguments.length < 1) {
|
||||
throw new TypeError('1 arguments required, but only ' + arguments.length + ' present');
|
||||
}
|
||||
|
||||
var startDate = (0, _index2.default)(dirtyDate);
|
||||
if (isNaN(startDate)) throw new RangeError('The passed date is invalid');
|
||||
var endDate = (0, _index3.default)(dirtyDate);
|
||||
return (0, _index.default)({
|
||||
start: startDate,
|
||||
end: endDate
|
||||
});
|
||||
}
|
||||
|
||||
module.exports = exports.default;
|
||||
+38
@@ -0,0 +1,38 @@
|
||||
// @flow
|
||||
// This file is generated automatically by `scripts/build/typings.js`. Please, don't change it.
|
||||
|
||||
export type Interval = {
|
||||
start: Date | number,
|
||||
end: Date | number
|
||||
}
|
||||
|
||||
export type Locale = {
|
||||
formatDistance: (...args: Array<any>) => any,
|
||||
formatRelative: (...args: Array<any>) => any,
|
||||
localize: {
|
||||
ordinalNumber: (...args: Array<any>) => any,
|
||||
era: (...args: Array<any>) => any,
|
||||
quarter: (...args: Array<any>) => any,
|
||||
month: (...args: Array<any>) => any,
|
||||
day: (...args: Array<any>) => any,
|
||||
dayPeriod: (...args: Array<any>) => any
|
||||
},
|
||||
formatLong: Object,
|
||||
date: (...args: Array<any>) => any,
|
||||
time: (...args: Array<any>) => any,
|
||||
dateTime: (...args: Array<any>) => any,
|
||||
match: {
|
||||
ordinalNumber: (...args: Array<any>) => any,
|
||||
era: (...args: Array<any>) => any,
|
||||
quarter: (...args: Array<any>) => any,
|
||||
month: (...args: Array<any>) => any,
|
||||
day: (...args: Array<any>) => any,
|
||||
dayPeriod: (...args: Array<any>) => any
|
||||
},
|
||||
options?: {
|
||||
weekStartsOn?: 0 | 1 | 2 | 3 | 4 | 5 | 6,
|
||||
firstWeekContainsDate?: 1 | 2 | 3 | 4 | 5 | 6 | 7
|
||||
}
|
||||
}
|
||||
|
||||
declare module.exports: (date: Date | number) => Date[]
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"sideEffects": false,
|
||||
"module": "../esm/eachWeekendOfMonth/index.js",
|
||||
"typings": "../typings.d.ts"
|
||||
}
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
// This file is generated automatically by `scripts/build/typings.js`. Please, don't change it.
|
||||
|
||||
import { eachWeekendOfYear } from 'date-fns'
|
||||
export default eachWeekendOfYear
|
||||
+54
@@ -0,0 +1,54 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.default = eachWeekendOfYear;
|
||||
|
||||
var _index = _interopRequireDefault(require("../eachWeekendOfInterval/index.js"));
|
||||
|
||||
var _index2 = _interopRequireDefault(require("../startOfYear/index.js"));
|
||||
|
||||
var _index3 = _interopRequireDefault(require("../endOfYear/index.js"));
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
|
||||
/**
|
||||
* @name eachWeekendOfYear
|
||||
* @category Year Helpers
|
||||
* @summary List all the Saturdays and Sundays in the year.
|
||||
*
|
||||
* @description
|
||||
* Get all the Saturdays and Sundays in the year.
|
||||
*
|
||||
* @param {Date|Number} date - the given year
|
||||
* @returns {Date[]} an array containing all the Saturdays and Sundays
|
||||
* @throws {TypeError} 1 argument required
|
||||
* @throws {RangeError} The passed date is invalid
|
||||
*
|
||||
* @example
|
||||
* // Lists all Saturdays and Sundays in the year
|
||||
* var result = eachWeekendOfYear(new Date(2020, 1, 1))
|
||||
* //=> [
|
||||
* // Sat Jan 03 2020 00:00:00,
|
||||
* // Sun Jan 04 2020 00:00:00,
|
||||
* // ...
|
||||
* // Sun Dec 27 2020 00:00:00
|
||||
* // ]
|
||||
* ]
|
||||
*/
|
||||
function eachWeekendOfYear(dirtyDate) {
|
||||
if (arguments.length < 1) {
|
||||
throw new TypeError('1 arguments required, but only ' + arguments.length + ' present');
|
||||
}
|
||||
|
||||
var startDate = (0, _index2.default)(dirtyDate);
|
||||
if (isNaN(startDate)) throw new RangeError('The passed date is invalid');
|
||||
var endDate = (0, _index3.default)(dirtyDate);
|
||||
return (0, _index.default)({
|
||||
start: startDate,
|
||||
end: endDate
|
||||
});
|
||||
}
|
||||
|
||||
module.exports = exports.default;
|
||||
+38
@@ -0,0 +1,38 @@
|
||||
// @flow
|
||||
// This file is generated automatically by `scripts/build/typings.js`. Please, don't change it.
|
||||
|
||||
export type Interval = {
|
||||
start: Date | number,
|
||||
end: Date | number
|
||||
}
|
||||
|
||||
export type Locale = {
|
||||
formatDistance: (...args: Array<any>) => any,
|
||||
formatRelative: (...args: Array<any>) => any,
|
||||
localize: {
|
||||
ordinalNumber: (...args: Array<any>) => any,
|
||||
era: (...args: Array<any>) => any,
|
||||
quarter: (...args: Array<any>) => any,
|
||||
month: (...args: Array<any>) => any,
|
||||
day: (...args: Array<any>) => any,
|
||||
dayPeriod: (...args: Array<any>) => any
|
||||
},
|
||||
formatLong: Object,
|
||||
date: (...args: Array<any>) => any,
|
||||
time: (...args: Array<any>) => any,
|
||||
dateTime: (...args: Array<any>) => any,
|
||||
match: {
|
||||
ordinalNumber: (...args: Array<any>) => any,
|
||||
era: (...args: Array<any>) => any,
|
||||
quarter: (...args: Array<any>) => any,
|
||||
month: (...args: Array<any>) => any,
|
||||
day: (...args: Array<any>) => any,
|
||||
dayPeriod: (...args: Array<any>) => any
|
||||
},
|
||||
options?: {
|
||||
weekStartsOn?: 0 | 1 | 2 | 3 | 4 | 5 | 6,
|
||||
firstWeekContainsDate?: 1 | 2 | 3 | 4 | 5 | 6 | 7
|
||||
}
|
||||
}
|
||||
|
||||
declare module.exports: (date: Date | number) => Date[]
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"sideEffects": false,
|
||||
"module": "../esm/eachWeekendOfYear/index.js",
|
||||
"typings": "../typings.d.ts"
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user