@yoooloo42/bean 1.0.33 → 1.0.35

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
@@ -4175,83 +4175,196 @@ var GBT = {
4175
4175
  gbt4658
4176
4176
  };
4177
4177
 
4178
- /**
4179
- * 将Date对象格式化为指定的字符串格式
4180
- *
4181
- * @param {Date} date - 要格式化的日期对象
4182
- * @param {string} format - 目标格式字符串,例如:"yyyy年MM月dd日", "yyyy/MM/dd HH:mm:ss", "MM-dd HH:mm"
4183
- * @returns {string} 格式化后的日期字符串
4184
- */
4185
- function dateFormat(date, format) {
4186
- let result = '';
4187
- if(!date){
4188
- return ''
4178
+ var busicode = {
4179
+ method: [
4180
+ {"code": "0", "text": "日结"},
4181
+ {"code": "1", "text": "小时"},
4182
+ {"code": "2", "text": "月结"}
4183
+ ]
4184
+ };
4185
+
4186
+ // 计算天数(计价单位数)
4187
+ function days$1({
4188
+ checkin, // 入住时间
4189
+ checkout, // 离开时间
4190
+ method_code = '0', // 计价方法
4191
+ timepoint_hours = 14, // 结算时点
4192
+ timepoint_minutes = 0,
4193
+ timepoint2_hours = 18, // 第二时点
4194
+ timepoint2_minutes = 0
4195
+ }){
4196
+ let count = 0; // 计算天数(计价单位数)
4197
+
4198
+ //时段错误
4199
+ if (checkout <= checkin){
4200
+ return 1; // 至少计价1天(1个计价单位)
4189
4201
  }
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
4202
 
4206
- // 替换年份 'yyyy'
4207
- if (/(y+)/.test(format0)) {
4208
- result = format0.replace(RegExp.$1, (Date0.getFullYear() + "").substr(4 - RegExp.$1.length));
4209
- }
4203
+ if (method_code === "0"){ // 日结
4204
+ //结算时点
4205
+ let checkin0 = new Date(checkin.toDateString()),
4206
+ checkout0 = new Date(checkout.toDateString());
4210
4207
 
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
- }
4208
+ if (checkin0 === checkout0){ // 当日不考虑结算时点
4209
+ return 1;
4210
+ }
4216
4211
 
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)));
4212
+ // 天数
4213
+ count = Math.round((checkout0 - checkin0) / (1000 * 60 * 60 * 24));
4214
+
4215
+ // 半天计价
4216
+ if (
4217
+ (
4218
+ (checkout.getHours() > timepoint_hours) ||
4219
+ (
4220
+ checkout.getHours() === timepoint_hours &&
4221
+ checkout.getMinutes() > timepoint_minutes
4222
+ )
4223
+ ) && (
4224
+ (checkout.getHours() <= timepoint2_hours) ||
4225
+ (
4226
+ checkout.getHours() === timepoint2_hours &&
4227
+ checkout.getMinutes() <= timepoint2_minutes
4228
+ )
4229
+ )
4230
+ ){
4231
+ count = count + 0.5;
4232
+ }else if(
4233
+ (checkout.getHours() > timepoint2_hours) ||
4234
+ (
4235
+ checkout.getHours() === timepoint2_hours &&
4236
+ checkout.getMinutes() > timepoint2_minutes
4237
+ )
4238
+ ){
4239
+ count = count + 1;
4224
4240
  }
4241
+
4242
+ // 至少 1 天
4243
+ count = (count < 1) ? 1 : count;
4244
+ }else if(method_code === "1"){ // 小时
4245
+ count = Math.round((checkout - checkin) / (1000 * 60 * 60)); // 小时数
4246
+ count = (count <= 0) ? 1 : count; // 至少 1 小时
4247
+ }else if(method_code === "2"){ // 月结
4248
+ let c = (checkout.getFullYear() - checkin.getFullYear()) * 12,
4249
+ c0 = (checkout.getMonth() >= checkin.getMonth())
4250
+ ? (checkout.getMonth() - checkin.getMonth())
4251
+ : (12 - checkin.getMonth + checkout.getMonth());
4252
+
4253
+ count = c + c0 >= 1 ? c + c0 : 1; // 至少 1 个月
4225
4254
  }
4226
4255
 
4227
- return result;
4256
+ return count;
4257
+ }
4258
+
4259
+ // 单房计价
4260
+ function calculator({
4261
+ price,
4262
+ checkin, // 入住时间
4263
+ checkout, // 离开时间
4264
+ method_code = '0', // 计价方法
4265
+ timepoint_hours = 14, // 结算时点
4266
+ timepoint_minutes = 0,
4267
+ timepoint2_hours = 18, // 第二时点
4268
+ timepoint2_minutes = 0
4269
+ }){
4270
+ const count = days$1({
4271
+ checkin,
4272
+ checkout,
4273
+ method_code,
4274
+ timepoint_hours,
4275
+ timepoint_minutes,
4276
+ timepoint2_hours,
4277
+ timepoint2_minutes
4278
+ });
4279
+
4280
+ return price * count
4228
4281
  }
4229
4282
 
4283
+ var calculator$1 = {
4284
+ days: days$1,
4285
+ calculator
4286
+ };
4287
+
4288
+ var ly0d4 = {
4289
+ busicode,
4290
+ calculator: calculator$1
4291
+ };
4292
+
4230
4293
  /**
4231
- * 计算两个日期之间相差的天数
4294
+ * 将Date对象格式化为指定的字符串格式
4232
4295
  *
4233
- * @param {Date} dateFrom - 开始日期 (Date 对象)
4234
- * @param {Date} dateTo - 结束日期 (Date 对象)
4235
- * @returns {number | null} 相差的天数(向下取整)。如果日期无效,则返回 null。
4236
- * 结果为正数表示 dateTo 在 dateFrom 之后;负数表示 dateFrom 在 dateTo 之后。
4296
+ * @param {Date} d - 要格式化的日期对象
4297
+ * @param {string} f - 目标格式字符串,例如:"yyyy年MM月dd日", "yyyy/MM/dd HH:mm:ss", "MM-dd HH:mm"
4298
+ * @returns {string} 格式化后的日期字符串
4237
4299
  */
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;
4300
+ function dateFormat(d, f){
4301
+ if(! d){ return "" }
4302
+ let d0 = new Date(d), d1 = "", f0 = f || "";
4303
+
4304
+ let year = d0.getFullYear();
4305
+ let year0 = "" + year;
4306
+ let month = d0.getMonth() + 1;
4307
+ let month0 = "" + month;
4308
+ let month1= month < 10 ? "0" + month0 : month0;
4309
+ let date = d0.getDate();
4310
+ let date0 = "" + date;
4311
+ let date1= date < 10 ? "0" + date0 : date0;
4312
+ let hours = d0.getHours();
4313
+ let hours0 = "" + hours;
4314
+ let hours1= hours < 10 ? "0" + hours0 : hours0;
4315
+ let minutes = d0.getMinutes();
4316
+ let minutes0 = "" + minutes;
4317
+ let minutes1= minutes < 10 ? "0" + minutes0 : minutes0;
4318
+
4319
+ switch(f0){
4320
+ case "yyyy年MM月dd日" :
4321
+ d1 = year0 + "年" + month1 + "月" + date1 + "日";
4322
+ break;
4323
+ case "yyyy年M月d日" :
4324
+ d1 = year0 + "年" + month0 + "月" + date0 + "日";
4325
+ break;
4326
+ case "yyyy-MM-dd" :
4327
+ d1 = year0 + "-" + month1 + "-" + date1;
4328
+ break;
4329
+ case "yyyy-M-d" :
4330
+ d1 = year0 + "-" + month0 + "-" + date0;
4331
+ break;
4332
+ case "yyyy/MM/dd" :
4333
+ d1 = year0 + "/" + month1 + "/" + date1;
4334
+ break;
4335
+ case "yyyy/M/d" :
4336
+ d1 = year0 + "/" + month0 + "/" + date0;
4337
+ break;
4338
+ case "yyyy/MM/dd HH:mm" :
4339
+ d1 = year0 + "/" + month1 + "/" + date1
4340
+ + " " + hours1 + ":" + minutes1;
4341
+ break;
4342
+ case "yyyy/M/d H:m" :
4343
+ d1 = year0 + "/" + month0 + "/" + date0
4344
+ + " " + hours0 + ":" + minutes0;
4345
+ break;
4346
+ default :
4347
+ d1 = year0 + "/" + month1 + "/" + date1
4348
+ + " " + hours1 + ":" + minutes1;
4349
+ }
4249
4350
 
4250
- // 4. 将毫秒差值转换为天数
4251
- // Math.floor() 用于向下取整,确保得到完整的经过天数
4252
- const dayDifference = Math.floor(timeDifference / msPerDay);
4351
+ return d1;
4352
+ }
4253
4353
 
4254
- return dayDifference;
4354
+ /**
4355
+ * 计算两个日期之间相差的天数
4356
+ *
4357
+ * @param {Date} dFrom - 开始日期 (Date 对象)
4358
+ * @param {Date} dTo - 截止日期 (Date 对象)
4359
+ * @returns {number} 相差的天数
4360
+ */
4361
+ function days(dFrom, dTo){
4362
+ let dFrom0 = new Date(new Date(dFrom).toDateString ());
4363
+ let dTo0 = new Date(new Date(dTo).toDateString ());
4364
+ if(dFrom0 >= dTo0){
4365
+ return 0
4366
+ }
4367
+ return Math.floor((dTo0 - dFrom0)/(1000 * 60 * 60 * 24)) + 1;
4255
4368
  }
4256
4369
  var dateFormat$1 = {
4257
4370
  dateFormat,
@@ -5311,10 +5424,12 @@ var unclassified = {
5311
5424
 
5312
5425
  var index = {
5313
5426
  GBT,
5427
+ ly0d4,
5314
5428
  unclassified
5315
5429
  };
5316
5430
 
5317
5431
  exports.GBT = GBT;
5318
5432
  exports.default = index;
5433
+ exports.ly0d4 = ly0d4;
5319
5434
  exports.unclassified = unclassified;
5320
5435
  //# sourceMappingURL=index.cjs.js.map