From 6ef4d170173a41c9e79192fcebde0d1c8af14763 Mon Sep 17 00:00:00 2001 From: Alexander Sokol Date: Wed, 16 Mar 2022 08:05:49 +0200 Subject: [PATCH] feat(calendar): add methods for calendar --- compiled/calendar/index.js | 13 +++++-------- index.d.ts | 12 +++--------- package.json | 2 +- src/calendar/index.js | 13 +++++-------- test/calendar/index.test.js | 28 ++++------------------------ 5 files changed, 18 insertions(+), 50 deletions(-) diff --git a/compiled/calendar/index.js b/compiled/calendar/index.js index b789ad7..4ec4f1e 100644 --- a/compiled/calendar/index.js +++ b/compiled/calendar/index.js @@ -38,18 +38,15 @@ var getStartDate = function getStartDate(minDate, travelFromDate) { return moment(minDate).format(constants.DATE_FORMAT); }; -var getDateFloorOffset = function getDateFloorOffset(_ref) { - var timezoneOffset = _ref.timezoneOffset, - dateFloorOffset = _ref.dateFloorOffset, - hourOfDayThreshold = _ref.hourOfDayThreshold, - _ref$enquiryType = _ref.enquiryType, - enquiryType = _ref$enquiryType === void 0 ? 'customer' : _ref$enquiryType; +var getDateFloorOffset = function getDateFloorOffset(timezoneOffset, offerType) { + var enquiryType = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'customer'; + var dateFloorOffset = constants.OFFERS[offerType].dateFloorOffset; if (enquiryType === 'admin') return 0; if (dateFloorOffset === 0) { - var nowHours = parseInt(moment().utcOffset(timezoneOffset).format('HH')); + var nowHours = parseInt(moment.utc().utcOffset(timezoneOffset).format('HH')); - if (nowHours >= hourOfDayThreshold) { + if (nowHours >= constants.OFFERS[offerType].hourOfDayThreshold) { return 1; } } diff --git a/index.d.ts b/index.d.ts index 178f21a..7790a7d 100644 --- a/index.d.ts +++ b/index.d.ts @@ -163,16 +163,10 @@ declare module "@luxuryescapes/lib-global" { minDate?: string, travelFromDate?: string ) => string; - getDateFloorOffset: ({ - timezoneOffset, - dateFloorOffset, - hourOfDayThreshold, - enquiryType - }: { + getDateFloorOffset: ( timezoneOffset: number, - dateFloorOffset: number, - hourOfDayThreshold: number, + offerType: string, enquiryType: 'customer' | 'admin' - }) => string; + ) => string; }; } diff --git a/package.json b/package.json index bd1b9ad..00baa8c 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@luxuryescapes/lib-global", - "version": "2.6.8", + "version": "2.6.9", "description": "Lib for expanding functionality and deduplicating code between services", "main": "compiled/index.js", "types": "index.d.ts", diff --git a/src/calendar/index.js b/src/calendar/index.js index c7385bd..e77727c 100644 --- a/src/calendar/index.js +++ b/src/calendar/index.js @@ -40,17 +40,14 @@ const getStartDate = (minDate, travelFromDate) => { return moment(minDate).format(constants.DATE_FORMAT) } -const getDateFloorOffset = ({ - timezoneOffset, - dateFloorOffset, - hourOfDayThreshold, - enquiryType = 'customer', -}) => { +const getDateFloorOffset = (timezoneOffset, offerType, enquiryType = 'customer') => { + const dateFloorOffset = constants.OFFERS[offerType].dateFloorOffset + if (enquiryType === 'admin') return 0 if (dateFloorOffset === 0) { - const nowHours = parseInt(moment().utcOffset(timezoneOffset).format('HH')) - if (nowHours >= hourOfDayThreshold) { + const nowHours = parseInt(moment.utc().utcOffset(timezoneOffset).format('HH')) + if (nowHours >= constants.OFFERS[offerType].hourOfDayThreshold) { return 1 } } diff --git a/test/calendar/index.test.js b/test/calendar/index.test.js index 540b813..0072f9e 100644 --- a/test/calendar/index.test.js +++ b/test/calendar/index.test.js @@ -49,40 +49,20 @@ describe('Calendar', () => { describe('getDateFloorOffset()', () => { it('get return default date floor offset', () => { - expect(calendar.getDateFloorOffset({ - timezoneOffset: 0, - dateFloorOffset: 2, - hourOfDayThreshold: 0, - enquiryType: 'customer', - })).to.eql(2) + expect(calendar.getDateFloorOffset(0, 'hotel', 'customer')).to.eql(2) }) it('get return zero date floor offset', () => { - expect(calendar.getDateFloorOffset({ - timezoneOffset: 600, - dateFloorOffset: 0, - hourOfDayThreshold: 15, - enquiryType: 'customer', - })).to.eql(0) + expect(calendar.getDateFloorOffset(600, 'last_minute_hotel', 'customer')).to.eql(0) }) it('get return one date floor offset', () => { MockDate.set('2022-01-31 12:22:47') - expect(calendar.getDateFloorOffset({ - timezoneOffset: 600, - dateFloorOffset: 0, - hourOfDayThreshold: 15, - enquiryType: 'customer', - })).to.eql(1) + expect(calendar.getDateFloorOffset(600, 'last_minute_hotel', 'customer')).to.eql(1) }) it('get return 0 date floor offset for admin', () => { - expect(calendar.getDateFloorOffset({ - timezoneOffset: 0, - dateFloorOffset: 2, - hourOfDayThreshold: 0, - enquiryType: 'admin', - })).to.eql(0) + expect(calendar.getDateFloorOffset(0, 'hotel', 'admin')).to.eql(0) }) })