Skip to content

Commit b72bbb1

Browse files
committed
update utils doc
1 parent 63fc99b commit b72bbb1

File tree

2 files changed

+46
-46
lines changed

2 files changed

+46
-46
lines changed

src/utils/libs/date.d.ts

+10-10
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export function isValidDate(v: string): boolean;
1212
* Get last day in month
1313
* @param {Date | String} v
1414
* @param {?Number} targetMonth
15-
* @returns {String} YYYY-MM-DD
15+
* @returns {String} yyyy-MM-dd
1616
*/
1717
export function getLastDayInMonth(v: Date | string, targetMonth?: number | null): string;
1818
/**
@@ -26,7 +26,7 @@ export function getFirstAndLastMonthDay(year: any, padZeroEnabled?: boolean): an
2626
* Get calendar date
2727
* @param {Date | String} v
2828
* @param {Boolean} padZeroEnabled
29-
* @returns {String} YYYY-MM-DD
29+
* @returns {String} yyyy-MM-dd
3030
*/
3131
export function getCalendarDate(v: Date | string, padZeroEnabled?: boolean): string;
3232
/**
@@ -39,7 +39,7 @@ export function getCalendarDate(v: Date | string, padZeroEnabled?: boolean): str
3939
export function getFullTime(v: Date | string, padZeroEnabled?: boolean, hasSeconds?: boolean): string;
4040
/**
4141
* Get today date
42-
* @returns {String} YYYY-MM-DD
42+
* @returns {String} yyyy-MM-dd
4343
*/
4444
export function getTodayDate(): string;
4545
/**
@@ -66,44 +66,44 @@ export function getCurrentDate(padZeroEnabled?: boolean): {
6666
/**
6767
* Get tomorrow date
6868
* @param {Date | String} v
69-
* @returns {String} YYYY-MM-DD
69+
* @returns {String} yyyy-MM-dd
7070
*/
7171
export function getTomorrowDate(v: Date | string): string;
7272
/**
7373
* Get yesterday date
7474
* @param {Date | String} v
75-
* @returns {String} YYYY-MM-DD
75+
* @returns {String} yyyy-MM-dd
7676
*/
7777
export function getYesterdayDate(v: Date | string): string;
7878
/**
7979
* Get next month date
8080
* @param {Date | String} v
81-
* @returns {String} YYYY-MM-DD
81+
* @returns {String} yyyy-MM-dd
8282
*/
8383
export function getNextMonthDate(v: Date | string): string;
8484
/**
8585
* Get previous month date
8686
* @param {Date | String} v
87-
* @returns {String} YYYY-MM-DD
87+
* @returns {String} yyyy-MM-dd
8888
*/
8989
export function getPrevMonthDate(v: Date | string): string;
9090
/**
9191
* Get next year date
9292
* @param {Date | String} v
93-
* @returns {String} YYYY-MM-DD
93+
* @returns {String} yyyy-MM-dd
9494
*/
9595
export function getNextYearDate(v: Date | string): string;
9696
/**
9797
* Get previous year date
9898
* @param {Date | String} v
99-
* @returns {String} YYYY-MM-DD
99+
* @returns {String} yyyy-MM-dd
100100
*/
101101
export function getPrevYearDate(v: Date | string): string;
102102
/**
103103
* Get specified date
104104
* @param {Date | String} v
105105
* @param {Number} days The number of days forward or backward, which can be a negative number
106-
* @returns {String} YYYY-MM-DD
106+
* @returns {String} yyyy-MM-dd
107107
*/
108108
export function getSpecifiedDate(v: Date | string, days: number): string;
109109
/**

src/utils/libs/date.js

+36-36
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ const isValidDate = (v) => {
1212
/**
1313
* Get calendar date
1414
* @param {Date | String} v
15-
* @returns {String} YYYY-MM-DD
15+
* @returns {String} yyyy-MM-dd
1616
*/
1717
function dateFormat(v) {
1818
const date = typeof v === 'string' ? new Date(v.replace(/-/g, "/")) : v; // fix "Invalid date in safari"
@@ -24,10 +24,10 @@ function dateFormat(v) {
2424
* Get calendar date
2525
* @param {Date | String} v
2626
* @param {Boolean} padZeroEnabled
27-
* @returns {String} YYYY-MM-DD
27+
* @returns {String} yyyy-MM-dd
2828
*/
2929
function getCalendarDate(v, padZeroEnabled = true) {
30-
30+
3131
const date = dateFormat(v);
3232
const padZero = (num) => {
3333
if (padZeroEnabled) {
@@ -50,10 +50,10 @@ function getCalendarDate(v, padZeroEnabled = true) {
5050

5151
/**
5252
* Get today date
53-
* @returns {String} YYYY-MM-DD
53+
* @returns {String} yyyy-MM-dd
5454
*/
5555
function getTodayDate() {
56-
56+
5757
return getCalendarDate(new Date());
5858
}
5959

@@ -62,10 +62,10 @@ function getTodayDate() {
6262
/**
6363
* Get tomorrow date
6464
* @param {Date | String} v
65-
* @returns {String} YYYY-MM-DD
65+
* @returns {String} yyyy-MM-dd
6666
*/
6767
function getTomorrowDate(v) {
68-
68+
6969
const today = dateFormat(v);
7070
const _tomorrow = today;
7171
_tomorrow.setDate(_tomorrow.getDate() + 1);
@@ -77,10 +77,10 @@ function getTomorrowDate(v) {
7777
/**
7878
* Get yesterday date
7979
* @param {Date | String} v
80-
* @returns {String} YYYY-MM-DD
80+
* @returns {String} yyyy-MM-dd
8181
*/
8282
function getYesterdayDate(v) {
83-
83+
8484
const today = dateFormat(v);
8585
const _yesterday = today;
8686
_yesterday.setDate(_yesterday.getDate() - 1);
@@ -92,11 +92,11 @@ function getYesterdayDate(v) {
9292
* Get specified date
9393
* @param {Date | String} v
9494
* @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
9696
*/
9797
/* console.log(getSpecifiedDate(getTodayDate(), -180)); // 2023-08-27 (180 days before February 23, 202) */
9898
function getSpecifiedDate(v, days) {
99-
99+
100100
const today = dateFormat(v);
101101
const _specifiedDay = today;
102102
_specifiedDay.setDate(_specifiedDay.getDate() + days);
@@ -109,27 +109,27 @@ function getSpecifiedDate(v, days) {
109109
/**
110110
* Get next month date
111111
* @param {Date | String} v
112-
* @returns {String} YYYY-MM-DD
112+
* @returns {String} yyyy-MM-dd
113113
*/
114114
function getNextMonthDate(v) {
115-
115+
116116
const today = dateFormat(v);
117-
today.setMonth(today.getMonth()+1);
118-
117+
today.setMonth(today.getMonth() + 1);
118+
119119
return getCalendarDate(today);
120120
}
121121

122122

123123
/**
124124
* Get previous month date
125125
* @param {Date | String} v
126-
* @returns {String} YYYY-MM-DD
126+
* @returns {String} yyyy-MM-dd
127127
*/
128128
function getPrevMonthDate(v) {
129-
129+
130130
const today = dateFormat(v);
131-
today.setMonth(today.getMonth()-1);
132-
131+
today.setMonth(today.getMonth() - 1);
132+
133133
return getCalendarDate(today);
134134
}
135135

@@ -138,29 +138,29 @@ function getPrevMonthDate(v) {
138138
/**
139139
* Get next year date
140140
* @param {Date | String} v
141-
* @returns {String} YYYY-MM-DD
141+
* @returns {String} yyyy-MM-dd
142142
*/
143143
function getNextYearDate(v) {
144-
144+
145145
const today = dateFormat(v);
146146
const current = new Date(today);
147147
current.setFullYear(current.getFullYear() + 1);
148-
148+
149149
return getCalendarDate(current);
150150
}
151151

152152

153153
/**
154154
* Get previous year date
155155
* @param {Date | String} v
156-
* @returns {String} YYYY-MM-DD
156+
* @returns {String} yyyy-MM-dd
157157
*/
158158
function getPrevYearDate(v) {
159-
159+
160160
const today = dateFormat(v);
161161
const current = new Date(today);
162162
current.setFullYear(current.getFullYear() - 1);
163-
163+
164164
return getCalendarDate(current);
165165
}
166166

@@ -171,7 +171,7 @@ function getPrevYearDate(v) {
171171
* Get last day in month
172172
* @param {Date | String} v
173173
* @param {?Number} targetMonth
174-
* @returns {String} YYYY-MM-DD
174+
* @returns {String} yyyy-MM-dd
175175
*/
176176
/*
177177
Example: Get last day in next month
@@ -186,7 +186,7 @@ const lastDayOfNextMonth = `${y}-${m}-${d}`; // 2024-02-29
186186
*/
187187
function getLastDayInMonth(v, targetMonth = undefined) {
188188
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();
190190
}
191191

192192

@@ -239,7 +239,7 @@ function getFirstAndLastMonthDay(year, padZeroEnabled = true) {
239239
* @typedef {String} JSON
240240
*/
241241
function getCurrentDate(padZeroEnabled = true) {
242-
242+
243243
const date = new Date();
244244
const padZero = (num) => {
245245
if (padZeroEnabled) {
@@ -272,7 +272,7 @@ function getCurrentDate(padZeroEnabled = true) {
272272
* @returns {String} yyyy-MM-dd HH:mm:ss
273273
*/
274274
function getFullTime(v, padZeroEnabled = true, hasSeconds = true) {
275-
275+
276276
const date = dateFormat(v);
277277
const padZero = (num) => {
278278
if (padZeroEnabled) {
@@ -290,7 +290,7 @@ function getFullTime(v, padZeroEnabled = true, hasSeconds = true) {
290290
const seconds = padZero(date.getSeconds());
291291
const res = `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
292292
const res2 = `${year}-${month}-${day} ${hours}:${minutes}`;
293-
293+
294294
return hasSeconds ? res : res2;
295295
}
296296

@@ -305,7 +305,7 @@ function getFullTime(v, padZeroEnabled = true, hasSeconds = true) {
305305
*/
306306
function setDateHours(v, offset, padZeroEnabled = true) {
307307
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));
309309
return getFullTime(new Date(_cur), padZeroEnabled);
310310
}
311311

@@ -316,9 +316,9 @@ function setDateHours(v, offset, padZeroEnabled = true) {
316316
* @param {Boolean} padZeroEnabled
317317
* @returns {String} yyyy-MM-dd HH:mm:ss
318318
*/
319-
function setDateMinutes(v, offset, padZeroEnabled = true) {
319+
function setDateMinutes(v, offset, padZeroEnabled = true) {
320320
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));
322322
return getFullTime(new Date(_cur), padZeroEnabled);
323323
}
324324
/**
@@ -328,9 +328,9 @@ function setDateHours(v, offset, padZeroEnabled = true) {
328328
* @param {Boolean} padZeroEnabled
329329
* @returns {String} yyyy-MM-dd HH:mm:ss
330330
*/
331-
function setDateDays(v, offset, padZeroEnabled = true) {
331+
function setDateDays(v, offset, padZeroEnabled = true) {
332332
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));
334334
return getFullTime(new Date(_cur), padZeroEnabled);
335335
}
336336

@@ -360,7 +360,7 @@ module.exports = {
360360
getCurrentMonth,
361361
getCurrentYear,
362362
getCurrentDate,
363-
363+
364364
// next & previous
365365
getTomorrowDate,
366366
getYesterdayDate,

0 commit comments

Comments
 (0)