@@ -12,7 +12,7 @@ const isValidDate = (v) => {
12
12
/**
13
13
* Get calendar date
14
14
* @param {Date | String } v
15
- * @returns {String } YYYY -MM-DD
15
+ * @returns {String } yyyy -MM-dd
16
16
*/
17
17
function dateFormat ( v ) {
18
18
const date = typeof v === 'string' ? new Date ( v . replace ( / - / g, "/" ) ) : v ; // fix "Invalid date in safari"
@@ -24,10 +24,10 @@ function dateFormat(v) {
24
24
* Get calendar date
25
25
* @param {Date | String } v
26
26
* @param {Boolean } padZeroEnabled
27
- * @returns {String } YYYY -MM-DD
27
+ * @returns {String } yyyy -MM-dd
28
28
*/
29
29
function getCalendarDate ( v , padZeroEnabled = true ) {
30
-
30
+
31
31
const date = dateFormat ( v ) ;
32
32
const padZero = ( num ) => {
33
33
if ( padZeroEnabled ) {
@@ -50,10 +50,10 @@ function getCalendarDate(v, padZeroEnabled = true) {
50
50
51
51
/**
52
52
* Get today date
53
- * @returns {String } YYYY -MM-DD
53
+ * @returns {String } yyyy -MM-dd
54
54
*/
55
55
function getTodayDate ( ) {
56
-
56
+
57
57
return getCalendarDate ( new Date ( ) ) ;
58
58
}
59
59
@@ -62,10 +62,10 @@ function getTodayDate() {
62
62
/**
63
63
* Get tomorrow date
64
64
* @param {Date | String } v
65
- * @returns {String } YYYY -MM-DD
65
+ * @returns {String } yyyy -MM-dd
66
66
*/
67
67
function getTomorrowDate ( v ) {
68
-
68
+
69
69
const today = dateFormat ( v ) ;
70
70
const _tomorrow = today ;
71
71
_tomorrow . setDate ( _tomorrow . getDate ( ) + 1 ) ;
@@ -77,10 +77,10 @@ function getTomorrowDate(v) {
77
77
/**
78
78
* Get yesterday date
79
79
* @param {Date | String } v
80
- * @returns {String } YYYY -MM-DD
80
+ * @returns {String } yyyy -MM-dd
81
81
*/
82
82
function getYesterdayDate ( v ) {
83
-
83
+
84
84
const today = dateFormat ( v ) ;
85
85
const _yesterday = today ;
86
86
_yesterday . setDate ( _yesterday . getDate ( ) - 1 ) ;
@@ -92,11 +92,11 @@ function getYesterdayDate(v) {
92
92
* Get specified date
93
93
* @param {Date | String } v
94
94
* @param {Number } days The number of days forward or backward, which can be a negative number
95
- * @returns {String } YYYY -MM-DD
95
+ * @returns {String } yyyy -MM-dd
96
96
*/
97
97
/* console.log(getSpecifiedDate(getTodayDate(), -180)); // 2023-08-27 (180 days before February 23, 202) */
98
98
function getSpecifiedDate ( v , days ) {
99
-
99
+
100
100
const today = dateFormat ( v ) ;
101
101
const _specifiedDay = today ;
102
102
_specifiedDay . setDate ( _specifiedDay . getDate ( ) + days ) ;
@@ -109,27 +109,27 @@ function getSpecifiedDate(v, days) {
109
109
/**
110
110
* Get next month date
111
111
* @param {Date | String } v
112
- * @returns {String } YYYY -MM-DD
112
+ * @returns {String } yyyy -MM-dd
113
113
*/
114
114
function getNextMonthDate ( v ) {
115
-
115
+
116
116
const today = dateFormat ( v ) ;
117
- today . setMonth ( today . getMonth ( ) + 1 ) ;
118
-
117
+ today . setMonth ( today . getMonth ( ) + 1 ) ;
118
+
119
119
return getCalendarDate ( today ) ;
120
120
}
121
121
122
122
123
123
/**
124
124
* Get previous month date
125
125
* @param {Date | String } v
126
- * @returns {String } YYYY -MM-DD
126
+ * @returns {String } yyyy -MM-dd
127
127
*/
128
128
function getPrevMonthDate ( v ) {
129
-
129
+
130
130
const today = dateFormat ( v ) ;
131
- today . setMonth ( today . getMonth ( ) - 1 ) ;
132
-
131
+ today . setMonth ( today . getMonth ( ) - 1 ) ;
132
+
133
133
return getCalendarDate ( today ) ;
134
134
}
135
135
@@ -138,29 +138,29 @@ function getPrevMonthDate(v) {
138
138
/**
139
139
* Get next year date
140
140
* @param {Date | String } v
141
- * @returns {String } YYYY -MM-DD
141
+ * @returns {String } yyyy -MM-dd
142
142
*/
143
143
function getNextYearDate ( v ) {
144
-
144
+
145
145
const today = dateFormat ( v ) ;
146
146
const current = new Date ( today ) ;
147
147
current . setFullYear ( current . getFullYear ( ) + 1 ) ;
148
-
148
+
149
149
return getCalendarDate ( current ) ;
150
150
}
151
151
152
152
153
153
/**
154
154
* Get previous year date
155
155
* @param {Date | String } v
156
- * @returns {String } YYYY -MM-DD
156
+ * @returns {String } yyyy -MM-dd
157
157
*/
158
158
function getPrevYearDate ( v ) {
159
-
159
+
160
160
const today = dateFormat ( v ) ;
161
161
const current = new Date ( today ) ;
162
162
current . setFullYear ( current . getFullYear ( ) - 1 ) ;
163
-
163
+
164
164
return getCalendarDate ( current ) ;
165
165
}
166
166
@@ -171,7 +171,7 @@ function getPrevYearDate(v) {
171
171
* Get last day in month
172
172
* @param {Date | String } v
173
173
* @param {?Number } targetMonth
174
- * @returns {String } YYYY -MM-DD
174
+ * @returns {String } yyyy -MM-dd
175
175
*/
176
176
/*
177
177
Example: Get last day in next month
@@ -186,7 +186,7 @@ const lastDayOfNextMonth = `${y}-${m}-${d}`; // 2024-02-29
186
186
*/
187
187
function getLastDayInMonth ( v , targetMonth = undefined ) {
188
188
const date = dateFormat ( v ) ;
189
- return new Date ( date . getFullYear ( ) , typeof targetMonth !== 'undefined' ? targetMonth : date . getMonth ( ) - 1 , 0 ) . getDate ( ) ;
189
+ return new Date ( date . getFullYear ( ) , typeof targetMonth !== 'undefined' ? targetMonth : date . getMonth ( ) - 1 , 0 ) . getDate ( ) ;
190
190
}
191
191
192
192
@@ -239,7 +239,7 @@ function getFirstAndLastMonthDay(year, padZeroEnabled = true) {
239
239
* @typedef {String } JSON
240
240
*/
241
241
function getCurrentDate ( padZeroEnabled = true ) {
242
-
242
+
243
243
const date = new Date ( ) ;
244
244
const padZero = ( num ) => {
245
245
if ( padZeroEnabled ) {
@@ -272,7 +272,7 @@ function getCurrentDate(padZeroEnabled = true) {
272
272
* @returns {String } yyyy-MM-dd HH:mm:ss
273
273
*/
274
274
function getFullTime ( v , padZeroEnabled = true , hasSeconds = true ) {
275
-
275
+
276
276
const date = dateFormat ( v ) ;
277
277
const padZero = ( num ) => {
278
278
if ( padZeroEnabled ) {
@@ -290,7 +290,7 @@ function getFullTime(v, padZeroEnabled = true, hasSeconds = true) {
290
290
const seconds = padZero ( date . getSeconds ( ) ) ;
291
291
const res = `${ year } -${ month } -${ day } ${ hours } :${ minutes } :${ seconds } ` ;
292
292
const res2 = `${ year } -${ month } -${ day } ${ hours } :${ minutes } ` ;
293
-
293
+
294
294
return hasSeconds ? res : res2 ;
295
295
}
296
296
@@ -305,7 +305,7 @@ function getFullTime(v, padZeroEnabled = true, hasSeconds = true) {
305
305
*/
306
306
function setDateHours ( v , offset , padZeroEnabled = true ) {
307
307
const date = dateFormat ( v ) ;
308
- const _cur = new Date ( date ) . setTime ( new Date ( date ) . getTime ( ) + ( offset * 60 * 60 * 1000 ) ) ;
308
+ const _cur = new Date ( date ) . setTime ( new Date ( date ) . getTime ( ) + ( offset * 60 * 60 * 1000 ) ) ;
309
309
return getFullTime ( new Date ( _cur ) , padZeroEnabled ) ;
310
310
}
311
311
@@ -316,9 +316,9 @@ function setDateHours(v, offset, padZeroEnabled = true) {
316
316
* @param {Boolean } padZeroEnabled
317
317
* @returns {String } yyyy-MM-dd HH:mm:ss
318
318
*/
319
- function setDateMinutes ( v , offset , padZeroEnabled = true ) {
319
+ function setDateMinutes ( v , offset , padZeroEnabled = true ) {
320
320
const date = dateFormat ( v ) ;
321
- const _cur = new Date ( date ) . setTime ( new Date ( date ) . getTime ( ) + ( offset * 60 * 1000 ) ) ;
321
+ const _cur = new Date ( date ) . setTime ( new Date ( date ) . getTime ( ) + ( offset * 60 * 1000 ) ) ;
322
322
return getFullTime ( new Date ( _cur ) , padZeroEnabled ) ;
323
323
}
324
324
/**
@@ -328,9 +328,9 @@ function setDateHours(v, offset, padZeroEnabled = true) {
328
328
* @param {Boolean } padZeroEnabled
329
329
* @returns {String } yyyy-MM-dd HH:mm:ss
330
330
*/
331
- function setDateDays ( v , offset , padZeroEnabled = true ) {
331
+ function setDateDays ( v , offset , padZeroEnabled = true ) {
332
332
const date = dateFormat ( v ) ;
333
- const _cur = new Date ( date ) . setTime ( new Date ( date ) . getTime ( ) + ( offset * 24 * 60 * 60 * 1000 ) ) ;
333
+ const _cur = new Date ( date ) . setTime ( new Date ( date ) . getTime ( ) + ( offset * 24 * 60 * 60 * 1000 ) ) ;
334
334
return getFullTime ( new Date ( _cur ) , padZeroEnabled ) ;
335
335
}
336
336
@@ -360,7 +360,7 @@ module.exports = {
360
360
getCurrentMonth,
361
361
getCurrentYear,
362
362
getCurrentDate,
363
-
363
+
364
364
// next & previous
365
365
getTomorrowDate,
366
366
getYesterdayDate,
0 commit comments