@yoooloo42/bean 1.0.33 → 1.0.34

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.
package/dist/index.cjs.js CHANGED
@@ -4178,80 +4178,78 @@ var GBT = {
4178
4178
  /**
4179
4179
  * 将Date对象格式化为指定的字符串格式
4180
4180
  *
4181
- * @param {Date} date - 要格式化的日期对象
4182
- * @param {string} format - 目标格式字符串,例如:"yyyy年MM月dd日", "yyyy/MM/dd HH:mm:ss", "MM-dd HH:mm"
4181
+ * @param {Date} d - 要格式化的日期对象
4182
+ * @param {string} f - 目标格式字符串,例如:"yyyy年MM月dd日", "yyyy/MM/dd HH:mm:ss", "MM-dd HH:mm"
4183
4183
  * @returns {string} 格式化后的日期字符串
4184
4184
  */
4185
- function dateFormat(date, format) {
4186
- let result = '';
4187
- if(!date){
4188
- return ''
4189
- }
4190
- const format0 = format || 'yyyy/MM/dd HH:mm:ss';
4191
-
4192
- // 有效的 Date 对象一致性
4193
- const Date0 = new Date(date);
4194
-
4195
- const o = {
4196
- 'M+': Date0.getMonth() + 1, // 月份
4197
- 'd+': Date0.getDate(), // 日
4198
- 'h+': Date0.getHours() % 12 === 0 ? 12 : Date0.getHours() % 12, // 12小时制
4199
- 'H+': Date0.getHours(), // 24小时制
4200
- 'm+': Date0.getMinutes(), // 分
4201
- 's+': Date0.getSeconds(), //
4202
- 'q+': Math.floor((Date0.getMonth() + 3) / 3), // 季度
4203
- 'S': Date0.getMilliseconds() // 毫秒
4204
- };
4205
-
4206
- // 替换年份 'yyyy'
4207
- if (/(y+)/.test(format0)) {
4208
- result = format0.replace(RegExp.$1, (Date0.getFullYear() + "").substr(4 - RegExp.$1.length));
4185
+ function dateFormat(d, f){
4186
+ if(! d){ return "" }
4187
+ let d0 = new Date(d), d1 = "", f0 = f || "";
4188
+
4189
+ let year = d0.getFullYear();
4190
+ let year0 = "" + year;
4191
+ let month = d0.getMonth() + 1;
4192
+ let month0 = "" + month;
4193
+ let month1= month < 10 ? "0" + month0 : month0;
4194
+ let date = d0.getDate();
4195
+ let date0 = "" + date;
4196
+ let date1= date < 10 ? "0" + date0 : date0;
4197
+ let hours = d0.getHours();
4198
+ let hours0 = "" + hours;
4199
+ let hours1= hours < 10 ? "0" + hours0 : hours0;
4200
+ let minutes = d0.getMinutes();
4201
+ let minutes0 = "" + minutes;
4202
+ let minutes1= minutes < 10 ? "0" + minutes0 : minutes0;
4203
+
4204
+ switch(f0){
4205
+ case "yyyy年MM月dd日" :
4206
+ d1 = year0 + "年" + month1 + "月" + date1 + "日";
4207
+ break;
4208
+ case "yyyy年M月d日" :
4209
+ d1 = year0 + "年" + month0 + "月" + date0 + "日";
4210
+ break;
4211
+ case "yyyy-MM-dd" :
4212
+ d1 = year0 + "-" + month1 + "-" + date1;
4213
+ break;
4214
+ case "yyyy-M-d" :
4215
+ d1 = year0 + "-" + month0 + "-" + date0;
4216
+ break;
4217
+ case "yyyy/MM/dd" :
4218
+ d1 = year0 + "/" + month1 + "/" + date1;
4219
+ break;
4220
+ case "yyyy/M/d" :
4221
+ d1 = year0 + "/" + month0 + "/" + date0;
4222
+ break;
4223
+ case "yyyy/MM/dd HH:mm" :
4224
+ d1 = year0 + "/" + month1 + "/" + date1
4225
+ + " " + hours1 + ":" + minutes1;
4226
+ break;
4227
+ case "yyyy/M/d H:m" :
4228
+ d1 = year0 + "/" + month0 + "/" + date0
4229
+ + " " + hours0 + ":" + minutes0;
4230
+ break;
4231
+ default :
4232
+ d1 = year0 + "/" + month1 + "/" + date1
4233
+ + " " + hours1 + ":" + minutes1;
4209
4234
  }
4210
4235
 
4211
- // 替换 'AM/PM'
4212
- if (/(A|a)/.test(format0)) {
4213
- const ampm = Date0.getHours() < 12 ? 'AM' : 'PM';
4214
- result = format0.replace(RegExp.$1, RegExp.$1 === 'a' ? ampm.toLowerCase() : ampm);
4215
- }
4216
-
4217
- // 替换其他时间单位 'MM', 'dd', 'HH' 等
4218
- for (let k in o) {
4219
- if (new RegExp("(" + k + ")").test(format0)) {
4220
- const value = o[k];
4221
- // $1 匹配到的字符串,例如 'MM'
4222
- // 如果是毫秒 'S',则不补零
4223
- result = format0.replace(RegExp.$1, (RegExp.$1.length === 1) ? (value) : (("00" + value).substr(("" + value).length)));
4224
- }
4225
- }
4226
-
4227
- return result;
4236
+ return d1;
4228
4237
  }
4229
4238
 
4230
4239
  /**
4231
4240
  * 计算两个日期之间相差的天数
4232
4241
  *
4233
- * @param {Date} dateFrom - 开始日期 (Date 对象)
4234
- * @param {Date} dateTo - 结束日期 (Date 对象)
4235
- * @returns {number | null} 相差的天数(向下取整)。如果日期无效,则返回 null。
4236
- * 结果为正数表示 dateTo 在 dateFrom 之后;负数表示 dateFrom 在 dateTo 之后。
4242
+ * @param {Date} dFrom - 开始日期 (Date 对象)
4243
+ * @param {Date} dTo - 截止日期 (Date 对象)
4244
+ * @returns {number} 相差的天数
4237
4245
  */
4238
- function days(dateFrom, dateTo) {
4239
- // 1. 有效的 Date 对象一致性
4240
- const DateFrom0 = new Date(dateFrom);
4241
- const DateTo0 = new Date(dateTo);
4242
-
4243
- // 2. 计算两个日期的时间戳差值 (毫秒)
4244
- // Date.getTime() 返回从 1970 1 1 00:00:00 UTC 至今的毫秒数
4245
- const timeDifference = DateTo0.getTime() - DateFrom0.getTime();
4246
-
4247
- // 3. 定义一天对应的毫秒数
4248
- const msPerDay = 1000 * 60 * 60 * 24;
4249
-
4250
- // 4. 将毫秒差值转换为天数
4251
- // Math.floor() 用于向下取整,确保得到完整的经过天数
4252
- const dayDifference = Math.floor(timeDifference / msPerDay);
4253
-
4254
- return dayDifference;
4246
+ function days(dFrom, dTo){
4247
+ let dFrom0 = new Date(new Date(dFrom).toDateString ());
4248
+ let dTo0 = new Date(new Date(dTo).toDateString ());
4249
+ if(dFrom0 >= dTo0){
4250
+ return 0
4251
+ }
4252
+ return Math.floor((dTo0 - dFrom0)/(1000 * 60 * 60 * 24)) + 1;
4255
4253
  }
4256
4254
  var dateFormat$1 = {
4257
4255
  dateFormat,