xctc-utils 1.5.6 → 1.5.8

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.
@@ -22,7 +22,7 @@ export declare function formatStrTime(str: string): any;
22
22
  * @returns
23
23
  */
24
24
  export declare function getDateData(value: string | number, format?: string): {
25
- year: number;
25
+ year: string | number;
26
26
  month: string | number;
27
27
  day: string | number;
28
28
  hour: string | number;
@@ -31,7 +31,7 @@ export declare function getDateData(value: string | number, format?: string): {
31
31
  num: any;
32
32
  };
33
33
  export declare function findIdcardAge(idcard: string): {
34
- year: number;
34
+ year: string | number;
35
35
  month: string | number;
36
36
  day: string | number;
37
37
  hour: string | number;
@@ -95,73 +95,79 @@ exports.formatStrTime = formatStrTime;
95
95
  */
96
96
  function getDateData(value, format) {
97
97
  var now = new Date();
98
+ var year = "";
99
+ var month = "";
100
+ var day = "";
101
+ var hour = "";
102
+ var minute = "";
103
+ var second = "";
98
104
  if (typeof value == 'number') {
99
105
  now = new Date(value * 1000);
106
+ year = now.getFullYear();
107
+ month = now.getMonth() + 1;
108
+ month = month < 10 ? "0" + month : month;
109
+ day = now.getDate();
110
+ day = day < 10 ? "0" + day : day;
111
+ hour = now.getHours();
112
+ hour = hour < 10 ? "0" + hour : hour;
113
+ minute = now.getMinutes();
114
+ minute = minute < 10 ? "0" + minute : minute;
115
+ second = now.getSeconds();
116
+ second = second < 10 ? "0" + second : second;
100
117
  }
101
118
  if (typeof value == "string") {
102
119
  if (!format)
103
120
  format = "YYYY-MM-DD HH:mm:ss";
104
- var year_1 = value.substring(0, 4);
105
- var str = "".concat(year_1);
121
+ year = value.substring(0, 4);
122
+ var str = "".concat(year);
106
123
  var monthIndex = format.indexOf("MM");
107
- var month_1 = "";
108
124
  if (monthIndex != -1) {
109
- month_1 = value.substring(monthIndex, monthIndex + 3);
110
- str = "".concat(str, "/").concat(month_1);
125
+ month = value.substring(monthIndex, monthIndex + 3);
126
+ str = "".concat(str, "/").concat(month);
111
127
  }
112
128
  else {
129
+ month = "01";
113
130
  str = "".concat(str, "/01");
114
131
  }
115
132
  var dayIndex = format.indexOf("DD");
116
- var day_1 = "";
117
133
  if (dayIndex != -1) {
118
- day_1 = value.substring(dayIndex, dayIndex + 3);
119
- str = "".concat(str, "/").concat(day_1);
134
+ day = value.substring(dayIndex, dayIndex + 3);
135
+ str = "".concat(str, "/").concat(day);
120
136
  }
121
137
  else {
138
+ day = "01";
122
139
  str = "".concat(str, "/01");
123
140
  }
124
141
  var hourIndex = format.indexOf("HH");
125
- var hour_1 = "";
126
142
  if (hourIndex != -1) {
127
- hour_1 = value.substring(hourIndex, hourIndex + 3);
128
- str = "".concat(str, " ").concat(hour_1);
143
+ hour = value.substring(hourIndex, hourIndex + 3);
144
+ str = "".concat(str, " ").concat(hour);
129
145
  }
130
146
  else {
147
+ hour = "00";
131
148
  str = "".concat(str, " 00");
132
149
  }
133
150
  var minuteIndex = format.indexOf("mm");
134
- var minute_1 = "";
135
151
  if (hourIndex != -1) {
136
- minute_1 = value.substring(minuteIndex, minuteIndex + 3);
137
- str = "".concat(str, ":").concat(minute_1);
152
+ minute = value.substring(minuteIndex, minuteIndex + 3);
153
+ str = "".concat(str, ":").concat(minute);
138
154
  }
139
155
  else {
156
+ minute = "00";
140
157
  str = "".concat(str, ":00");
141
158
  }
142
159
  var secondIndex = format.indexOf("ss");
143
- var second_1 = "";
144
160
  if (hourIndex != -1) {
145
- second_1 = value.substring(secondIndex, secondIndex + 3);
146
- str = "".concat(str, ":").concat(second_1);
161
+ second = value.substring(secondIndex, secondIndex + 3);
162
+ str = "".concat(str, ":").concat(second);
147
163
  }
148
164
  else {
149
- str = "".concat(str, ":00");
165
+ second = "01";
166
+ str = "".concat(str, ":01");
150
167
  }
151
168
  now = new Date(str);
152
169
  }
153
- var year = now.getFullYear();
154
- var month = now.getMonth() + 1;
155
- month = month < 10 ? "0" + month : month;
156
- var day = now.getDate();
157
- day = day < 10 ? "0" + day : day;
158
- var hour = now.getHours();
159
- hour = hour < 10 ? "0" + hour : hour;
160
- var minute = now.getMinutes();
161
- minute = minute < 10 ? "0" + minute : minute;
162
- var second = now.getSeconds();
163
- second = second < 10 ? "0" + second : second;
164
- var nowNumber = new Date().getTime() / 1000;
170
+ var nowNumber = now.getTime() / 1000;
165
171
  nowNumber = parseInt(nowNumber);
166
172
  return {
167
173
  year: year,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "xctc-utils",
3
- "version": "1.5.6",
3
+ "version": "1.5.8",
4
4
  "description": "localStorage存储\r ```\r sessionStorage存储\r ```\r crypto-js加密、解密\r ```\r 微信授权登录、微信分享\r ```\r 设备环境获取\r ```\r 是否是微信浏览器\r ```\r 时间戳转时间,字符串转时间戳",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",