turf-common 1.2.1-beta.11 → 1.2.1-beta.12

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.
@@ -9,4 +9,5 @@ export interface IChargeModel {
9
9
  amountPayable: number;
10
10
  totalRefundedAmount: number;
11
11
  couponCode: string;
12
+ totalBookingHours: number;
12
13
  }
@@ -86,4 +86,9 @@ export declare class BookingCode {
86
86
  formatDateAndTime(formateDateAndTime: IFormateDateAndTime): string;
87
87
  static timeFormatter(timeFormatter: ITimeFormatter): string;
88
88
  static dateFormatter(dateFormatter: IDateFormatter): string;
89
+ getTotalTime(unit?: "minute" | "hr"): number;
90
+ getAcrossDateCodes(): {
91
+ fromDateCode: string;
92
+ toDateCode: string;
93
+ };
89
94
  }
@@ -523,6 +523,17 @@ var BookingCode = /** @class */ (function () {
523
523
  var dateFormat = dateFormatter.dateFormat, dateCode = dateFormatter.dateCode;
524
524
  return (0, date_fns_1.format)(BookingCode.convertToDate(dateCode), dateFormat);
525
525
  };
526
+ BookingCode.prototype.getTotalTime = function (unit) {
527
+ if (unit === void 0) { unit = "minute"; }
528
+ return date_util_1.dateUtilService.calculateDateDifference(this.getAcrossDateCodes().fromDateCode, this.getAcrossDateCodes().toDateCode, unit);
529
+ };
530
+ BookingCode.prototype.getAcrossDateCodes = function () {
531
+ var fromDateCode = "".concat(this.dateCode).concat(this.fromTimeCode);
532
+ var toDateCode = "".concat(this.fromTimeCode > this.toTimeCode
533
+ ? date_util_1.dateUtilService.addNDaysToDateCode(this.dateCode, 1)
534
+ : this.dateCode).concat(this.toTimeCode);
535
+ return { fromDateCode: fromDateCode, toDateCode: toDateCode };
536
+ };
526
537
  return BookingCode;
527
538
  }());
528
539
  exports.BookingCode = BookingCode;
@@ -11,9 +11,10 @@ export declare class ChargesModel implements IChargeModel {
11
11
  amountPaid: number;
12
12
  amountPayable: number;
13
13
  totalRefundedAmount: number;
14
+ totalBookingHours: number;
14
15
  couponCode: string;
15
16
  discountPolicy: ModificationDiscountPolicy;
16
- constructor(initialGrossAmount: number, paidAmount: number, couponCode: string, discountPolicy: ModificationDiscountPolicy);
17
+ constructor(initialGrossAmount: number, paidAmount: number, couponCode: string, totalBookingHours: number, discountPolicy: ModificationDiscountPolicy);
17
18
  getGrossAmount(): number;
18
19
  getNetAmount(): number;
19
20
  getDiscountAmount(): number;
@@ -4,7 +4,7 @@ exports.ChargesModel = void 0;
4
4
  var app_badrequest_exception_1 = require("../exceptions/app-badrequest.exception");
5
5
  var modification_discount_policy_enum_1 = require("../enums/modification-discount-policy.enum");
6
6
  var ChargesModel = /** @class */ (function () {
7
- function ChargesModel(initialGrossAmount, paidAmount, couponCode, discountPolicy) {
7
+ function ChargesModel(initialGrossAmount, paidAmount, couponCode, totalBookingHours, discountPolicy) {
8
8
  this.initialBookingGrossAmount = initialGrossAmount;
9
9
  this.amountPaid = paidAmount;
10
10
  this.couponCode = couponCode;
@@ -13,6 +13,7 @@ var ChargesModel = /** @class */ (function () {
13
13
  this.totalCancellationCharges = 0;
14
14
  this.refundPayable = 0;
15
15
  this.totalRefundedAmount = 0;
16
+ this.totalBookingHours = totalBookingHours;
16
17
  this.netTotal = this.getNetAmount();
17
18
  this.amountPayable = this.getPayableRefundAmount();
18
19
  this.discountPolicy = discountPolicy;
@@ -33,7 +34,7 @@ var ChargesModel = /** @class */ (function () {
33
34
  this.cancelledBookingGrossAmount > 0) {
34
35
  this.couponCode = "";
35
36
  }
36
- return ChargesModel.getDiscountAmount(this.couponCode, this.getGrossAmount());
37
+ return ChargesModel.getDiscountAmount(this.couponCode, this.getGrossAmount(), false, this.totalBookingHours);
37
38
  };
38
39
  ChargesModel.prototype.getPayableRefundAmount = function () {
39
40
  return (this.getNetAmount() +
@@ -182,7 +183,7 @@ var ChargesModel = /** @class */ (function () {
182
183
  return newChargeModel;
183
184
  };
184
185
  ChargesModel.prototype.clone = function () {
185
- var that = new ChargesModel(this.initialBookingGrossAmount, this.amountPaid, this.couponCode, this.discountPolicy);
186
+ var that = new ChargesModel(this.initialBookingGrossAmount, this.amountPaid, this.couponCode, this.totalBookingHours, this.discountPolicy);
186
187
  Object.assign(that, this);
187
188
  return that;
188
189
  };
@@ -206,7 +207,7 @@ var ChargesModel = /** @class */ (function () {
206
207
  };
207
208
  ChargesModel.getInstance = function (chargeData, discountPolicy) {
208
209
  if (discountPolicy === void 0) { discountPolicy = modification_discount_policy_enum_1.ModificationDiscountPolicy.DISCOUNT_CONDITIONAL; }
209
- var chargesModel = new ChargesModel(chargeData.initialBookingGrossAmount, chargeData.amountPaid, chargeData.couponCode, discountPolicy);
210
+ var chargesModel = new ChargesModel(chargeData.initialBookingGrossAmount, chargeData.amountPaid, chargeData.couponCode, chargeData.totalBookingHours, discountPolicy);
210
211
  Object.assign(chargesModel, chargeData);
211
212
  return chargesModel;
212
213
  };
@@ -12,5 +12,6 @@ export declare class DateUtilService {
12
12
  formatTimeSlotCode(timeSlot: string, both?: boolean, date?: Date | null): string;
13
13
  formatDateCode(dateCode: string): string;
14
14
  getDateNDaysFromToday(n: number): Date;
15
+ calculateDateDifference(fromDateCode: string, toDateCode: string, unit?: "minute" | "hr"): number;
15
16
  }
16
17
  export declare const dateUtilService: DateUtilService;
@@ -63,6 +63,15 @@ var DateUtilService = /** @class */ (function () {
63
63
  futureDate.setDate(today.getDate() + n);
64
64
  return futureDate;
65
65
  };
66
+ DateUtilService.prototype.calculateDateDifference = function (fromDateCode, toDateCode, unit) {
67
+ if (unit === void 0) { unit = "minute"; }
68
+ var fromDate = (0, date_fns_1.parse)(fromDateCode, "yyMMddHHmm", new Date());
69
+ var toDate = (0, date_fns_1.parse)(toDateCode, "yyMMddHHmm", new Date());
70
+ var minutesDifference = (0, date_fns_1.differenceInMinutes)(toDate, fromDate);
71
+ return unit === "minute"
72
+ ? minutesDifference
73
+ : parseFloat((minutesDifference / 60).toFixed(1));
74
+ };
66
75
  return DateUtilService;
67
76
  }());
68
77
  exports.DateUtilService = DateUtilService;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "turf-common",
3
- "version": "1.2.1-beta.11",
3
+ "version": "1.2.1-beta.12",
4
4
  "description": "",
5
5
  "main": "./build/index.js",
6
6
  "types": "./build/index.d.ts",