Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(calendar): add methods for calendar #51

Merged
merged 1 commit into from
Mar 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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