@escapenavigator/utils 1.9.39 → 1.9.40

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.
@@ -1,19 +1,22 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.validatePromocode = void 0;
4
+ const date_fns_1 = require("date-fns");
5
+ const date_fns_tz_1 = require("date-fns-tz");
4
6
  function getWeekdayNumber(date) {
5
7
  const day = new Date(date).getDay();
6
8
  return (day === 0 ? 7 : day) - 1;
7
9
  }
8
10
  function validatePromocode({ promocode, players, questroomId, timeZone, orderDate, hasCertificates, otherPromocodes, isInside, type, }) {
9
11
  const errors = [];
10
- const orderDateInTimeZone = type === 'order' && new Date(new Date(orderDate).toLocaleString('en-US', { timeZone }));
11
- const currentDate = type === 'order' && orderDateInTimeZone.toISOString().split('T')[0];
12
+ const orderDateInTimeZone = type === 'order' && (0, date_fns_tz_1.utcToZonedTime)(new Date(orderDate).toISOString(), timeZone);
13
+ const currentDate = type === 'order' && (0, date_fns_1.format)(orderDateInTimeZone, 'yyyy-MM-dd');
12
14
  const orderDayOfWeek = type === 'order' && getWeekdayNumber(orderDateInTimeZone);
13
- const localOrderTime = type === 'order' && new Date(orderDate).toLocaleTimeString('en-GB', { timeZone });
14
- const currentHour = type === 'order' && localOrderTime;
15
- const today = new Date(new Date().toLocaleString('en-US', { timeZone }));
16
- const todayDate = today.toISOString().split('T')[0];
15
+ const localOrderTime = type === 'order' && (0, date_fns_1.format)(orderDateInTimeZone, 'HH:mm');
16
+ const todayDate = (0, date_fns_1.format)((0, date_fns_tz_1.utcToZonedTime)(new Date(), timeZone), 'yyyy-MM-dd');
17
+ console.log({
18
+ currentDate, orderDayOfWeek, localOrderTime, orderDate, timeZone,
19
+ });
17
20
  if (type === 'certificate' && !promocode.availableForCertificates) {
18
21
  errors.push("The promocode can't be applied for certificates.");
19
22
  }
@@ -56,10 +59,10 @@ function validatePromocode({ promocode, players, questroomId, timeZone, orderDat
56
59
  if (!promocode.allQuestrooms && !promocode.questroomsIds?.includes(questroomId)) {
57
60
  errors.push('The promocode is not valid for the selected escape room.');
58
61
  }
59
- if (type === 'order' && promocode.availableFrom && currentHour < promocode.availableFrom) {
62
+ if (type === 'order' && promocode.availableFrom && localOrderTime < promocode.availableFrom) {
60
63
  errors.push(`The promocode is available from ${promocode.availableFrom}.`);
61
64
  }
62
- if (type === 'order' && promocode.availableTo && currentHour > promocode.availableTo) {
65
+ if (type === 'order' && promocode.availableTo && localOrderTime > promocode.availableTo) {
63
66
  errors.push(`The promocode is only available until ${promocode.availableTo}.`);
64
67
  }
65
68
  if (type === 'order' &&
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@escapenavigator/utils",
3
- "version": "1.9.39",
3
+ "version": "1.9.40",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -55,5 +55,5 @@
55
55
  "node_modules"
56
56
  ]
57
57
  },
58
- "gitHead": "daf2978f7fd6d9217b64cc09944ab7c333690d1c"
58
+ "gitHead": "3292197490e3df9bc3410ba0b0e45214b1023a37"
59
59
  }