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