@fr0st/datetime 6.1.1 → 8.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Formats.md +454 -0
- package/LICENSE +0 -0
- package/README.md +407 -1868
- package/dist/frost-datetime.js +2526 -2376
- package/dist/frost-datetime.js.map +1 -1
- package/dist/frost-datetime.min.js +2 -1
- package/dist/frost-datetime.min.js.map +1 -1
- package/package.json +32 -19
- package/src/date-time.js +2094 -90
- package/src/factory.js +29 -19
- package/src/formatter/format.js +38 -29
- package/src/formatter/locale.js +80 -0
- package/src/formatter/locales.js +2 -2
- package/src/formatter/parse.js +26 -12
- package/src/formatter/tokens.js +113 -123
- package/src/formatter/utility.js +38 -64
- package/src/formatter/values.js +26 -22
- package/src/helpers.js +178 -52
- package/src/index.js +1 -186
- package/src/vars.js +4 -4
- package/src/prototype/attributes-get.js +0 -163
- package/src/prototype/attributes-set.js +0 -281
- package/src/prototype/comparisons.js +0 -605
- package/src/prototype/manipulate.js +0 -395
- package/src/prototype/output.js +0 -89
- package/src/prototype/utility.js +0 -127
- package/src/static/create.js +0 -222
- package/src/static/utility.js +0 -103
package/src/index.js
CHANGED
|
@@ -1,186 +1 @@
|
|
|
1
|
-
|
|
2
|
-
import { fromArray, fromDate, fromFormat, fromISOString, fromTimestamp, now } from './static/create.js';
|
|
3
|
-
import { dayOfYear, daysInMonth as _daysInMonth, daysInYear as _daysInYear, getDefaultLocale, getDefaultTimeZone, isLeapYear as _isLeapYear, setDateClamping, setDefaultLocale, setDefaultTimeZone } from './static/utility.js';
|
|
4
|
-
import { getDate, getDay, getDayOfYear, getHours, getMilliseconds, getMinutes, getMonth, getQuarter, getSeconds, getTimestamp, getWeek, getWeekDay, getWeekDayInMonth, getWeekOfMonth, getWeekYear, getYear } from './prototype/attributes-get.js';
|
|
5
|
-
import { setDate, setDay, setDayOfYear, setHours, setMilliseconds, setMinutes, setMonth, setQuarter, setSeconds, setTimestamp, setWeek, setWeekDay, setWeekDayInMonth, setWeekOfMonth, setWeekYear, setYear } from './prototype/attributes-set.js';
|
|
6
|
-
import { diff, diffInDays, diffInHours, diffInMinutes, diffInMonths, diffInSeconds, diffInWeeks, diffInYears, humanDiff, humanDiffInDays, humanDiffInHours, humanDiffInMinutes, humanDiffInMonths, humanDiffInSeconds, humanDiffInWeeks, humanDiffInYears, isAfter, isAfterDay, isAfterHour, isAfterMinute, isAfterMonth, isAfterSecond, isAfterWeek, isAfterYear, isBefore, isBeforeDay, isBeforeHour, isBeforeMinute, isBeforeMonth, isBeforeSecond, isBeforeWeek, isBeforeYear, isBetween, isBetweenDay, isBetweenHour, isBetweenMinute, isBetweenMonth, isBetweenSecond, isBetweenWeek, isBetweenYear, isSame, isSameDay, isSameHour, isSameMinute, isSameMonth, isSameSecond, isSameWeek, isSameYear, isSameOrAfter, isSameOrAfterDay, isSameOrAfterHour, isSameOrAfterMinute, isSameOrAfterMonth, isSameOrAfterSecond, isSameOrAfterWeek, isSameOrAfterYear, isSameOrBefore, isSameOrBeforeDay, isSameOrBeforeHour, isSameOrBeforeMinute, isSameOrBeforeMonth, isSameOrBeforeSecond, isSameOrBeforeWeek, isSameOrBeforeYear } from './prototype/comparisons.js';
|
|
7
|
-
import { addDay, addDays, addHour, addHours, addMinute, addMinutes, addMonth, addMonths, addSecond, addSeconds, addWeek, addWeeks, addYear, addYears, endOfDay, endOfHour, endOfMinute, endOfMonth, endOfQuarter, endOfSecond, endOfWeek, endOfYear, startOfDay, startOfHour, startOfMinute, startOfMonth, startOfQuarter, startOfSecond, startOfWeek, startOfYear, subDay, subDays, subHour, subHours, subMinute, subMinutes, subMonth, subMonths, subSecond, subSeconds, subWeek, subWeeks, subYear, subYears } from './prototype/manipulate.js';
|
|
8
|
-
import { format, toDateString, toISOString, toString, toTimeString, toUTCString } from './prototype/output.js';
|
|
9
|
-
import { dayName, dayPeriod, daysInMonth, daysInYear, era, isDST, isLeapYear, monthName, timeZoneName, weeksInYear } from './prototype/utility.js';
|
|
10
|
-
|
|
11
|
-
DateTime.dayOfYear = dayOfYear;
|
|
12
|
-
DateTime.daysInMonth = _daysInMonth;
|
|
13
|
-
DateTime.daysInYear = _daysInYear;
|
|
14
|
-
DateTime.fromArray = fromArray;
|
|
15
|
-
DateTime.fromDate = fromDate;
|
|
16
|
-
DateTime.fromFormat = fromFormat;
|
|
17
|
-
DateTime.fromISOString = fromISOString;
|
|
18
|
-
DateTime.fromTimestamp = fromTimestamp;
|
|
19
|
-
DateTime.getDefaultLocale = getDefaultLocale;
|
|
20
|
-
DateTime.getDefaultTimeZone = getDefaultTimeZone;
|
|
21
|
-
DateTime.isLeapYear = _isLeapYear;
|
|
22
|
-
DateTime.now = now;
|
|
23
|
-
DateTime.setDateClamping = setDateClamping;
|
|
24
|
-
DateTime.setDefaultLocale = setDefaultLocale;
|
|
25
|
-
DateTime.setDefaultTimeZone = setDefaultTimeZone;
|
|
26
|
-
|
|
27
|
-
const proto = DateTime.prototype;
|
|
28
|
-
|
|
29
|
-
proto.addDay = addDay;
|
|
30
|
-
proto.addDays = addDays;
|
|
31
|
-
proto.addHour = addHour;
|
|
32
|
-
proto.addHours = addHours;
|
|
33
|
-
proto.addMinute = addMinute;
|
|
34
|
-
proto.addMinutes = addMinutes;
|
|
35
|
-
proto.addMonth = addMonth;
|
|
36
|
-
proto.addMonths = addMonths;
|
|
37
|
-
proto.addSecond = addSecond;
|
|
38
|
-
proto.addSeconds = addSeconds;
|
|
39
|
-
proto.addWeek = addWeek;
|
|
40
|
-
proto.addWeeks = addWeeks;
|
|
41
|
-
proto.addYear = addYear;
|
|
42
|
-
proto.addYears = addYears;
|
|
43
|
-
proto.dayName = dayName;
|
|
44
|
-
proto.dayPeriod = dayPeriod;
|
|
45
|
-
proto.daysInMonth = daysInMonth;
|
|
46
|
-
proto.daysInYear = daysInYear;
|
|
47
|
-
proto.diff = diff;
|
|
48
|
-
proto.diffInDays = diffInDays;
|
|
49
|
-
proto.diffInHours = diffInHours;
|
|
50
|
-
proto.diffInMinutes = diffInMinutes;
|
|
51
|
-
proto.diffInMonths = diffInMonths;
|
|
52
|
-
proto.diffInSeconds = diffInSeconds;
|
|
53
|
-
proto.diffInWeeks = diffInWeeks;
|
|
54
|
-
proto.diffInYears = diffInYears;
|
|
55
|
-
proto.endOfDay = endOfDay;
|
|
56
|
-
proto.endOfHour = endOfHour;
|
|
57
|
-
proto.endOfMinute = endOfMinute;
|
|
58
|
-
proto.endOfMonth = endOfMonth;
|
|
59
|
-
proto.endOfQuarter = endOfQuarter;
|
|
60
|
-
proto.endOfSecond = endOfSecond;
|
|
61
|
-
proto.endOfWeek = endOfWeek;
|
|
62
|
-
proto.endOfYear = endOfYear;
|
|
63
|
-
proto.era = era;
|
|
64
|
-
proto.format = format;
|
|
65
|
-
proto.getDate = getDate;
|
|
66
|
-
proto.getDay = getDay;
|
|
67
|
-
proto.getDayOfYear = getDayOfYear;
|
|
68
|
-
proto.getHours = getHours;
|
|
69
|
-
proto.getMilliseconds = getMilliseconds;
|
|
70
|
-
proto.getMinutes = getMinutes;
|
|
71
|
-
proto.getMonth = getMonth;
|
|
72
|
-
proto.getQuarter = getQuarter;
|
|
73
|
-
proto.getSeconds = getSeconds;
|
|
74
|
-
proto.getTimestamp = getTimestamp;
|
|
75
|
-
proto.getWeek = getWeek;
|
|
76
|
-
proto.getWeekDay = getWeekDay;
|
|
77
|
-
proto.getWeekDayInMonth = getWeekDayInMonth;
|
|
78
|
-
proto.getWeekOfMonth = getWeekOfMonth;
|
|
79
|
-
proto.getWeekYear = getWeekYear;
|
|
80
|
-
proto.getYear = getYear;
|
|
81
|
-
proto.humanDiff = humanDiff;
|
|
82
|
-
proto.humanDiffInDays = humanDiffInDays;
|
|
83
|
-
proto.humanDiffInHours = humanDiffInHours;
|
|
84
|
-
proto.humanDiffInMinutes = humanDiffInMinutes;
|
|
85
|
-
proto.humanDiffInMonths = humanDiffInMonths;
|
|
86
|
-
proto.humanDiffInSeconds = humanDiffInSeconds;
|
|
87
|
-
proto.humanDiffInWeeks = humanDiffInWeeks;
|
|
88
|
-
proto.humanDiffInYears = humanDiffInYears;
|
|
89
|
-
proto.isAfter = isAfter;
|
|
90
|
-
proto.isAfterDay = isAfterDay;
|
|
91
|
-
proto.isAfterHour = isAfterHour;
|
|
92
|
-
proto.isAfterMinute = isAfterMinute;
|
|
93
|
-
proto.isAfterMonth = isAfterMonth;
|
|
94
|
-
proto.isAfterSecond = isAfterSecond;
|
|
95
|
-
proto.isAfterWeek = isAfterWeek;
|
|
96
|
-
proto.isAfterYear = isAfterYear;
|
|
97
|
-
proto.isBefore = isBefore;
|
|
98
|
-
proto.isBeforeDay = isBeforeDay;
|
|
99
|
-
proto.isBeforeHour = isBeforeHour;
|
|
100
|
-
proto.isBeforeMinute = isBeforeMinute;
|
|
101
|
-
proto.isBeforeMonth = isBeforeMonth;
|
|
102
|
-
proto.isBeforeSecond = isBeforeSecond;
|
|
103
|
-
proto.isBeforeWeek = isBeforeWeek;
|
|
104
|
-
proto.isBeforeYear = isBeforeYear;
|
|
105
|
-
proto.isBetween = isBetween;
|
|
106
|
-
proto.isBetweenDay = isBetweenDay;
|
|
107
|
-
proto.isBetweenHour = isBetweenHour;
|
|
108
|
-
proto.isBetweenMinute = isBetweenMinute;
|
|
109
|
-
proto.isBetweenMonth = isBetweenMonth;
|
|
110
|
-
proto.isBetweenSecond = isBetweenSecond;
|
|
111
|
-
proto.isBetweenWeek = isBetweenWeek;
|
|
112
|
-
proto.isBetweenYear = isBetweenYear;
|
|
113
|
-
proto.isDST = isDST;
|
|
114
|
-
proto.isLeapYear = isLeapYear;
|
|
115
|
-
proto.isSame = isSame;
|
|
116
|
-
proto.isSameDay = isSameDay;
|
|
117
|
-
proto.isSameHour = isSameHour;
|
|
118
|
-
proto.isSameMinute = isSameMinute;
|
|
119
|
-
proto.isSameMonth = isSameMonth;
|
|
120
|
-
proto.isSameSecond = isSameSecond;
|
|
121
|
-
proto.isSameWeek = isSameWeek;
|
|
122
|
-
proto.isSameYear = isSameYear;
|
|
123
|
-
proto.isSameOrAfter = isSameOrAfter;
|
|
124
|
-
proto.isSameOrAfterDay = isSameOrAfterDay;
|
|
125
|
-
proto.isSameOrAfterHour = isSameOrAfterHour;
|
|
126
|
-
proto.isSameOrAfterMinute = isSameOrAfterMinute;
|
|
127
|
-
proto.isSameOrAfterMonth = isSameOrAfterMonth;
|
|
128
|
-
proto.isSameOrAfterSecond = isSameOrAfterSecond;
|
|
129
|
-
proto.isSameOrAfterWeek = isSameOrAfterWeek;
|
|
130
|
-
proto.isSameOrAfterYear = isSameOrAfterYear;
|
|
131
|
-
proto.isSameOrBefore = isSameOrBefore;
|
|
132
|
-
proto.isSameOrBeforeDay = isSameOrBeforeDay;
|
|
133
|
-
proto.isSameOrBeforeHour = isSameOrBeforeHour;
|
|
134
|
-
proto.isSameOrBeforeMinute = isSameOrBeforeMinute;
|
|
135
|
-
proto.isSameOrBeforeMonth = isSameOrBeforeMonth;
|
|
136
|
-
proto.isSameOrBeforeSecond = isSameOrBeforeSecond;
|
|
137
|
-
proto.isSameOrBeforeWeek = isSameOrBeforeWeek;
|
|
138
|
-
proto.isSameOrBeforeYear = isSameOrBeforeYear;
|
|
139
|
-
proto.monthName = monthName;
|
|
140
|
-
proto.setDate = setDate;
|
|
141
|
-
proto.setDay = setDay;
|
|
142
|
-
proto.setDayOfYear = setDayOfYear;
|
|
143
|
-
proto.setHours = setHours;
|
|
144
|
-
proto.setMilliseconds = setMilliseconds;
|
|
145
|
-
proto.setMinutes = setMinutes;
|
|
146
|
-
proto.setMonth = setMonth;
|
|
147
|
-
proto.setQuarter = setQuarter;
|
|
148
|
-
proto.setSeconds = setSeconds;
|
|
149
|
-
proto.setTimestamp = setTimestamp;
|
|
150
|
-
proto.setWeek = setWeek;
|
|
151
|
-
proto.setWeekDay = setWeekDay;
|
|
152
|
-
proto.setWeekDayInMonth = setWeekDayInMonth;
|
|
153
|
-
proto.setWeekOfMonth = setWeekOfMonth;
|
|
154
|
-
proto.setWeekYear = setWeekYear;
|
|
155
|
-
proto.setYear = setYear;
|
|
156
|
-
proto.startOfDay = startOfDay;
|
|
157
|
-
proto.startOfHour = startOfHour;
|
|
158
|
-
proto.startOfMinute = startOfMinute;
|
|
159
|
-
proto.startOfMonth = startOfMonth;
|
|
160
|
-
proto.startOfQuarter = startOfQuarter;
|
|
161
|
-
proto.startOfSecond = startOfSecond;
|
|
162
|
-
proto.startOfWeek = startOfWeek;
|
|
163
|
-
proto.startOfYear = startOfYear;
|
|
164
|
-
proto.subDay = subDay;
|
|
165
|
-
proto.subDays = subDays;
|
|
166
|
-
proto.subHour = subHour;
|
|
167
|
-
proto.subHours = subHours;
|
|
168
|
-
proto.subMinute = subMinute;
|
|
169
|
-
proto.subMinutes = subMinutes;
|
|
170
|
-
proto.subMonth = subMonth;
|
|
171
|
-
proto.subMonths = subMonths;
|
|
172
|
-
proto.subSecond = subSecond;
|
|
173
|
-
proto.subSeconds = subSeconds;
|
|
174
|
-
proto.subWeek = subWeek;
|
|
175
|
-
proto.subWeeks = subWeeks;
|
|
176
|
-
proto.subYear = subYear;
|
|
177
|
-
proto.subYears = subYears;
|
|
178
|
-
proto.timeZoneName = timeZoneName;
|
|
179
|
-
proto.toDateString = toDateString;
|
|
180
|
-
proto.toISOString = toISOString;
|
|
181
|
-
proto.toString = toString;
|
|
182
|
-
proto.toTimeString = toTimeString;
|
|
183
|
-
proto.toUTCString = toUTCString;
|
|
184
|
-
proto.weeksInYear = weeksInYear;
|
|
185
|
-
|
|
186
|
-
export default DateTime;
|
|
1
|
+
export { default } from './date-time.js';
|
package/src/vars.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* DateTime Variables
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
|
-
const resolvedOptions =
|
|
5
|
+
const resolvedOptions = new Intl.DateTimeFormat().resolvedOptions();
|
|
6
6
|
|
|
7
7
|
export const config = {
|
|
8
8
|
clampDates: true,
|
|
@@ -10,7 +10,7 @@ export const config = {
|
|
|
10
10
|
defaultTimeZone: resolvedOptions.timeZone,
|
|
11
11
|
};
|
|
12
12
|
|
|
13
|
-
export const dateStringTimeZoneRegExp =
|
|
13
|
+
export const dateStringTimeZoneRegExp = /(?:\b(?:UTC|GMT)\b|[T\s]\d{2}:\d{2}(?::\d{2}(?:\.\d{3})?)?(?:Z|[+-]\d{2}(?::?\d{2})?)\b)/i;
|
|
14
14
|
|
|
15
15
|
export const formats = {
|
|
16
16
|
date: 'eee MMM dd yyyy',
|
|
@@ -19,11 +19,11 @@ export const formats = {
|
|
|
19
19
|
time: 'HH:mm:ss xx (VV)',
|
|
20
20
|
};
|
|
21
21
|
|
|
22
|
-
export const formatTokenRegExp = /([a-z])\1*|'[^']*'/i;
|
|
22
|
+
export const formatTokenRegExp = /([a-z])\1*|''|'(?:[^']|'')*'/i;
|
|
23
23
|
|
|
24
24
|
export const monthDays = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
|
|
25
25
|
|
|
26
|
-
export const offsetRegExp =
|
|
26
|
+
export const offsetRegExp = /^(?:GMT)?([+-])([01]\d|2[0-3])(?:(:?)([0-5]\d)(?:\3([0-5]\d))?)?$/;
|
|
27
27
|
|
|
28
28
|
export const parseOrderKeys = [
|
|
29
29
|
['year', 'weekYear'],
|
|
@@ -1,163 +0,0 @@
|
|
|
1
|
-
import { getOffsetTime } from './../helpers.js';
|
|
2
|
-
import { minimumDays, weekDay } from './../formatter/utility.js';
|
|
3
|
-
import { dayOfYear } from './../static/utility.js';
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* DateTime Attributes (Get)
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* Get the date of the month in current timeZone.
|
|
11
|
-
* @return {number} The date of the month.
|
|
12
|
-
*/
|
|
13
|
-
export function getDate() {
|
|
14
|
-
return new Date(getOffsetTime(this)).getUTCDate();
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* Get the day of the week in current timeZone.
|
|
19
|
-
* @return {number} The day of the week. (0 - Sunday, 6 - Saturday)
|
|
20
|
-
*/
|
|
21
|
-
export function getDay() {
|
|
22
|
-
return new Date(getOffsetTime(this)).getUTCDay();
|
|
23
|
-
};
|
|
24
|
-
|
|
25
|
-
/**
|
|
26
|
-
* Get the day of the year in current timeZone.
|
|
27
|
-
* @return {number} The day of the year. (1, 366)
|
|
28
|
-
*/
|
|
29
|
-
export function getDayOfYear() {
|
|
30
|
-
return dayOfYear(
|
|
31
|
-
this.getYear(),
|
|
32
|
-
this.getMonth(),
|
|
33
|
-
this.getDate(),
|
|
34
|
-
);
|
|
35
|
-
};
|
|
36
|
-
|
|
37
|
-
/**
|
|
38
|
-
* Get the hours of the day in current timeZone.
|
|
39
|
-
* @return {number} The hours of the day. (0, 23)
|
|
40
|
-
*/
|
|
41
|
-
export function getHours() {
|
|
42
|
-
return new Date(getOffsetTime(this)).getUTCHours();
|
|
43
|
-
};
|
|
44
|
-
|
|
45
|
-
/**
|
|
46
|
-
* Get the milliseconds in current timeZone.
|
|
47
|
-
* @return {number} The milliseconds.
|
|
48
|
-
*/
|
|
49
|
-
export function getMilliseconds() {
|
|
50
|
-
return new Date(getOffsetTime(this)).getUTCMilliseconds();
|
|
51
|
-
};
|
|
52
|
-
|
|
53
|
-
/**
|
|
54
|
-
* Get the minutes in current timeZone.
|
|
55
|
-
* @return {number} The minutes. (0, 59)
|
|
56
|
-
*/
|
|
57
|
-
export function getMinutes() {
|
|
58
|
-
return new Date(getOffsetTime(this)).getUTCMinutes();
|
|
59
|
-
};
|
|
60
|
-
|
|
61
|
-
/**
|
|
62
|
-
* Get the month in current timeZone.
|
|
63
|
-
* @return {number} The month. (1, 12)
|
|
64
|
-
*/
|
|
65
|
-
export function getMonth() {
|
|
66
|
-
return new Date(getOffsetTime(this)).getUTCMonth() + 1;
|
|
67
|
-
};
|
|
68
|
-
|
|
69
|
-
/**
|
|
70
|
-
* Get the quarter of the year in current timeZone.
|
|
71
|
-
* @return {number} The quarter of the year. (1, 4)
|
|
72
|
-
*/
|
|
73
|
-
export function getQuarter() {
|
|
74
|
-
return Math.ceil(this.getMonth() / 3);
|
|
75
|
-
};
|
|
76
|
-
|
|
77
|
-
/**
|
|
78
|
-
* Get the seconds in current timeZone.
|
|
79
|
-
* @return {number} The seconds. (0, 59)
|
|
80
|
-
*/
|
|
81
|
-
export function getSeconds() {
|
|
82
|
-
return new Date(getOffsetTime(this)).getUTCSeconds();
|
|
83
|
-
};
|
|
84
|
-
|
|
85
|
-
/**
|
|
86
|
-
* Get the number of seconds since the UNIX epoch.
|
|
87
|
-
* @return {number} The number of seconds since the UNIX epoch.
|
|
88
|
-
*/
|
|
89
|
-
export function getTimestamp() {
|
|
90
|
-
return Math.floor(this.getTime() / 1000);
|
|
91
|
-
};
|
|
92
|
-
|
|
93
|
-
/**
|
|
94
|
-
* Get the local week in current timeZone.
|
|
95
|
-
* @return {number} The local week. (1, 53)
|
|
96
|
-
*/
|
|
97
|
-
export function getWeek() {
|
|
98
|
-
const thisWeek = this.startOfDay().setWeekDay(1);
|
|
99
|
-
const firstWeek = thisWeek.setWeek(1, 1);
|
|
100
|
-
|
|
101
|
-
return 1 +
|
|
102
|
-
(
|
|
103
|
-
(
|
|
104
|
-
(thisWeek - firstWeek) /
|
|
105
|
-
604800000
|
|
106
|
-
) | 0
|
|
107
|
-
);
|
|
108
|
-
};
|
|
109
|
-
|
|
110
|
-
/**
|
|
111
|
-
* Get the local day of the week in current timeZone.
|
|
112
|
-
* @return {number} The local day of the week. (1 - 7)
|
|
113
|
-
*/
|
|
114
|
-
export function getWeekDay() {
|
|
115
|
-
return weekDay(
|
|
116
|
-
this.getLocale(),
|
|
117
|
-
this.getDay(),
|
|
118
|
-
);
|
|
119
|
-
};
|
|
120
|
-
|
|
121
|
-
/**
|
|
122
|
-
* Get the week day in month in current timeZone.
|
|
123
|
-
* @return {number} The week day in month.
|
|
124
|
-
*/
|
|
125
|
-
export function getWeekDayInMonth() {
|
|
126
|
-
const thisWeek = this.getWeek();
|
|
127
|
-
const first = this.setDate(1);
|
|
128
|
-
const firstWeek = first.getWeek();
|
|
129
|
-
const offset = first.getWeekDay() > this.getWeekDay() ?
|
|
130
|
-
0 : 1;
|
|
131
|
-
return firstWeek > thisWeek ?
|
|
132
|
-
thisWeek + offset :
|
|
133
|
-
thisWeek - firstWeek + offset;
|
|
134
|
-
};
|
|
135
|
-
|
|
136
|
-
/**
|
|
137
|
-
* Get the week of month in current timeZone.
|
|
138
|
-
* @return {number} The week of month.
|
|
139
|
-
*/
|
|
140
|
-
export function getWeekOfMonth() {
|
|
141
|
-
const thisWeek = this.getWeek();
|
|
142
|
-
const firstWeek = this.setDate(1).getWeek();
|
|
143
|
-
return firstWeek > thisWeek ?
|
|
144
|
-
thisWeek + 1 :
|
|
145
|
-
thisWeek - firstWeek + 1;
|
|
146
|
-
};
|
|
147
|
-
|
|
148
|
-
/**
|
|
149
|
-
* Get the week year in current timeZone.
|
|
150
|
-
* @return {number} The week year.
|
|
151
|
-
*/
|
|
152
|
-
export function getWeekYear() {
|
|
153
|
-
const minDays = minimumDays(this.getLocale());
|
|
154
|
-
return this.setWeekDay(7 - minDays + 1).getYear();
|
|
155
|
-
};
|
|
156
|
-
|
|
157
|
-
/**
|
|
158
|
-
* Get the year in current timeZone.
|
|
159
|
-
* @return {number} The year.
|
|
160
|
-
*/
|
|
161
|
-
export function getYear() {
|
|
162
|
-
return new Date(getOffsetTime(this)).getUTCFullYear();
|
|
163
|
-
};
|
|
@@ -1,281 +0,0 @@
|
|
|
1
|
-
import DateTime from './../date-time.js';
|
|
2
|
-
import { getOffsetTime, setOffsetTime } from './../helpers.js';
|
|
3
|
-
import { config } from './../vars.js';
|
|
4
|
-
import { minimumDays } from './../formatter/utility.js';
|
|
5
|
-
import { daysInMonth } from './../static/utility.js';
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* DateTime Attributes (Set)
|
|
9
|
-
*/
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* Set the date of the month in current timeZone.
|
|
13
|
-
* @param {number} date The date of the month.
|
|
14
|
-
* @return {DateTime} The DateTime object.
|
|
15
|
-
*/
|
|
16
|
-
export function setDate(date) {
|
|
17
|
-
return setOffsetTime(
|
|
18
|
-
this,
|
|
19
|
-
new Date(getOffsetTime(this)).setUTCDate(date),
|
|
20
|
-
);
|
|
21
|
-
};
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* Set the day of the week in current timeZone.
|
|
25
|
-
* @param {number} day The day of the week. (0 - Sunday, 6 - Saturday)
|
|
26
|
-
* @return {DateTime} The DateTime object.
|
|
27
|
-
*/
|
|
28
|
-
export function setDay(day) {
|
|
29
|
-
return setOffsetTime(
|
|
30
|
-
this,
|
|
31
|
-
new Date(getOffsetTime(this)).setUTCDate(
|
|
32
|
-
this.getDate() -
|
|
33
|
-
this.getDay() +
|
|
34
|
-
parseInt(day),
|
|
35
|
-
),
|
|
36
|
-
);
|
|
37
|
-
};
|
|
38
|
-
|
|
39
|
-
/**
|
|
40
|
-
* Set the day of the year in current timeZone.
|
|
41
|
-
* @param {number} day The day of the year. (1, 366)
|
|
42
|
-
* @return {DateTime} The DateTime object.
|
|
43
|
-
*/
|
|
44
|
-
export function setDayOfYear(day) {
|
|
45
|
-
return setOffsetTime(
|
|
46
|
-
this,
|
|
47
|
-
new Date(getOffsetTime(this)).setUTCMonth(
|
|
48
|
-
0,
|
|
49
|
-
day,
|
|
50
|
-
),
|
|
51
|
-
);
|
|
52
|
-
};
|
|
53
|
-
|
|
54
|
-
/**
|
|
55
|
-
* Set the hours in current timeZone (and optionally, minutes, seconds and milliseconds).
|
|
56
|
-
* @param {number} hours The hours. (0, 23)
|
|
57
|
-
* @param {number} [minutes] The minutes. (0, 59)
|
|
58
|
-
* @param {number} [seconds] The seconds. (0, 59)
|
|
59
|
-
* @param {number} [milliseconds] The milliseconds.
|
|
60
|
-
* @return {DateTime} The DateTime object.
|
|
61
|
-
*/
|
|
62
|
-
export function setHours(...args) {
|
|
63
|
-
return setOffsetTime(
|
|
64
|
-
this,
|
|
65
|
-
new Date(getOffsetTime(this)).setUTCHours(...args),
|
|
66
|
-
);
|
|
67
|
-
};
|
|
68
|
-
|
|
69
|
-
/**
|
|
70
|
-
* Set the milliseconds in current timeZone.
|
|
71
|
-
* @param {number} milliseconds The milliseconds.
|
|
72
|
-
* @return {DateTime} The DateTime object.
|
|
73
|
-
*/
|
|
74
|
-
export function setMilliseconds(milliseconds) {
|
|
75
|
-
return setOffsetTime(
|
|
76
|
-
this,
|
|
77
|
-
new Date(getOffsetTime(this)).setUTCMilliseconds(milliseconds),
|
|
78
|
-
);
|
|
79
|
-
};
|
|
80
|
-
|
|
81
|
-
/**
|
|
82
|
-
* Set the minutes in current timeZone (and optionally, seconds and milliseconds).
|
|
83
|
-
* @param {number} minutes The minutes. (0, 59)
|
|
84
|
-
* @param {number} [seconds] The seconds. (0, 59)
|
|
85
|
-
* @param {number} [milliseconds] The milliseconds.
|
|
86
|
-
* @return {DateTime} The DateTime object.
|
|
87
|
-
*/
|
|
88
|
-
export function setMinutes(...args) {
|
|
89
|
-
return setOffsetTime(
|
|
90
|
-
this,
|
|
91
|
-
new Date(getOffsetTime(this)).setUTCMinutes(...args),
|
|
92
|
-
);
|
|
93
|
-
};
|
|
94
|
-
|
|
95
|
-
/**
|
|
96
|
-
* Set the month in current timeZone (and optionally, date).
|
|
97
|
-
* @param {number} month The month. (1, 12)
|
|
98
|
-
* @param {number|null} [date] The date of the month.
|
|
99
|
-
* @return {DateTime} The DateTime object.
|
|
100
|
-
*/
|
|
101
|
-
export function setMonth(month, date = null) {
|
|
102
|
-
if (date === null) {
|
|
103
|
-
date = this.getDate();
|
|
104
|
-
|
|
105
|
-
if (config.clampDates) {
|
|
106
|
-
date = Math.min(
|
|
107
|
-
date,
|
|
108
|
-
daysInMonth(
|
|
109
|
-
this.getYear(),
|
|
110
|
-
month,
|
|
111
|
-
),
|
|
112
|
-
);
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
return setOffsetTime(
|
|
117
|
-
this,
|
|
118
|
-
new Date(getOffsetTime(this)).setUTCMonth(
|
|
119
|
-
month - 1,
|
|
120
|
-
date,
|
|
121
|
-
),
|
|
122
|
-
);
|
|
123
|
-
};
|
|
124
|
-
|
|
125
|
-
/**
|
|
126
|
-
* Set the quarter of the year in current timeZone.
|
|
127
|
-
* @param {number} quarter The quarter of the year. (1, 4)
|
|
128
|
-
* @return {DateTime} The DateTime object.
|
|
129
|
-
*/
|
|
130
|
-
export function setQuarter(quarter) {
|
|
131
|
-
return setOffsetTime(
|
|
132
|
-
this,
|
|
133
|
-
new Date(getOffsetTime(this)).setUTCMonth(
|
|
134
|
-
quarter * 3 -
|
|
135
|
-
3,
|
|
136
|
-
),
|
|
137
|
-
);
|
|
138
|
-
};
|
|
139
|
-
|
|
140
|
-
/**
|
|
141
|
-
* Set the seconds in current timeZone (and optionally, milliseconds).
|
|
142
|
-
* @param {number} seconds The seconds. (0, 59)
|
|
143
|
-
* @param {number} [milliseconds] The milliseconds.
|
|
144
|
-
* @return {DateTime} The DateTime object.
|
|
145
|
-
*/
|
|
146
|
-
export function setSeconds(...args) {
|
|
147
|
-
return setOffsetTime(
|
|
148
|
-
this,
|
|
149
|
-
new Date(getOffsetTime(this)).setUTCSeconds(...args),
|
|
150
|
-
);
|
|
151
|
-
};
|
|
152
|
-
|
|
153
|
-
/**
|
|
154
|
-
* Set the number of seconds since the UNIX epoch.
|
|
155
|
-
* @param {number} timestamp The number of seconds since the UNIX epoch.
|
|
156
|
-
* @return {DateTime} The DateTime object.
|
|
157
|
-
*/
|
|
158
|
-
export function setTimestamp(timestamp) {
|
|
159
|
-
return this.setTime(timestamp * 1000);
|
|
160
|
-
};
|
|
161
|
-
|
|
162
|
-
/**
|
|
163
|
-
* Set the local day of the week in current timeZone (and optionally, day of the week).
|
|
164
|
-
* @param {number} week The local week.
|
|
165
|
-
* @param {number|null} [day] The local day of the week. (1 - 7)
|
|
166
|
-
* @return {DateTime} The DateTime object.
|
|
167
|
-
*/
|
|
168
|
-
export function setWeek(week, day = null) {
|
|
169
|
-
if (day === null) {
|
|
170
|
-
day = this.getWeekDay();
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
const minDays = minimumDays(this.getLocale());
|
|
174
|
-
return this.setYear(this.getWeekYear(), 1, minDays + ((week - 1) * 7)).setWeekDay(day);
|
|
175
|
-
};
|
|
176
|
-
|
|
177
|
-
/**
|
|
178
|
-
* Set the local day of the week in current timeZone.
|
|
179
|
-
* @param {number} day The local day of the week. (1 - 7)
|
|
180
|
-
* @return {DateTime} The DateTime object.
|
|
181
|
-
*/
|
|
182
|
-
export function setWeekDay(day) {
|
|
183
|
-
return setOffsetTime(
|
|
184
|
-
this,
|
|
185
|
-
new Date(getOffsetTime(this)).setUTCDate(
|
|
186
|
-
this.getDate() -
|
|
187
|
-
this.getWeekDay() +
|
|
188
|
-
parseInt(day),
|
|
189
|
-
),
|
|
190
|
-
);
|
|
191
|
-
};
|
|
192
|
-
|
|
193
|
-
/**
|
|
194
|
-
* Set the week day in month in current timeZone.
|
|
195
|
-
* @param {number} week The week day in month.
|
|
196
|
-
* @return {DateTime} The DateTime object.
|
|
197
|
-
*/
|
|
198
|
-
export function setWeekDayInMonth(week) {
|
|
199
|
-
return this.setDate(
|
|
200
|
-
this.getDate() +
|
|
201
|
-
(
|
|
202
|
-
week -
|
|
203
|
-
this.getWeekDayInMonth()
|
|
204
|
-
) * 7,
|
|
205
|
-
);
|
|
206
|
-
};
|
|
207
|
-
|
|
208
|
-
/**
|
|
209
|
-
* Set the week of month in current timeZone.
|
|
210
|
-
* @param {number} week The week of month.
|
|
211
|
-
* @return {DateTime} The DateTime object.
|
|
212
|
-
*/
|
|
213
|
-
export function setWeekOfMonth(week) {
|
|
214
|
-
return this.setDate(
|
|
215
|
-
this.getDate() +
|
|
216
|
-
(
|
|
217
|
-
week -
|
|
218
|
-
this.getWeekOfMonth()
|
|
219
|
-
) * 7,
|
|
220
|
-
);
|
|
221
|
-
};
|
|
222
|
-
|
|
223
|
-
/**
|
|
224
|
-
* Set the local day of the week in current timeZone (and optionally, week and day of the week).
|
|
225
|
-
* @param {number} year The local year.
|
|
226
|
-
* @param {number|null} [week] The local week.
|
|
227
|
-
* @param {number|null} [day] The local day of the week. (1 - 7)
|
|
228
|
-
* @return {DateTime} The DateTime object.
|
|
229
|
-
*/
|
|
230
|
-
export function setWeekYear(year, week = null, day = null) {
|
|
231
|
-
const minDays = minimumDays(this.getLocale());
|
|
232
|
-
|
|
233
|
-
if (week === null) {
|
|
234
|
-
week = Math.min(
|
|
235
|
-
this.getWeek(),
|
|
236
|
-
DateTime.fromArray([year, 1, minDays]).weeksInYear(),
|
|
237
|
-
);
|
|
238
|
-
}
|
|
239
|
-
|
|
240
|
-
if (day === null) {
|
|
241
|
-
day = this.getWeekDay();
|
|
242
|
-
}
|
|
243
|
-
|
|
244
|
-
return this.setYear(year, 1, minDays + ((week - 1) * 7)).setWeekDay(day);
|
|
245
|
-
};
|
|
246
|
-
|
|
247
|
-
/**
|
|
248
|
-
* Set the year in current timeZone (and optionally, month and date).
|
|
249
|
-
* @param {number} year The year.
|
|
250
|
-
* @param {number|null} [month] The month. (1, 12)
|
|
251
|
-
* @param {number|null} [date] The date of the month.
|
|
252
|
-
* @return {DateTime} The DateTime object.
|
|
253
|
-
*/
|
|
254
|
-
export function setYear(year, month = null, date = null) {
|
|
255
|
-
if (month === null) {
|
|
256
|
-
month = this.getMonth();
|
|
257
|
-
}
|
|
258
|
-
|
|
259
|
-
if (date === null) {
|
|
260
|
-
date = this.getDate();
|
|
261
|
-
|
|
262
|
-
if (config.clampDates) {
|
|
263
|
-
date = Math.min(
|
|
264
|
-
date,
|
|
265
|
-
daysInMonth(
|
|
266
|
-
this.getYear(),
|
|
267
|
-
month,
|
|
268
|
-
),
|
|
269
|
-
);
|
|
270
|
-
}
|
|
271
|
-
}
|
|
272
|
-
|
|
273
|
-
return setOffsetTime(
|
|
274
|
-
this,
|
|
275
|
-
new Date(getOffsetTime(this)).setUTCFullYear(
|
|
276
|
-
year,
|
|
277
|
-
month - 1,
|
|
278
|
-
date,
|
|
279
|
-
),
|
|
280
|
-
);
|
|
281
|
-
};
|