File tree 2 files changed +45
-4
lines changed
2 files changed +45
-4
lines changed Original file line number Diff line number Diff line change 1
1
/**
2
- * Get current date
2
+ * Get date details
3
3
*/
4
- export type JSON = string ;
4
+ export type JSON = any ;
5
5
/**
6
6
* The check string contains only hours, minutes, and seconds
7
7
* @returns {Boolean }
@@ -25,6 +25,20 @@ export function padZero(num: number, padZeroEnabled?: boolean): string;
25
25
* @returns {String } yyyy-MM-dd
26
26
*/
27
27
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
+ } ;
28
42
/**
29
43
* Check if the string is legitimate
30
44
* @param {String } v
@@ -121,7 +135,7 @@ export function getCurrentDay(padZeroEnabled?: boolean): number;
121
135
/**
122
136
* Get current date
123
137
* @param {Boolean } padZeroEnabled
124
- * @typedef {String } JSON
138
+ * @typedef {Object } JSON
125
139
*/
126
140
export function getCurrentDate ( padZeroEnabled ?: boolean ) : {
127
141
today : string ;
Original file line number Diff line number Diff line change @@ -110,6 +110,32 @@ function dateFormat(v) {
110
110
return date ;
111
111
}
112
112
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
+
113
139
114
140
/**
115
141
* Get calendar date
@@ -334,7 +360,7 @@ function getFirstAndLastMonthDay(year, padZeroEnabled = true) {
334
360
/**
335
361
* Get current date
336
362
* @param {Boolean } padZeroEnabled
337
- * @typedef {String } JSON
363
+ * @typedef {Object } JSON
338
364
*/
339
365
function getCurrentDate ( padZeroEnabled = true ) {
340
366
@@ -450,6 +476,7 @@ export {
450
476
getNow ,
451
477
padZero ,
452
478
dateFormat ,
479
+ getDateDetails ,
453
480
454
481
//
455
482
isValidDate ,
You can’t perform that action at this time.
0 commit comments