project files added
This commit is contained in:
+10
@@ -0,0 +1,10 @@
|
||||
export default function addLeadingZeros(number, targetLength) {
|
||||
var sign = number < 0 ? '-' : '';
|
||||
var output = Math.abs(number).toString();
|
||||
|
||||
while (output.length < targetLength) {
|
||||
output = '0' + output;
|
||||
}
|
||||
|
||||
return sign + output;
|
||||
}
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
export default 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;
|
||||
}
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
import assign from '../assign/index.js';
|
||||
export default function cloneObject(dirtyObject) {
|
||||
return assign({}, dirtyObject);
|
||||
}
|
||||
+856
@@ -0,0 +1,856 @@
|
||||
import lightFormatters from '../lightFormatters/index.js';
|
||||
import getUTCDayOfYear from '../../../_lib/getUTCDayOfYear/index.js';
|
||||
import getUTCISOWeek from '../../../_lib/getUTCISOWeek/index.js';
|
||||
import getUTCISOWeekYear from '../../../_lib/getUTCISOWeekYear/index.js';
|
||||
import getUTCWeek from '../../../_lib/getUTCWeek/index.js';
|
||||
import getUTCWeekYear from '../../../_lib/getUTCWeekYear/index.js';
|
||||
import addLeadingZeros from '../../addLeadingZeros/index.js';
|
||||
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 lightFormatters.y(date, token);
|
||||
},
|
||||
// Local week-numbering year
|
||||
Y: function (date, token, localize, options) {
|
||||
var signedWeekYear = getUTCWeekYear(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 addLeadingZeros(twoDigitYear, 2);
|
||||
} // Ordinal number
|
||||
|
||||
|
||||
if (token === 'Yo') {
|
||||
return localize.ordinalNumber(weekYear, {
|
||||
unit: 'year'
|
||||
});
|
||||
} // Padding
|
||||
|
||||
|
||||
return addLeadingZeros(weekYear, token.length);
|
||||
},
|
||||
// ISO week-numbering year
|
||||
R: function (date, token) {
|
||||
var isoWeekYear = getUTCISOWeekYear(date); // Padding
|
||||
|
||||
return addLeadingZeros(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 addLeadingZeros(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 addLeadingZeros(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 addLeadingZeros(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 lightFormatters.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 addLeadingZeros(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 = getUTCWeek(date, options);
|
||||
|
||||
if (token === 'wo') {
|
||||
return localize.ordinalNumber(week, {
|
||||
unit: 'week'
|
||||
});
|
||||
}
|
||||
|
||||
return addLeadingZeros(week, token.length);
|
||||
},
|
||||
// ISO week of year
|
||||
I: function (date, token, localize) {
|
||||
var isoWeek = getUTCISOWeek(date);
|
||||
|
||||
if (token === 'Io') {
|
||||
return localize.ordinalNumber(isoWeek, {
|
||||
unit: 'week'
|
||||
});
|
||||
}
|
||||
|
||||
return addLeadingZeros(isoWeek, token.length);
|
||||
},
|
||||
// Day of the month
|
||||
d: function (date, token, localize) {
|
||||
if (token === 'do') {
|
||||
return localize.ordinalNumber(date.getUTCDate(), {
|
||||
unit: 'date'
|
||||
});
|
||||
}
|
||||
|
||||
return lightFormatters.d(date, token);
|
||||
},
|
||||
// Day of year
|
||||
D: function (date, token, localize) {
|
||||
var dayOfYear = getUTCDayOfYear(date);
|
||||
|
||||
if (token === 'Do') {
|
||||
return localize.ordinalNumber(dayOfYear, {
|
||||
unit: 'dayOfYear'
|
||||
});
|
||||
}
|
||||
|
||||
return addLeadingZeros(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 addLeadingZeros(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 addLeadingZeros(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 addLeadingZeros(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 lightFormatters.h(date, token);
|
||||
},
|
||||
// Hour [0-23]
|
||||
H: function (date, token, localize) {
|
||||
if (token === 'Ho') {
|
||||
return localize.ordinalNumber(date.getUTCHours(), {
|
||||
unit: 'hour'
|
||||
});
|
||||
}
|
||||
|
||||
return lightFormatters.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 addLeadingZeros(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 addLeadingZeros(hours, token.length);
|
||||
},
|
||||
// Minute
|
||||
m: function (date, token, localize) {
|
||||
if (token === 'mo') {
|
||||
return localize.ordinalNumber(date.getUTCMinutes(), {
|
||||
unit: 'minute'
|
||||
});
|
||||
}
|
||||
|
||||
return lightFormatters.m(date, token);
|
||||
},
|
||||
// Second
|
||||
s: function (date, token, localize) {
|
||||
if (token === 'so') {
|
||||
return localize.ordinalNumber(date.getUTCSeconds(), {
|
||||
unit: 'second'
|
||||
});
|
||||
}
|
||||
|
||||
return lightFormatters.s(date, token);
|
||||
},
|
||||
// Fraction of second
|
||||
S: function (date, token) {
|
||||
return lightFormatters.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 addLeadingZeros(timestamp, token.length);
|
||||
},
|
||||
// Milliseconds timestamp
|
||||
T: function (date, token, _localize, options) {
|
||||
var originalDate = options._originalDate || date;
|
||||
var timestamp = originalDate.getTime();
|
||||
return addLeadingZeros(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 + addLeadingZeros(minutes, 2);
|
||||
}
|
||||
|
||||
function formatTimezoneWithOptionalMinutes(offset, dirtyDelimiter) {
|
||||
if (offset % 60 === 0) {
|
||||
var sign = offset > 0 ? '-' : '+';
|
||||
return sign + addLeadingZeros(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 = addLeadingZeros(Math.floor(absOffset / 60), 2);
|
||||
var minutes = addLeadingZeros(absOffset % 60, 2);
|
||||
return sign + hours + delimiter + minutes;
|
||||
}
|
||||
|
||||
export default formatters;
|
||||
+82
@@ -0,0 +1,82 @@
|
||||
import addLeadingZeros from '../../addLeadingZeros/index.js';
|
||||
/*
|
||||
* | | 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 addLeadingZeros(token === 'yy' ? year % 100 : year, token.length);
|
||||
},
|
||||
// Month
|
||||
M: function (date, token) {
|
||||
var month = date.getUTCMonth();
|
||||
return token === 'M' ? String(month + 1) : addLeadingZeros(month + 1, 2);
|
||||
},
|
||||
// Day of the month
|
||||
d: function (date, token) {
|
||||
return addLeadingZeros(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 addLeadingZeros(date.getUTCHours() % 12 || 12, token.length);
|
||||
},
|
||||
// Hour [0-23]
|
||||
H: function (date, token) {
|
||||
return addLeadingZeros(date.getUTCHours(), token.length);
|
||||
},
|
||||
// Minute
|
||||
m: function (date, token) {
|
||||
return addLeadingZeros(date.getUTCMinutes(), token.length);
|
||||
},
|
||||
// Second
|
||||
s: function (date, token) {
|
||||
return addLeadingZeros(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 addLeadingZeros(fractionalSeconds, token.length);
|
||||
}
|
||||
};
|
||||
export default formatters;
|
||||
+96
@@ -0,0 +1,96 @@
|
||||
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
|
||||
};
|
||||
export default longFormatters;
|
||||
Generated
Vendored
+20
@@ -0,0 +1,20 @@
|
||||
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.
|
||||
*/
|
||||
|
||||
export default 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;
|
||||
}
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
import toDate from '../../toDate/index.js';
|
||||
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
|
||||
|
||||
export default function getUTCDayOfYear(dirtyDate) {
|
||||
if (arguments.length < 1) {
|
||||
throw new TypeError('1 argument required, but only ' + arguments.length + ' present');
|
||||
}
|
||||
|
||||
var date = toDate(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;
|
||||
}
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
import toDate from '../../toDate/index.js';
|
||||
import startOfUTCISOWeek from '../startOfUTCISOWeek/index.js';
|
||||
import startOfUTCISOWeekYear from '../startOfUTCISOWeekYear/index.js';
|
||||
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
|
||||
|
||||
export default function getUTCISOWeek(dirtyDate) {
|
||||
if (arguments.length < 1) {
|
||||
throw new TypeError('1 argument required, but only ' + arguments.length + ' present');
|
||||
}
|
||||
|
||||
var date = toDate(dirtyDate);
|
||||
var diff = startOfUTCISOWeek(date).getTime() - startOfUTCISOWeekYear(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;
|
||||
}
|
||||
+28
@@ -0,0 +1,28 @@
|
||||
import toDate from '../../toDate/index.js';
|
||||
import startOfUTCISOWeek from '../startOfUTCISOWeek/index.js'; // 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
|
||||
|
||||
export default function getUTCISOWeekYear(dirtyDate) {
|
||||
if (arguments.length < 1) {
|
||||
throw new TypeError('1 argument required, but only ' + arguments.length + ' present');
|
||||
}
|
||||
|
||||
var date = toDate(dirtyDate);
|
||||
var year = date.getUTCFullYear();
|
||||
var fourthOfJanuaryOfNextYear = new Date(0);
|
||||
fourthOfJanuaryOfNextYear.setUTCFullYear(year + 1, 0, 4);
|
||||
fourthOfJanuaryOfNextYear.setUTCHours(0, 0, 0, 0);
|
||||
var startOfNextYear = startOfUTCISOWeek(fourthOfJanuaryOfNextYear);
|
||||
var fourthOfJanuaryOfThisYear = new Date(0);
|
||||
fourthOfJanuaryOfThisYear.setUTCFullYear(year, 0, 4);
|
||||
fourthOfJanuaryOfThisYear.setUTCHours(0, 0, 0, 0);
|
||||
var startOfThisYear = startOfUTCISOWeek(fourthOfJanuaryOfThisYear);
|
||||
|
||||
if (date.getTime() >= startOfNextYear.getTime()) {
|
||||
return year + 1;
|
||||
} else if (date.getTime() >= startOfThisYear.getTime()) {
|
||||
return year;
|
||||
} else {
|
||||
return year - 1;
|
||||
}
|
||||
}
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
import toDate from '../../toDate/index.js';
|
||||
import startOfUTCWeek from '../startOfUTCWeek/index.js';
|
||||
import startOfUTCWeekYear from '../startOfUTCWeekYear/index.js';
|
||||
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
|
||||
|
||||
export default function getUTCWeek(dirtyDate, options) {
|
||||
if (arguments.length < 1) {
|
||||
throw new TypeError('1 argument required, but only ' + arguments.length + ' present');
|
||||
}
|
||||
|
||||
var date = toDate(dirtyDate);
|
||||
var diff = startOfUTCWeek(date, options).getTime() - startOfUTCWeekYear(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;
|
||||
}
|
||||
+39
@@ -0,0 +1,39 @@
|
||||
import toInteger from '../toInteger/index.js';
|
||||
import toDate from '../../toDate/index.js';
|
||||
import startOfUTCWeek from '../startOfUTCWeek/index.js'; // 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
|
||||
|
||||
export default function getUTCWeekYear(dirtyDate, dirtyOptions) {
|
||||
if (arguments.length < 1) {
|
||||
throw new TypeError('1 argument required, but only ' + arguments.length + ' present');
|
||||
}
|
||||
|
||||
var date = toDate(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 : toInteger(localeFirstWeekContainsDate);
|
||||
var firstWeekContainsDate = options.firstWeekContainsDate == null ? defaultFirstWeekContainsDate : toInteger(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 = startOfUTCWeek(firstWeekOfNextYear, dirtyOptions);
|
||||
var firstWeekOfThisYear = new Date(0);
|
||||
firstWeekOfThisYear.setUTCFullYear(year, 0, firstWeekContainsDate);
|
||||
firstWeekOfThisYear.setUTCHours(0, 0, 0, 0);
|
||||
var startOfThisYear = startOfUTCWeek(firstWeekOfThisYear, dirtyOptions);
|
||||
|
||||
if (date.getTime() >= startOfNextYear.getTime()) {
|
||||
return year + 1;
|
||||
} else if (date.getTime() >= startOfThisYear.getTime()) {
|
||||
return year;
|
||||
} else {
|
||||
return year - 1;
|
||||
}
|
||||
}
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
import startOfUTCWeek from '../startOfUTCWeek/index.js'; // 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
|
||||
|
||||
export default function isSameUTCWeek(dirtyDateLeft, dirtyDateRight, options) {
|
||||
if (arguments.length < 2) {
|
||||
throw new TypeError('2 argument required, but only ' + arguments.length + ' present');
|
||||
}
|
||||
|
||||
var dateLeftStartOfWeek = startOfUTCWeek(dirtyDateLeft, options);
|
||||
var dateRightStartOfWeek = startOfUTCWeek(dirtyDateRight, options);
|
||||
return dateLeftStartOfWeek.getTime() === dateRightStartOfWeek.getTime();
|
||||
}
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
var protectedDayOfYearTokens = ['D', 'DD'];
|
||||
var protectedWeekYearTokens = ['YY', 'YYYY'];
|
||||
export function isProtectedDayOfYearToken(token) {
|
||||
return protectedDayOfYearTokens.indexOf(token) !== -1;
|
||||
}
|
||||
export function isProtectedWeekYearToken(token) {
|
||||
return protectedWeekYearTokens.indexOf(token) !== -1;
|
||||
}
|
||||
export 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');
|
||||
}
|
||||
}
|
||||
+28
@@ -0,0 +1,28 @@
|
||||
import toInteger from '../toInteger/index.js';
|
||||
import toDate from '../../toDate/index.js'; // 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
|
||||
|
||||
export default 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 : toInteger(localeWeekStartsOn);
|
||||
var weekStartsOn = options.weekStartsOn == null ? defaultWeekStartsOn : toInteger(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 = toDate(dirtyDate);
|
||||
var day = toInteger(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;
|
||||
}
|
||||
+24
@@ -0,0 +1,24 @@
|
||||
import toInteger from '../toInteger/index.js';
|
||||
import toDate from '../../toDate/index.js'; // 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
|
||||
|
||||
export default function setUTCISODay(dirtyDate, dirtyDay) {
|
||||
if (arguments.length < 2) {
|
||||
throw new TypeError('2 arguments required, but only ' + arguments.length + ' present');
|
||||
}
|
||||
|
||||
var day = toInteger(dirtyDay);
|
||||
|
||||
if (day % 7 === 0) {
|
||||
day = day - 7;
|
||||
}
|
||||
|
||||
var weekStartsOn = 1;
|
||||
var date = toDate(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;
|
||||
}
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
import toInteger from '../toInteger/index.js';
|
||||
import toDate from '../../toDate/index.js';
|
||||
import getUTCISOWeek from '../getUTCISOWeek/index.js'; // 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
|
||||
|
||||
export default function setUTCISOWeek(dirtyDate, dirtyISOWeek) {
|
||||
if (arguments.length < 2) {
|
||||
throw new TypeError('2 arguments required, but only ' + arguments.length + ' present');
|
||||
}
|
||||
|
||||
var date = toDate(dirtyDate);
|
||||
var isoWeek = toInteger(dirtyISOWeek);
|
||||
var diff = getUTCISOWeek(date) - isoWeek;
|
||||
date.setUTCDate(date.getUTCDate() - diff * 7);
|
||||
return date;
|
||||
}
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
import toInteger from '../toInteger/index.js';
|
||||
import toDate from '../../toDate/index.js';
|
||||
import getUTCWeek from '../getUTCWeek/index.js'; // 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
|
||||
|
||||
export default function setUTCWeek(dirtyDate, dirtyWeek, options) {
|
||||
if (arguments.length < 2) {
|
||||
throw new TypeError('2 arguments required, but only ' + arguments.length + ' present');
|
||||
}
|
||||
|
||||
var date = toDate(dirtyDate);
|
||||
var week = toInteger(dirtyWeek);
|
||||
var diff = getUTCWeek(date, options) - week;
|
||||
date.setUTCDate(date.getUTCDate() - diff * 7);
|
||||
return date;
|
||||
}
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
import toDate from '../../toDate/index.js'; // 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
|
||||
|
||||
export default function startOfUTCISOWeek(dirtyDate) {
|
||||
if (arguments.length < 1) {
|
||||
throw new TypeError('1 argument required, but only ' + arguments.length + ' present');
|
||||
}
|
||||
|
||||
var weekStartsOn = 1;
|
||||
var date = toDate(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;
|
||||
}
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
import getUTCISOWeekYear from '../getUTCISOWeekYear/index.js';
|
||||
import startOfUTCISOWeek from '../startOfUTCISOWeek/index.js'; // 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
|
||||
|
||||
export default function startOfUTCISOWeekYear(dirtyDate) {
|
||||
if (arguments.length < 1) {
|
||||
throw new TypeError('1 argument required, but only ' + arguments.length + ' present');
|
||||
}
|
||||
|
||||
var year = getUTCISOWeekYear(dirtyDate);
|
||||
var fourthOfJanuary = new Date(0);
|
||||
fourthOfJanuary.setUTCFullYear(year, 0, 4);
|
||||
fourthOfJanuary.setUTCHours(0, 0, 0, 0);
|
||||
var date = startOfUTCISOWeek(fourthOfJanuary);
|
||||
return date;
|
||||
}
|
||||
+26
@@ -0,0 +1,26 @@
|
||||
import toInteger from '../toInteger/index.js';
|
||||
import toDate from '../../toDate/index.js'; // 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
|
||||
|
||||
export default 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 : toInteger(localeWeekStartsOn);
|
||||
var weekStartsOn = options.weekStartsOn == null ? defaultWeekStartsOn : toInteger(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 = toDate(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;
|
||||
}
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
import toInteger from '../toInteger/index.js';
|
||||
import getUTCWeekYear from '../getUTCWeekYear/index.js';
|
||||
import startOfUTCWeek from '../startOfUTCWeek/index.js'; // 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
|
||||
|
||||
export default 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 : toInteger(localeFirstWeekContainsDate);
|
||||
var firstWeekContainsDate = options.firstWeekContainsDate == null ? defaultFirstWeekContainsDate : toInteger(options.firstWeekContainsDate);
|
||||
var year = getUTCWeekYear(dirtyDate, dirtyOptions);
|
||||
var firstWeek = new Date(0);
|
||||
firstWeek.setUTCFullYear(year, 0, firstWeekContainsDate);
|
||||
firstWeek.setUTCHours(0, 0, 0, 0);
|
||||
var date = startOfUTCWeek(firstWeek, dirtyOptions);
|
||||
return date;
|
||||
}
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
export default 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);
|
||||
}
|
||||
+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
|
||||
+45
@@ -0,0 +1,45 @@
|
||||
import isWeekend from '../isWeekend/index.js';
|
||||
import toDate from '../toDate/index.js';
|
||||
import toInteger from '../_lib/toInteger/index.js';
|
||||
/**
|
||||
* @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)
|
||||
*/
|
||||
|
||||
export default function addBusinessDays(dirtyDate, dirtyAmount) {
|
||||
if (arguments.length < 2) {
|
||||
throw new TypeError('2 arguments required, but only ' + arguments.length + ' present');
|
||||
}
|
||||
|
||||
var date = toDate(dirtyDate);
|
||||
var amount = toInteger(dirtyAmount);
|
||||
if (isNaN(amount)) return new Date(NaN);
|
||||
var hours = date.getHours();
|
||||
var sign = amount < 0 ? -1 : 1;
|
||||
date.setDate(date.getDate() + toInteger(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 || isWeekend(date)) {
|
||||
if (!isWeekend(date)) shiftSize -= 1;
|
||||
date.setDate(date.getDate() + sign);
|
||||
}
|
||||
|
||||
date.setHours(hours);
|
||||
return date;
|
||||
}
|
||||
+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
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
{
|
||||
"sideEffects": false,
|
||||
"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
|
||||
+35
@@ -0,0 +1,35 @@
|
||||
import toInteger from '../_lib/toInteger/index.js';
|
||||
import toDate from '../toDate/index.js';
|
||||
/**
|
||||
* @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
|
||||
*/
|
||||
|
||||
export default function addDays(dirtyDate, dirtyAmount) {
|
||||
if (arguments.length < 2) {
|
||||
throw new TypeError('2 arguments required, but only ' + arguments.length + ' present');
|
||||
}
|
||||
|
||||
var date = toDate(dirtyDate);
|
||||
var amount = toInteger(dirtyAmount);
|
||||
date.setDate(date.getDate() + amount);
|
||||
return date;
|
||||
}
|
||||
+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
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
{
|
||||
"sideEffects": false,
|
||||
"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
|
||||
+34
@@ -0,0 +1,34 @@
|
||||
import toInteger from '../_lib/toInteger/index.js';
|
||||
import addMilliseconds from '../addMilliseconds/index.js';
|
||||
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
|
||||
*/
|
||||
|
||||
export default function addHours(dirtyDate, dirtyAmount) {
|
||||
if (arguments.length < 2) {
|
||||
throw new TypeError('2 arguments required, but only ' + arguments.length + ' present');
|
||||
}
|
||||
|
||||
var amount = toInteger(dirtyAmount);
|
||||
return addMilliseconds(dirtyDate, amount * MILLISECONDS_IN_HOUR);
|
||||
}
|
||||
+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
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
{
|
||||
"sideEffects": false,
|
||||
"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
|
||||
+41
@@ -0,0 +1,41 @@
|
||||
import toInteger from '../_lib/toInteger/index.js';
|
||||
import getISOWeekYear from '../getISOWeekYear/index.js';
|
||||
import setISOWeekYear from '../setISOWeekYear/index.js';
|
||||
/**
|
||||
* @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
|
||||
*/
|
||||
|
||||
export default function addISOWeekYears(dirtyDate, dirtyAmount) {
|
||||
if (arguments.length < 2) {
|
||||
throw new TypeError('2 arguments required, but only ' + arguments.length + ' present');
|
||||
}
|
||||
|
||||
var amount = toInteger(dirtyAmount);
|
||||
return setISOWeekYear(dirtyDate, getISOWeekYear(dirtyDate) + amount);
|
||||
}
|
||||
+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
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
{
|
||||
"sideEffects": false,
|
||||
"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
|
||||
+34
@@ -0,0 +1,34 @@
|
||||
import toInteger from '../_lib/toInteger/index.js';
|
||||
import toDate from '../toDate/index.js';
|
||||
/**
|
||||
* @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
|
||||
*/
|
||||
|
||||
export default function addMilliseconds(dirtyDate, dirtyAmount) {
|
||||
if (arguments.length < 2) {
|
||||
throw new TypeError('2 arguments required, but only ' + arguments.length + ' present');
|
||||
}
|
||||
|
||||
var timestamp = toDate(dirtyDate).getTime();
|
||||
var amount = toInteger(dirtyAmount);
|
||||
return new Date(timestamp + amount);
|
||||
}
|
||||
+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
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
{
|
||||
"sideEffects": false,
|
||||
"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
|
||||
+34
@@ -0,0 +1,34 @@
|
||||
import toInteger from '../_lib/toInteger/index.js';
|
||||
import addMilliseconds from '../addMilliseconds/index.js';
|
||||
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
|
||||
*/
|
||||
|
||||
export default function addMinutes(dirtyDate, dirtyAmount) {
|
||||
if (arguments.length < 2) {
|
||||
throw new TypeError('2 arguments required, but only ' + arguments.length + ' present');
|
||||
}
|
||||
|
||||
var amount = toInteger(dirtyAmount);
|
||||
return addMilliseconds(dirtyDate, amount * MILLISECONDS_IN_MINUTE);
|
||||
}
|
||||
+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
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
{
|
||||
"sideEffects": false,
|
||||
"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
|
||||
+43
@@ -0,0 +1,43 @@
|
||||
import toInteger from '../_lib/toInteger/index.js';
|
||||
import toDate from '../toDate/index.js';
|
||||
import getDaysInMonth from '../getDaysInMonth/index.js';
|
||||
/**
|
||||
* @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
|
||||
*/
|
||||
|
||||
export default function addMonths(dirtyDate, dirtyAmount) {
|
||||
if (arguments.length < 2) {
|
||||
throw new TypeError('2 arguments required, but only ' + arguments.length + ' present');
|
||||
}
|
||||
|
||||
var date = toDate(dirtyDate);
|
||||
var amount = toInteger(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 = getDaysInMonth(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;
|
||||
}
|
||||
+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
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
{
|
||||
"sideEffects": false,
|
||||
"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
|
||||
+34
@@ -0,0 +1,34 @@
|
||||
import toInteger from '../_lib/toInteger/index.js';
|
||||
import addMonths from '../addMonths/index.js';
|
||||
/**
|
||||
* @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
|
||||
*/
|
||||
|
||||
export default function addQuarters(dirtyDate, dirtyAmount) {
|
||||
if (arguments.length < 2) {
|
||||
throw new TypeError('2 arguments required, but only ' + arguments.length + ' present');
|
||||
}
|
||||
|
||||
var amount = toInteger(dirtyAmount);
|
||||
var months = amount * 3;
|
||||
return addMonths(dirtyDate, months);
|
||||
}
|
||||
+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
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
{
|
||||
"sideEffects": false,
|
||||
"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
|
||||
+33
@@ -0,0 +1,33 @@
|
||||
import toInteger from '../_lib/toInteger/index.js';
|
||||
import addMilliseconds from '../addMilliseconds/index.js';
|
||||
/**
|
||||
* @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
|
||||
*/
|
||||
|
||||
export default function addSeconds(dirtyDate, dirtyAmount) {
|
||||
if (arguments.length < 2) {
|
||||
throw new TypeError('2 arguments required, but only ' + arguments.length + ' present');
|
||||
}
|
||||
|
||||
var amount = toInteger(dirtyAmount);
|
||||
return addMilliseconds(dirtyDate, amount * 1000);
|
||||
}
|
||||
+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
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
{
|
||||
"sideEffects": false,
|
||||
"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
|
||||
+34
@@ -0,0 +1,34 @@
|
||||
import toInteger from '../_lib/toInteger/index.js';
|
||||
import addDays from '../addDays/index.js';
|
||||
/**
|
||||
* @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
|
||||
*/
|
||||
|
||||
export default function addWeeks(dirtyDate, dirtyAmount) {
|
||||
if (arguments.length < 2) {
|
||||
throw new TypeError('2 arguments required, but only ' + arguments.length + ' present');
|
||||
}
|
||||
|
||||
var amount = toInteger(dirtyAmount);
|
||||
var days = amount * 7;
|
||||
return addDays(dirtyDate, days);
|
||||
}
|
||||
+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
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
{
|
||||
"sideEffects": false,
|
||||
"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
|
||||
+33
@@ -0,0 +1,33 @@
|
||||
import toInteger from '../_lib/toInteger/index.js';
|
||||
import addMonths from '../addMonths/index.js';
|
||||
/**
|
||||
* @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
|
||||
*/
|
||||
|
||||
export default function addYears(dirtyDate, dirtyAmount) {
|
||||
if (arguments.length < 2) {
|
||||
throw new TypeError('2 arguments required, but only ' + arguments.length + ' present');
|
||||
}
|
||||
|
||||
var amount = toInteger(dirtyAmount);
|
||||
return addMonths(dirtyDate, amount * 12);
|
||||
}
|
||||
+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
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
{
|
||||
"sideEffects": false,
|
||||
"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
|
||||
+93
@@ -0,0 +1,93 @@
|
||||
import toDate from '../toDate/index.js';
|
||||
/**
|
||||
* @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
|
||||
*/
|
||||
|
||||
export default 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 = toDate(intervalLeft.start).getTime();
|
||||
var leftEndTime = toDate(intervalLeft.end).getTime();
|
||||
var rightStartTime = toDate(intervalRight.start).getTime();
|
||||
var rightEndTime = toDate(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;
|
||||
}
|
||||
+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
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
{
|
||||
"sideEffects": false,
|
||||
"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
|
||||
+75
@@ -0,0 +1,75 @@
|
||||
import toDate from '../toDate/index.js';
|
||||
/**
|
||||
* @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
|
||||
*/
|
||||
|
||||
export default function closestIndexTo(dirtyDateToCompare, dirtyDatesArray) {
|
||||
if (arguments.length < 2) {
|
||||
throw new TypeError('2 arguments required, but only ' + arguments.length + ' present');
|
||||
}
|
||||
|
||||
var dateToCompare = toDate(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 = toDate(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;
|
||||
}
|
||||
+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
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
{
|
||||
"sideEffects": false,
|
||||
"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
|
||||
+73
@@ -0,0 +1,73 @@
|
||||
import toDate from '../toDate/index.js';
|
||||
/**
|
||||
* @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
|
||||
*/
|
||||
|
||||
export default function closestTo(dirtyDateToCompare, dirtyDatesArray) {
|
||||
if (arguments.length < 2) {
|
||||
throw new TypeError('2 arguments required, but only ' + arguments.length + ' present');
|
||||
}
|
||||
|
||||
var dateToCompare = toDate(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 = toDate(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;
|
||||
}
|
||||
+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
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
{
|
||||
"sideEffects": false,
|
||||
"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
|
||||
+55
@@ -0,0 +1,55 @@
|
||||
import toDate from '../toDate/index.js';
|
||||
/**
|
||||
* @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
|
||||
* // ]
|
||||
*/
|
||||
|
||||
export default function compareAsc(dirtyDateLeft, dirtyDateRight) {
|
||||
if (arguments.length < 2) {
|
||||
throw new TypeError('2 arguments required, but only ' + arguments.length + ' present');
|
||||
}
|
||||
|
||||
var dateLeft = toDate(dirtyDateLeft);
|
||||
var dateRight = toDate(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;
|
||||
}
|
||||
}
|
||||
+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
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
{
|
||||
"sideEffects": false,
|
||||
"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
|
||||
+55
@@ -0,0 +1,55 @@
|
||||
import toDate from '../toDate/index.js';
|
||||
/**
|
||||
* @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
|
||||
* // ]
|
||||
*/
|
||||
|
||||
export default function compareDesc(dirtyDateLeft, dirtyDateRight) {
|
||||
if (arguments.length < 2) {
|
||||
throw new TypeError('2 arguments required, but only ' + arguments.length + ' present');
|
||||
}
|
||||
|
||||
var dateLeft = toDate(dirtyDateLeft);
|
||||
var dateRight = toDate(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;
|
||||
}
|
||||
}
|
||||
+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
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
{
|
||||
"sideEffects": false,
|
||||
"typings": "../../typings.d.ts"
|
||||
}
|
||||
+2
@@ -0,0 +1,2 @@
|
||||
export const maxTime: number
|
||||
export const minTime: number
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
/**
|
||||
* Maximum allowed time.
|
||||
* @constant
|
||||
* @type {number}
|
||||
* @default
|
||||
*/
|
||||
export var maxTime = Math.pow(10, 8) * 24 * 60 * 60 * 1000;
|
||||
/**
|
||||
* Minimum allowed time.
|
||||
* @constant
|
||||
* @type {number}
|
||||
* @default
|
||||
*/
|
||||
|
||||
export var minTime = -maxTime;
|
||||
+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
|
||||
+55
@@ -0,0 +1,55 @@
|
||||
import isValid from '../isValid/index.js';
|
||||
import isWeekend from '../isWeekend/index.js';
|
||||
import toDate from '../toDate/index.js';
|
||||
import differenceInCalendarDays from '../differenceInCalendarDays/index.js';
|
||||
import addDays from '../addDays/index.js';
|
||||
import isSameDay from '../isSameDay/index.js';
|
||||
import toInteger from '../_lib/toInteger/index.js';
|
||||
/**
|
||||
* @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
|
||||
*/
|
||||
|
||||
export default function differenceInBusinessDays(dirtyDateLeft, dirtyDateRight) {
|
||||
if (arguments.length < 2) {
|
||||
throw new TypeError('2 arguments required, but only ' + arguments.length + ' present');
|
||||
}
|
||||
|
||||
var dateLeft = toDate(dirtyDateLeft);
|
||||
var dateRight = toDate(dirtyDateRight);
|
||||
if (!isValid(dateLeft) || !isValid(dateRight)) return new Date(NaN);
|
||||
var calendarDifference = differenceInCalendarDays(dateLeft, dateRight);
|
||||
var sign = calendarDifference < 0 ? -1 : 1;
|
||||
var weeks = toInteger(calendarDifference / 7);
|
||||
var result = weeks * 5;
|
||||
dateRight = addDays(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 (!isSameDay(dateLeft, dateRight)) {
|
||||
// sign is used to account for both negative and positive differences
|
||||
result += isWeekend(dateRight) ? 0 : sign;
|
||||
dateRight = addDays(dateRight, sign);
|
||||
}
|
||||
|
||||
return result === 0 ? 0 : result;
|
||||
}
|
||||
+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
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
{
|
||||
"sideEffects": false,
|
||||
"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
|
||||
+52
@@ -0,0 +1,52 @@
|
||||
import getTimezoneOffsetInMilliseconds from '../_lib/getTimezoneOffsetInMilliseconds/index.js';
|
||||
import startOfDay from '../startOfDay/index.js';
|
||||
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
|
||||
*/
|
||||
|
||||
export default function differenceInCalendarDays(dirtyDateLeft, dirtyDateRight) {
|
||||
if (arguments.length < 2) {
|
||||
throw new TypeError('2 arguments required, but only ' + arguments.length + ' present');
|
||||
}
|
||||
|
||||
var startOfDayLeft = startOfDay(dirtyDateLeft);
|
||||
var startOfDayRight = startOfDay(dirtyDateRight);
|
||||
var timestampLeft = startOfDayLeft.getTime() - getTimezoneOffsetInMilliseconds(startOfDayLeft);
|
||||
var timestampRight = startOfDayRight.getTime() - getTimezoneOffsetInMilliseconds(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);
|
||||
}
|
||||
+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
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
{
|
||||
"sideEffects": false,
|
||||
"typings": "../../typings.d.ts"
|
||||
}
|
||||
Generated
Vendored
+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
|
||||
Generated
Vendored
+41
@@ -0,0 +1,41 @@
|
||||
import getISOWeekYear from '../getISOWeekYear/index.js';
|
||||
/**
|
||||
* @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
|
||||
*/
|
||||
|
||||
export default function differenceInCalendarISOWeekYears(dirtyDateLeft, dirtyDateRight) {
|
||||
if (arguments.length < 2) {
|
||||
throw new TypeError('2 arguments required, but only ' + arguments.length + ' present');
|
||||
}
|
||||
|
||||
return getISOWeekYear(dirtyDateLeft) - getISOWeekYear(dirtyDateRight);
|
||||
}
|
||||
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
+4
@@ -0,0 +1,4 @@
|
||||
{
|
||||
"sideEffects": false,
|
||||
"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
|
||||
+45
@@ -0,0 +1,45 @@
|
||||
import getTimezoneOffsetInMilliseconds from '../_lib/getTimezoneOffsetInMilliseconds/index.js';
|
||||
import startOfISOWeek from '../startOfISOWeek/index.js';
|
||||
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
|
||||
*/
|
||||
|
||||
export default function differenceInCalendarISOWeeks(dirtyDateLeft, dirtyDateRight) {
|
||||
if (arguments.length < 2) {
|
||||
throw new TypeError('2 arguments required, but only ' + arguments.length + ' present');
|
||||
}
|
||||
|
||||
var startOfISOWeekLeft = startOfISOWeek(dirtyDateLeft);
|
||||
var startOfISOWeekRight = startOfISOWeek(dirtyDateRight);
|
||||
var timestampLeft = startOfISOWeekLeft.getTime() - getTimezoneOffsetInMilliseconds(startOfISOWeekLeft);
|
||||
var timestampRight = startOfISOWeekRight.getTime() - getTimezoneOffsetInMilliseconds(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);
|
||||
}
|
||||
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
+4
@@ -0,0 +1,4 @@
|
||||
{
|
||||
"sideEffects": false,
|
||||
"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
|
||||
+38
@@ -0,0 +1,38 @@
|
||||
import toDate from '../toDate/index.js';
|
||||
/**
|
||||
* @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
|
||||
*/
|
||||
|
||||
export default function differenceInCalendarMonths(dirtyDateLeft, dirtyDateRight) {
|
||||
if (arguments.length < 2) {
|
||||
throw new TypeError('2 arguments required, but only ' + arguments.length + ' present');
|
||||
}
|
||||
|
||||
var dateLeft = toDate(dirtyDateLeft);
|
||||
var dateRight = toDate(dirtyDateRight);
|
||||
var yearDiff = dateLeft.getFullYear() - dateRight.getFullYear();
|
||||
var monthDiff = dateLeft.getMonth() - dateRight.getMonth();
|
||||
return yearDiff * 12 + monthDiff;
|
||||
}
|
||||
+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
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
{
|
||||
"sideEffects": false,
|
||||
"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
|
||||
+39
@@ -0,0 +1,39 @@
|
||||
import getQuarter from '../getQuarter/index.js';
|
||||
import toDate from '../toDate/index.js';
|
||||
/**
|
||||
* @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
|
||||
*/
|
||||
|
||||
export default function differenceInCalendarQuarters(dirtyDateLeft, dirtyDateRight) {
|
||||
if (arguments.length < 2) {
|
||||
throw new TypeError('2 arguments required, but only ' + arguments.length + ' present');
|
||||
}
|
||||
|
||||
var dateLeft = toDate(dirtyDateLeft);
|
||||
var dateRight = toDate(dirtyDateRight);
|
||||
var yearDiff = dateLeft.getFullYear() - dateRight.getFullYear();
|
||||
var quarterDiff = getQuarter(dateLeft) - getQuarter(dateRight);
|
||||
return yearDiff * 4 + quarterDiff;
|
||||
}
|
||||
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
+4
@@ -0,0 +1,4 @@
|
||||
{
|
||||
"sideEffects": false,
|
||||
"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
|
||||
+57
@@ -0,0 +1,57 @@
|
||||
import startOfWeek from '../startOfWeek/index.js';
|
||||
import getTimezoneOffsetInMilliseconds from '../_lib/getTimezoneOffsetInMilliseconds/index.js';
|
||||
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
|
||||
*/
|
||||
|
||||
export default function differenceInCalendarWeeks(dirtyDateLeft, dirtyDateRight, dirtyOptions) {
|
||||
if (arguments.length < 2) {
|
||||
throw new TypeError('2 arguments required, but only ' + arguments.length + ' present');
|
||||
}
|
||||
|
||||
var startOfWeekLeft = startOfWeek(dirtyDateLeft, dirtyOptions);
|
||||
var startOfWeekRight = startOfWeek(dirtyDateRight, dirtyOptions);
|
||||
var timestampLeft = startOfWeekLeft.getTime() - getTimezoneOffsetInMilliseconds(startOfWeekLeft);
|
||||
var timestampRight = startOfWeekRight.getTime() - getTimezoneOffsetInMilliseconds(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);
|
||||
}
|
||||
+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
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
{
|
||||
"sideEffects": false,
|
||||
"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
|
||||
+36
@@ -0,0 +1,36 @@
|
||||
import toDate from '../toDate/index.js';
|
||||
/**
|
||||
* @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
|
||||
*/
|
||||
|
||||
export default function differenceInCalendarYears(dirtyDateLeft, dirtyDateRight) {
|
||||
if (arguments.length < 2) {
|
||||
throw new TypeError('2 arguments required, but only ' + arguments.length + ' present');
|
||||
}
|
||||
|
||||
var dateLeft = toDate(dirtyDateLeft);
|
||||
var dateRight = toDate(dirtyDateRight);
|
||||
return dateLeft.getFullYear() - dateRight.getFullYear();
|
||||
}
|
||||
+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
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
{
|
||||
"sideEffects": false,
|
||||
"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
|
||||
+54
@@ -0,0 +1,54 @@
|
||||
import toDate from '../toDate/index.js';
|
||||
import differenceInCalendarDays from '../differenceInCalendarDays/index.js';
|
||||
import compareAsc from '../compareAsc/index.js';
|
||||
/**
|
||||
* @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
|
||||
*/
|
||||
|
||||
export default function differenceInDays(dirtyDateLeft, dirtyDateRight) {
|
||||
if (arguments.length < 2) {
|
||||
throw new TypeError('2 arguments required, but only ' + arguments.length + ' present');
|
||||
}
|
||||
|
||||
var dateLeft = toDate(dirtyDateLeft);
|
||||
var dateRight = toDate(dirtyDateRight);
|
||||
var sign = compareAsc(dateLeft, dateRight);
|
||||
var difference = Math.abs(differenceInCalendarDays(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 = compareAsc(dateLeft, dateRight) === -sign;
|
||||
var result = sign * (difference - isLastDayNotFull); // Prevent negative zero
|
||||
|
||||
return result === 0 ? 0 : result;
|
||||
}
|
||||
+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
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
{
|
||||
"sideEffects": false,
|
||||
"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
|
||||
+36
@@ -0,0 +1,36 @@
|
||||
import differenceInMilliseconds from '../differenceInMilliseconds/index.js';
|
||||
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
|
||||
*/
|
||||
|
||||
export default function differenceInHours(dirtyDateLeft, dirtyDateRight) {
|
||||
if (arguments.length < 2) {
|
||||
throw new TypeError('2 arguments required, but only ' + arguments.length + ' present');
|
||||
}
|
||||
|
||||
var diff = differenceInMilliseconds(dirtyDateLeft, dirtyDateRight) / MILLISECONDS_IN_HOUR;
|
||||
return diff > 0 ? Math.floor(diff) : Math.ceil(diff);
|
||||
}
|
||||
+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
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
{
|
||||
"sideEffects": false,
|
||||
"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
|
||||
+55
@@ -0,0 +1,55 @@
|
||||
import toDate from '../toDate/index.js';
|
||||
import differenceInCalendarISOWeekYears from '../differenceInCalendarISOWeekYears/index.js';
|
||||
import compareAsc from '../compareAsc/index.js';
|
||||
import subISOWeekYears from '../subISOWeekYears/index.js';
|
||||
/**
|
||||
* @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
|
||||
*/
|
||||
|
||||
export default function differenceInISOWeekYears(dirtyDateLeft, dirtyDateRight) {
|
||||
if (arguments.length < 2) {
|
||||
throw new TypeError('2 arguments required, but only ' + arguments.length + ' present');
|
||||
}
|
||||
|
||||
var dateLeft = toDate(dirtyDateLeft);
|
||||
var dateRight = toDate(dirtyDateRight);
|
||||
var sign = compareAsc(dateLeft, dateRight);
|
||||
var difference = Math.abs(differenceInCalendarISOWeekYears(dateLeft, dateRight));
|
||||
dateLeft = subISOWeekYears(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 = compareAsc(dateLeft, dateRight) === -sign;
|
||||
var result = sign * (difference - isLastISOWeekYearNotFull); // Prevent negative zero
|
||||
|
||||
return result === 0 ? 0 : result;
|
||||
}
|
||||
+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
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
{
|
||||
"sideEffects": false,
|
||||
"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
|
||||
+37
@@ -0,0 +1,37 @@
|
||||
import toDate from '../toDate/index.js';
|
||||
/**
|
||||
* @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
|
||||
*/
|
||||
|
||||
export default function differenceInMilliseconds(dirtyDateLeft, dirtyDateRight) {
|
||||
if (arguments.length < 2) {
|
||||
throw new TypeError('2 arguments required, but only ' + arguments.length + ' present');
|
||||
}
|
||||
|
||||
var dateLeft = toDate(dirtyDateLeft);
|
||||
var dateRight = toDate(dirtyDateRight);
|
||||
return dateLeft.getTime() - dateRight.getTime();
|
||||
}
|
||||
+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
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
{
|
||||
"sideEffects": false,
|
||||
"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
|
||||
+44
@@ -0,0 +1,44 @@
|
||||
import differenceInMilliseconds from '../differenceInMilliseconds/index.js';
|
||||
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
|
||||
*/
|
||||
|
||||
export default function differenceInMinutes(dirtyDateLeft, dirtyDateRight) {
|
||||
if (arguments.length < 2) {
|
||||
throw new TypeError('2 arguments required, but only ' + arguments.length + ' present');
|
||||
}
|
||||
|
||||
var diff = differenceInMilliseconds(dirtyDateLeft, dirtyDateRight) / MILLISECONDS_IN_MINUTE;
|
||||
return diff > 0 ? Math.floor(diff) : Math.ceil(diff);
|
||||
}
|
||||
+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
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
{
|
||||
"sideEffects": false,
|
||||
"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
|
||||
+43
@@ -0,0 +1,43 @@
|
||||
import toDate from '../toDate/index.js';
|
||||
import differenceInCalendarMonths from '../differenceInCalendarMonths/index.js';
|
||||
import compareAsc from '../compareAsc/index.js';
|
||||
/**
|
||||
* @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
|
||||
*/
|
||||
|
||||
export default function differenceInMonths(dirtyDateLeft, dirtyDateRight) {
|
||||
if (arguments.length < 2) {
|
||||
throw new TypeError('2 arguments required, but only ' + arguments.length + ' present');
|
||||
}
|
||||
|
||||
var dateLeft = toDate(dirtyDateLeft);
|
||||
var dateRight = toDate(dirtyDateRight);
|
||||
var sign = compareAsc(dateLeft, dateRight);
|
||||
var difference = Math.abs(differenceInCalendarMonths(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 = compareAsc(dateLeft, dateRight) === -sign;
|
||||
var result = sign * (difference - isLastMonthNotFull); // Prevent negative zero
|
||||
|
||||
return result === 0 ? 0 : result;
|
||||
}
|
||||
+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
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
{
|
||||
"sideEffects": false,
|
||||
"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
|
||||
+32
@@ -0,0 +1,32 @@
|
||||
import differenceInMonths from '../differenceInMonths/index.js';
|
||||
/**
|
||||
* @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
|
||||
*/
|
||||
|
||||
export default function differenceInQuarters(dirtyDateLeft, dirtyDateRight) {
|
||||
if (arguments.length < 2) {
|
||||
throw new TypeError('2 arguments required, but only ' + arguments.length + ' present');
|
||||
}
|
||||
|
||||
var diff = differenceInMonths(dirtyDateLeft, dirtyDateRight) / 3;
|
||||
return diff > 0 ? Math.floor(diff) : Math.ceil(diff);
|
||||
}
|
||||
+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
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
{
|
||||
"sideEffects": false,
|
||||
"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
|
||||
+36
@@ -0,0 +1,36 @@
|
||||
import differenceInMilliseconds from '../differenceInMilliseconds/index.js';
|
||||
/**
|
||||
* @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
|
||||
*/
|
||||
|
||||
export default function differenceInSeconds(dirtyDateLeft, dirtyDateRight) {
|
||||
if (arguments.length < 2) {
|
||||
throw new TypeError('2 arguments required, but only ' + arguments.length + ' present');
|
||||
}
|
||||
|
||||
var diff = differenceInMilliseconds(dirtyDateLeft, dirtyDateRight) / 1000;
|
||||
return diff > 0 ? Math.floor(diff) : Math.ceil(diff);
|
||||
}
|
||||
+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
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
{
|
||||
"sideEffects": false,
|
||||
"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
|
||||
+32
@@ -0,0 +1,32 @@
|
||||
import differenceInDays from '../differenceInDays/index.js';
|
||||
/**
|
||||
* @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
|
||||
*/
|
||||
|
||||
export default function differenceInWeeks(dirtyDateLeft, dirtyDateRight) {
|
||||
if (arguments.length < 2) {
|
||||
throw new TypeError('2 arguments required, but only ' + arguments.length + ' present');
|
||||
}
|
||||
|
||||
var diff = differenceInDays(dirtyDateLeft, dirtyDateRight) / 7;
|
||||
return diff > 0 ? Math.floor(diff) : Math.ceil(diff);
|
||||
}
|
||||
+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
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
{
|
||||
"sideEffects": false,
|
||||
"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
|
||||
+43
@@ -0,0 +1,43 @@
|
||||
import toDate from '../toDate/index.js';
|
||||
import differenceInCalendarYears from '../differenceInCalendarYears/index.js';
|
||||
import compareAsc from '../compareAsc/index.js';
|
||||
/**
|
||||
* @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
|
||||
*/
|
||||
|
||||
export default function differenceInYears(dirtyDateLeft, dirtyDateRight) {
|
||||
if (arguments.length < 2) {
|
||||
throw new TypeError('2 arguments required, but only ' + arguments.length + ' present');
|
||||
}
|
||||
|
||||
var dateLeft = toDate(dirtyDateLeft);
|
||||
var dateRight = toDate(dirtyDateRight);
|
||||
var sign = compareAsc(dateLeft, dateRight);
|
||||
var difference = Math.abs(differenceInCalendarYears(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 = compareAsc(dateLeft, dateRight) === -sign;
|
||||
var result = sign * (difference - isLastYearNotFull); // Prevent negative zero
|
||||
|
||||
return result === 0 ? 0 : result;
|
||||
}
|
||||
+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
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
{
|
||||
"sideEffects": false,
|
||||
"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 { eachDayOfInterval } from 'date-fns'
|
||||
export default eachDayOfInterval
|
||||
+91
@@ -0,0 +1,91 @@
|
||||
import toDate from '../toDate/index.js';
|
||||
/**
|
||||
* @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
|
||||
* // ]
|
||||
*/
|
||||
|
||||
export default function eachDayOfInterval(dirtyInterval, options) {
|
||||
if (arguments.length < 1) {
|
||||
throw new TypeError('1 argument required, but only ' + arguments.length + ' present');
|
||||
}
|
||||
|
||||
var interval = dirtyInterval || {};
|
||||
var startDate = toDate(interval.start);
|
||||
var endDate = toDate(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(toDate(currentDate));
|
||||
currentDate.setDate(currentDate.getDate() + step);
|
||||
currentDate.setHours(0, 0, 0, 0);
|
||||
}
|
||||
|
||||
return dates;
|
||||
}
|
||||
+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[]
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
{
|
||||
"sideEffects": false,
|
||||
"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
|
||||
+75
@@ -0,0 +1,75 @@
|
||||
import addWeeks from '../addWeeks/index.js';
|
||||
import startOfWeek from '../startOfWeek/index.js';
|
||||
import toDate from '../toDate/index.js';
|
||||
/**
|
||||
* @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
|
||||
* // ]
|
||||
*/
|
||||
|
||||
export default function eachWeekOfInterval(dirtyInterval, options) {
|
||||
if (arguments.length < 1) {
|
||||
throw new TypeError('1 argument required, but only ' + arguments.length + ' present');
|
||||
}
|
||||
|
||||
var interval = dirtyInterval || {};
|
||||
var startDate = toDate(interval.start);
|
||||
var endDate = toDate(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 = startOfWeek(startDate, options);
|
||||
var endDateWeek = startOfWeek(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(toDate(currentWeek));
|
||||
currentWeek = addWeeks(currentWeek, 1);
|
||||
currentWeek.setHours(15);
|
||||
}
|
||||
|
||||
return weeks;
|
||||
}
|
||||
+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[]
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
{
|
||||
"sideEffects": false,
|
||||
"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
|
||||
+51
@@ -0,0 +1,51 @@
|
||||
import eachDayOfInterval from '../eachDayOfInterval/index.js';
|
||||
import isSunday from '../isSunday/index.js';
|
||||
import isWeekend from '../isWeekend/index.js';
|
||||
/**
|
||||
* @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
|
||||
* // ]
|
||||
*/
|
||||
|
||||
export default function eachWeekendOfInterval(interval) {
|
||||
if (arguments.length < 1) {
|
||||
throw new TypeError('1 argument required, but only ' + arguments.length + ' present');
|
||||
}
|
||||
|
||||
var dateInterval = eachDayOfInterval(interval);
|
||||
var weekends = [];
|
||||
var index = 0;
|
||||
|
||||
while (index < dateInterval.length) {
|
||||
var date = dateInterval[index++];
|
||||
|
||||
if (isWeekend(date)) {
|
||||
weekends.push(date);
|
||||
if (isSunday(date)) index = index + 5;
|
||||
}
|
||||
}
|
||||
|
||||
return weekends;
|
||||
}
|
||||
+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[]
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
{
|
||||
"sideEffects": false,
|
||||
"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
|
||||
+44
@@ -0,0 +1,44 @@
|
||||
import eachWeekendOfInterval from '../eachWeekendOfInterval/index.js';
|
||||
import startOfMonth from '../startOfMonth/index.js';
|
||||
import endOfMonth from '../endOfMonth/index.js';
|
||||
/**
|
||||
* @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
|
||||
* // ]
|
||||
*/
|
||||
|
||||
export default function eachWeekendOfMonth(dirtyDate) {
|
||||
if (arguments.length < 1) {
|
||||
throw new TypeError('1 arguments required, but only ' + arguments.length + ' present');
|
||||
}
|
||||
|
||||
var startDate = startOfMonth(dirtyDate);
|
||||
if (isNaN(startDate)) throw new RangeError('The passed date is invalid');
|
||||
var endDate = endOfMonth(dirtyDate);
|
||||
return eachWeekendOfInterval({
|
||||
start: startDate,
|
||||
end: endDate
|
||||
});
|
||||
}
|
||||
+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[]
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
{
|
||||
"sideEffects": false,
|
||||
"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
|
||||
+41
@@ -0,0 +1,41 @@
|
||||
import eachWeekendOfInterval from '../eachWeekendOfInterval/index.js';
|
||||
import startOfYear from '../startOfYear/index.js';
|
||||
import endOfYear from '../endOfYear/index.js';
|
||||
/**
|
||||
* @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
|
||||
* // ]
|
||||
* ]
|
||||
*/
|
||||
|
||||
export default function eachWeekendOfYear(dirtyDate) {
|
||||
if (arguments.length < 1) {
|
||||
throw new TypeError('1 arguments required, but only ' + arguments.length + ' present');
|
||||
}
|
||||
|
||||
var startDate = startOfYear(dirtyDate);
|
||||
if (isNaN(startDate)) throw new RangeError('The passed date is invalid');
|
||||
var endDate = endOfYear(dirtyDate);
|
||||
return eachWeekendOfInterval({
|
||||
start: startDate,
|
||||
end: endDate
|
||||
});
|
||||
}
|
||||
+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[]
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
{
|
||||
"sideEffects": false,
|
||||
"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 { endOfDay } from 'date-fns'
|
||||
export default endOfDay
|
||||
+33
@@ -0,0 +1,33 @@
|
||||
import toDate from '../toDate/index.js';
|
||||
/**
|
||||
* @name endOfDay
|
||||
* @category Day Helpers
|
||||
* @summary Return the end of a day for the given date.
|
||||
*
|
||||
* @description
|
||||
* Return the end of a day for the given date.
|
||||
* The result will be in the local timezone.
|
||||
*
|
||||
* ### 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 original date
|
||||
* @returns {Date} the end of a day
|
||||
* @throws {TypeError} 1 argument required
|
||||
*
|
||||
* @example
|
||||
* // The end of a day for 2 September 2014 11:55:00:
|
||||
* var result = endOfDay(new Date(2014, 8, 2, 11, 55, 0))
|
||||
* //=> Tue Sep 02 2014 23:59:59.999
|
||||
*/
|
||||
|
||||
export default function endOfDay(dirtyDate) {
|
||||
if (arguments.length < 1) {
|
||||
throw new TypeError('1 argument required, but only ' + arguments.length + ' present');
|
||||
}
|
||||
|
||||
var date = toDate(dirtyDate);
|
||||
date.setHours(23, 59, 59, 999);
|
||||
return date;
|
||||
}
|
||||
+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
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
{
|
||||
"sideEffects": false,
|
||||
"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 { endOfDecade } from 'date-fns'
|
||||
export default endOfDecade
|
||||
+38
@@ -0,0 +1,38 @@
|
||||
import toDate from '../toDate/index.js';
|
||||
/**
|
||||
* @name endOfDecade
|
||||
* @category Decade Helpers
|
||||
* @summary Return the end of a decade for the given date.
|
||||
*
|
||||
* @description
|
||||
* Return the end of a decade for 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 original date
|
||||
* @returns {Date} the end of a decade
|
||||
* @param {Object} [options] - an object with options.
|
||||
* @param {0|1|2} [options.additionalDigits=2] - passed to `toDate`. See [toDate]{@link https://date-fns.org/docs/toDate}
|
||||
* @throws {TypeError} 1 argument required
|
||||
* @throws {RangeError} `options.additionalDigits` must be 0, 1 or 2
|
||||
*
|
||||
* @example
|
||||
* // The end of a decade for 12 May 1984 00:00:00:
|
||||
* var result = endOfDecade(new Date(1984, 4, 12, 00, 00, 00))
|
||||
* //=> Dec 31 1989 23:59:59.999
|
||||
*/
|
||||
|
||||
export default function endOfDecade(dirtyDate) {
|
||||
if (arguments.length < 1) {
|
||||
throw new TypeError('1 argument required, but only ' + arguments.length + ' present');
|
||||
}
|
||||
|
||||
var date = toDate(dirtyDate);
|
||||
var year = date.getFullYear();
|
||||
var decade = 9 + Math.floor(year / 10) * 10;
|
||||
date.setFullYear(decade, 11, 31);
|
||||
date.setHours(23, 59, 59, 999);
|
||||
return date;
|
||||
}
|
||||
+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: (
|
||||
date: Date | number,
|
||||
options?: {
|
||||
additionalDigits?: 0 | 1 | 2
|
||||
}
|
||||
) => Date
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
{
|
||||
"sideEffects": false,
|
||||
"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 { endOfHour } from 'date-fns'
|
||||
export default endOfHour
|
||||
+33
@@ -0,0 +1,33 @@
|
||||
import toDate from '../toDate/index.js';
|
||||
/**
|
||||
* @name endOfHour
|
||||
* @category Hour Helpers
|
||||
* @summary Return the end of an hour for the given date.
|
||||
*
|
||||
* @description
|
||||
* Return the end of an hour for the given date.
|
||||
* The result will be in the local timezone.
|
||||
*
|
||||
* ### 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 original date
|
||||
* @returns {Date} the end of an hour
|
||||
* @throws {TypeError} 1 argument required
|
||||
*
|
||||
* @example
|
||||
* // The end of an hour for 2 September 2014 11:55:00:
|
||||
* var result = endOfHour(new Date(2014, 8, 2, 11, 55))
|
||||
* //=> Tue Sep 02 2014 11:59:59.999
|
||||
*/
|
||||
|
||||
export default function endOfHour(dirtyDate) {
|
||||
if (arguments.length < 1) {
|
||||
throw new TypeError('1 argument required, but only ' + arguments.length + ' present');
|
||||
}
|
||||
|
||||
var date = toDate(dirtyDate);
|
||||
date.setMinutes(59, 59, 999);
|
||||
return date;
|
||||
}
|
||||
+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
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
{
|
||||
"sideEffects": false,
|
||||
"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 { endOfISOWeek } from 'date-fns'
|
||||
export default endOfISOWeek
|
||||
+35
@@ -0,0 +1,35 @@
|
||||
import endOfWeek from '../endOfWeek/index.js';
|
||||
/**
|
||||
* @name endOfISOWeek
|
||||
* @category ISO Week Helpers
|
||||
* @summary Return the end of an ISO week for the given date.
|
||||
*
|
||||
* @description
|
||||
* Return the end of an ISO week for the given date.
|
||||
* The result will be in the local timezone.
|
||||
*
|
||||
* 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} date - the original date
|
||||
* @returns {Date} the end of an ISO week
|
||||
* @throws {TypeError} 1 argument required
|
||||
*
|
||||
* @example
|
||||
* // The end of an ISO week for 2 September 2014 11:55:00:
|
||||
* var result = endOfISOWeek(new Date(2014, 8, 2, 11, 55, 0))
|
||||
* //=> Sun Sep 07 2014 23:59:59.999
|
||||
*/
|
||||
|
||||
export default function endOfISOWeek(dirtyDate) {
|
||||
if (arguments.length < 1) {
|
||||
throw new TypeError('1 argument required, but only ' + arguments.length + ' present');
|
||||
}
|
||||
|
||||
return endOfWeek(dirtyDate, {
|
||||
weekStartsOn: 1
|
||||
});
|
||||
}
|
||||
+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
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
{
|
||||
"sideEffects": false,
|
||||
"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 { endOfISOWeekYear } from 'date-fns'
|
||||
export default endOfISOWeekYear
|
||||
+46
@@ -0,0 +1,46 @@
|
||||
import getISOWeekYear from '../getISOWeekYear/index.js';
|
||||
import startOfISOWeek from '../startOfISOWeek/index.js';
|
||||
/**
|
||||
* @name endOfISOWeekYear
|
||||
* @category ISO Week-Numbering Year Helpers
|
||||
* @summary Return the end of an ISO week-numbering year for the given date.
|
||||
*
|
||||
* @description
|
||||
* Return the end of an ISO week-numbering year,
|
||||
* which always starts 3 days before the year's first Thursday.
|
||||
* The result will be in the local timezone.
|
||||
*
|
||||
* 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 `endOfISOYear` to `endOfISOWeekYear`.
|
||||
* "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 original date
|
||||
* @returns {Date} the end of an ISO week-numbering year
|
||||
* @throws {TypeError} 1 argument required
|
||||
*
|
||||
* @example
|
||||
* // The end of an ISO week-numbering year for 2 July 2005:
|
||||
* var result = endOfISOWeekYear(new Date(2005, 6, 2))
|
||||
* //=> Sun Jan 01 2006 23:59:59.999
|
||||
*/
|
||||
|
||||
export default function endOfISOWeekYear(dirtyDate) {
|
||||
if (arguments.length < 1) {
|
||||
throw new TypeError('1 argument required, but only ' + arguments.length + ' present');
|
||||
}
|
||||
|
||||
var year = getISOWeekYear(dirtyDate);
|
||||
var fourthOfJanuaryOfNextYear = new Date(0);
|
||||
fourthOfJanuaryOfNextYear.setFullYear(year + 1, 0, 4);
|
||||
fourthOfJanuaryOfNextYear.setHours(0, 0, 0, 0);
|
||||
var date = startOfISOWeek(fourthOfJanuaryOfNextYear);
|
||||
date.setMilliseconds(date.getMilliseconds() - 1);
|
||||
return date;
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user