Skip to content

Commit ff4682f

Browse files
committed
update date toolbox
1 parent 702a73f commit ff4682f

File tree

2 files changed

+45
-4
lines changed

2 files changed

+45
-4
lines changed

src/utils/libs/date.d.ts

+17-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
2-
* Get current date
2+
* Get date details
33
*/
4-
export type JSON = string;
4+
export type JSON = any;
55
/**
66
* The check string contains only hours, minutes, and seconds
77
* @returns {Boolean}
@@ -25,6 +25,20 @@ export function padZero(num: number, padZeroEnabled?: boolean): string;
2525
* @returns {String} yyyy-MM-dd
2626
*/
2727
export function dateFormat(v: Date | string): string;
28+
/**
29+
* Get date details
30+
* @param {Date | String} v
31+
* @param {Boolean} padZeroEnabled
32+
* @typedef {Object} JSON
33+
*/
34+
export function getDateDetails(v: Date | string, padZeroEnabled?: boolean): {
35+
year: string;
36+
month: string;
37+
day: string;
38+
hours: string;
39+
minutes: string;
40+
seconds: string;
41+
};
2842
/**
2943
* Check if the string is legitimate
3044
* @param {String} v
@@ -121,7 +135,7 @@ export function getCurrentDay(padZeroEnabled?: boolean): number;
121135
/**
122136
* Get current date
123137
* @param {Boolean} padZeroEnabled
124-
* @typedef {String} JSON
138+
* @typedef {Object} JSON
125139
*/
126140
export function getCurrentDate(padZeroEnabled?: boolean): {
127141
today: string;

src/utils/libs/date.js

+28-1
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,32 @@ function dateFormat(v) {
110110
return date;
111111
}
112112

113+
/**
114+
* Get date details
115+
* @param {Date | String} v
116+
* @param {Boolean} padZeroEnabled
117+
* @typedef {Object} JSON
118+
*/
119+
function getDateDetails(v, padZeroEnabled = true) {
120+
121+
const date = dateFormat(v);
122+
const year = date.getFullYear();
123+
const month = padZero(date.getMonth() + 1, padZeroEnabled);
124+
const day = padZero(date.getDate(), padZeroEnabled);
125+
const hours = padZero(date.getHours(), padZeroEnabled);
126+
const minutes = padZero(date.getMinutes(), padZeroEnabled);
127+
const seconds = padZero(date.getSeconds(), padZeroEnabled);
128+
129+
return {
130+
year: String(year),
131+
month,
132+
day,
133+
hours,
134+
minutes,
135+
seconds
136+
};
137+
}
138+
113139

114140
/**
115141
* Get calendar date
@@ -334,7 +360,7 @@ function getFirstAndLastMonthDay(year, padZeroEnabled = true) {
334360
/**
335361
* Get current date
336362
* @param {Boolean} padZeroEnabled
337-
* @typedef {String} JSON
363+
* @typedef {Object} JSON
338364
*/
339365
function getCurrentDate(padZeroEnabled = true) {
340366

@@ -450,6 +476,7 @@ export {
450476
getNow,
451477
padZero,
452478
dateFormat,
479+
getDateDetails,
453480

454481
//
455482
isValidDate,

0 commit comments

Comments
 (0)