Skip to content

Commit

Permalink
Merge pull request #51 from lux-group/calendar
Browse files Browse the repository at this point in the history
feat(calendar): add methods for calendar
  • Loading branch information
reb2020 authored Mar 16, 2022
2 parents 45c3545 + 6ef4d17 commit 5e44bf6
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 50 deletions.
13 changes: 5 additions & 8 deletions compiled/calendar/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand Down
12 changes: 3 additions & 9 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
13 changes: 5 additions & 8 deletions src/calendar/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Expand Down
28 changes: 4 additions & 24 deletions test/calendar/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})
})

Expand Down

0 comments on commit 5e44bf6

Please sign in to comment.