-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #42 from lux-group/calendar
feat(calendar): add methods for calendar
- Loading branch information
Showing
9 changed files
with
389 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
"use strict"; | ||
|
||
var _OFFERS; | ||
|
||
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } | ||
|
||
var _require = require('../offer/constants'), | ||
OFFER_TYPE_HOTEL = _require.OFFER_TYPE_HOTEL, | ||
OFFER_TYPE_TOUR = _require.OFFER_TYPE_TOUR, | ||
OFFER_TYPE_LAST_MINUTE_HOTEL = _require.OFFER_TYPE_LAST_MINUTE_HOTEL, | ||
OFFER_TYPE_TACTICAL_AO_HOTEL = _require.OFFER_TYPE_TACTICAL_AO_HOTEL; | ||
|
||
var OFFERS = (_OFFERS = {}, _defineProperty(_OFFERS, OFFER_TYPE_TOUR, { | ||
type: OFFER_TYPE_TOUR, | ||
parentType: OFFER_TYPE_TOUR, | ||
dateFloorOffset: 2, | ||
hourOfDayThreshold: 0, | ||
useDynamicRate: false, | ||
useTimezoneOffset: false | ||
}), _defineProperty(_OFFERS, OFFER_TYPE_HOTEL, { | ||
type: OFFER_TYPE_HOTEL, | ||
parentType: OFFER_TYPE_HOTEL, | ||
dateFloorOffset: 2, | ||
hourOfDayThreshold: 0, | ||
useDynamicRate: false, | ||
useTimezoneOffset: false | ||
}), _defineProperty(_OFFERS, OFFER_TYPE_LAST_MINUTE_HOTEL, { | ||
type: OFFER_TYPE_LAST_MINUTE_HOTEL, | ||
parentType: OFFER_TYPE_HOTEL, | ||
dateFloorOffset: 0, | ||
hourOfDayThreshold: 15, | ||
useDynamicRate: true, | ||
useTimezoneOffset: true | ||
}), _defineProperty(_OFFERS, OFFER_TYPE_TACTICAL_AO_HOTEL, { | ||
type: OFFER_TYPE_TACTICAL_AO_HOTEL, | ||
parentType: OFFER_TYPE_HOTEL, | ||
dateFloorOffset: 0, | ||
hourOfDayThreshold: 15, | ||
useDynamicRate: true, | ||
useTimezoneOffset: true | ||
}), _OFFERS); | ||
var CEILING_YEARS = 3; | ||
var DEFAULT_MONTHS_FALLBACK = 18; | ||
var DATE_FORMAT = 'YYYY-MM-DD'; | ||
module.exports = { | ||
CEILING_YEARS: CEILING_YEARS, | ||
DEFAULT_MONTHS_FALLBACK: DEFAULT_MONTHS_FALLBACK, | ||
DATE_FORMAT: DATE_FORMAT, | ||
OFFER_TYPE_HOTEL: OFFER_TYPE_HOTEL, | ||
OFFER_TYPE_TOUR: OFFER_TYPE_TOUR, | ||
OFFER_TYPE_LAST_MINUTE_HOTEL: OFFER_TYPE_LAST_MINUTE_HOTEL, | ||
OFFER_TYPE_TACTICAL_AO_HOTEL: OFFER_TYPE_TACTICAL_AO_HOTEL, | ||
OFFERS: OFFERS | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
"use strict"; | ||
|
||
var moment = require('moment'); | ||
|
||
var constants = require('./constants'); | ||
|
||
var getTimezoneOffset = function getTimezoneOffset(offerPackageTimezoneOffset, offerType, requestTimezoneOffset) { | ||
if (!requestTimezoneOffset && constants.OFFERS[offerType].useTimezoneOffset) { | ||
return parseInt(offerPackageTimezoneOffset || 0); | ||
} | ||
|
||
return requestTimezoneOffset; | ||
}; | ||
|
||
var getMonthsToRequest = function getMonthsToRequest(timezoneOffset, maxDate) { | ||
var now = moment().utcOffset(timezoneOffset); | ||
return moment(maxDate).diff(now, 'months') + 2; | ||
}; | ||
|
||
var getMaxCheckInCloseDate = function getMaxCheckInCloseDate(checkInCloses) { | ||
var defaultMonths = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : constants.DEFAULT_MONTHS_FALLBACK; | ||
return checkInCloses ? moment.min(moment(checkInCloses), moment().add(constants.CEILING_YEARS, 'years')).format(constants.DATE_FORMAT) : moment().add(defaultMonths, 'months').format(constants.DATE_FORMAT); | ||
}; | ||
|
||
var getStartDate = function getStartDate(minDate, travelFromDate) { | ||
if (minDate && travelFromDate) { | ||
if (moment(travelFromDate).isAfter(moment(minDate))) { | ||
return moment(travelFromDate).format(constants.DATE_FORMAT); | ||
} else { | ||
return moment(minDate).format(constants.DATE_FORMAT); | ||
} | ||
} | ||
|
||
if (travelFromDate) { | ||
return moment(travelFromDate).format(constants.DATE_FORMAT); | ||
} | ||
|
||
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; | ||
if (enquiryType === 'admin') return 0; | ||
|
||
if (dateFloorOffset === 0) { | ||
var nowHours = parseInt(moment().utcOffset(timezoneOffset).format('HH')); | ||
|
||
if (nowHours >= hourOfDayThreshold) { | ||
return 1; | ||
} | ||
} | ||
|
||
return dateFloorOffset; | ||
}; | ||
|
||
module.exports = { | ||
constants: constants, | ||
getTimezoneOffset: getTimezoneOffset, | ||
getMonthsToRequest: getMonthsToRequest, | ||
getMaxCheckInCloseDate: getMaxCheckInCloseDate, | ||
getStartDate: getStartDate, | ||
getDateFloorOffset: getDateFloorOffset | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
const { OFFER_TYPE_HOTEL, OFFER_TYPE_TOUR, OFFER_TYPE_LAST_MINUTE_HOTEL, OFFER_TYPE_TACTICAL_AO_HOTEL } = require('../offer/constants') | ||
|
||
const OFFERS = { | ||
[OFFER_TYPE_TOUR]: { | ||
type: OFFER_TYPE_TOUR, | ||
parentType: OFFER_TYPE_TOUR, | ||
dateFloorOffset: 2, | ||
hourOfDayThreshold: 0, | ||
useDynamicRate: false, | ||
useTimezoneOffset: false, | ||
}, | ||
[OFFER_TYPE_HOTEL]: { | ||
type: OFFER_TYPE_HOTEL, | ||
parentType: OFFER_TYPE_HOTEL, | ||
dateFloorOffset: 2, | ||
hourOfDayThreshold: 0, | ||
useDynamicRate: false, | ||
useTimezoneOffset: false, | ||
}, | ||
[OFFER_TYPE_LAST_MINUTE_HOTEL]: { | ||
type: OFFER_TYPE_LAST_MINUTE_HOTEL, | ||
parentType: OFFER_TYPE_HOTEL, | ||
dateFloorOffset: 0, | ||
hourOfDayThreshold: 15, | ||
useDynamicRate: true, | ||
useTimezoneOffset: true, | ||
}, | ||
[OFFER_TYPE_TACTICAL_AO_HOTEL]: { | ||
type: OFFER_TYPE_TACTICAL_AO_HOTEL, | ||
parentType: OFFER_TYPE_HOTEL, | ||
dateFloorOffset: 0, | ||
hourOfDayThreshold: 15, | ||
useDynamicRate: true, | ||
useTimezoneOffset: true, | ||
}, | ||
} | ||
|
||
const CEILING_YEARS = 3 | ||
const DEFAULT_MONTHS_FALLBACK = 18 | ||
const DATE_FORMAT = 'YYYY-MM-DD' | ||
|
||
module.exports = { | ||
CEILING_YEARS, | ||
DEFAULT_MONTHS_FALLBACK, | ||
DATE_FORMAT, | ||
OFFER_TYPE_HOTEL, | ||
OFFER_TYPE_TOUR, | ||
OFFER_TYPE_LAST_MINUTE_HOTEL, | ||
OFFER_TYPE_TACTICAL_AO_HOTEL, | ||
OFFERS, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
const moment = require('moment') | ||
|
||
const constants = require('./constants') | ||
|
||
const getTimezoneOffset = (offerPackageTimezoneOffset, offerType, requestTimezoneOffset) => { | ||
if (!requestTimezoneOffset && constants.OFFERS[offerType].useTimezoneOffset) { | ||
return parseInt(offerPackageTimezoneOffset || 0) | ||
} | ||
|
||
return requestTimezoneOffset | ||
} | ||
|
||
const getMonthsToRequest = (timezoneOffset, maxDate) => { | ||
const now = moment().utcOffset(timezoneOffset) | ||
return moment(maxDate).diff(now, 'months') + 2 | ||
} | ||
|
||
const getMaxCheckInCloseDate = ( | ||
checkInCloses, | ||
defaultMonths = constants.DEFAULT_MONTHS_FALLBACK, | ||
) => { | ||
return checkInCloses ? | ||
moment | ||
.min(moment(checkInCloses), moment().add(constants.CEILING_YEARS, 'years')) | ||
.format(constants.DATE_FORMAT) : | ||
moment().add(defaultMonths, 'months').format(constants.DATE_FORMAT) | ||
} | ||
|
||
const getStartDate = (minDate, travelFromDate) => { | ||
if (minDate && travelFromDate) { | ||
if (moment(travelFromDate).isAfter(moment(minDate))) { | ||
return moment(travelFromDate).format(constants.DATE_FORMAT) | ||
} else { | ||
return moment(minDate).format(constants.DATE_FORMAT) | ||
} | ||
} | ||
if (travelFromDate) { | ||
return moment(travelFromDate).format(constants.DATE_FORMAT) | ||
} | ||
return moment(minDate).format(constants.DATE_FORMAT) | ||
} | ||
|
||
const getDateFloorOffset = ({ | ||
timezoneOffset, | ||
dateFloorOffset, | ||
hourOfDayThreshold, | ||
enquiryType = 'customer', | ||
}) => { | ||
if (enquiryType === 'admin') return 0 | ||
|
||
if (dateFloorOffset === 0) { | ||
const nowHours = parseInt(moment().utcOffset(timezoneOffset).format('HH')) | ||
if (nowHours >= hourOfDayThreshold) { | ||
return 1 | ||
} | ||
} | ||
|
||
return dateFloorOffset | ||
} | ||
|
||
module.exports = { | ||
constants, | ||
getTimezoneOffset, | ||
getMonthsToRequest, | ||
getMaxCheckInCloseDate, | ||
getStartDate, | ||
getDateFloorOffset, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.