mirror of
https://github.com/kingomarnajjar/flex-template-web.git
synced 2026-07-29 05:00:43 +10:00
review changes
This commit is contained in:
parent
cec498d30f
commit
598c3ab99e
3 changed files with 7 additions and 6 deletions
|
|
@ -59,15 +59,15 @@ const estimatedTransaction = (unitType, bookingStart, bookingEnd, unitPrice, qua
|
|||
// Server normalizes night/day bookings to start from 00:00 UTC aka "Thu Mar 29 2018 13:00:00 GMT-1100 (SST)"
|
||||
// The result is: local timestamp.subtract(12h).add(timezoneoffset) (in eg. -23 h)
|
||||
|
||||
// local noon - 12h => 00:00 local => remove timezoneoffset => 00:00 API (UTC)
|
||||
// local noon -> startOf('day') => 00:00 local => remove timezoneoffset => 00:00 API (UTC)
|
||||
const serverDayStart = dateFromLocalToAPI(
|
||||
moment(bookingStart)
|
||||
.subtract(12, 'hours')
|
||||
.startOf('day')
|
||||
.toDate()
|
||||
);
|
||||
const serverDayEnd = dateFromLocalToAPI(
|
||||
moment(bookingEnd)
|
||||
.subtract(12, 'hours')
|
||||
.startOf('day')
|
||||
.toDate()
|
||||
);
|
||||
|
||||
|
|
|
|||
|
|
@ -95,7 +95,7 @@ export class CheckoutPageComponent extends Component {
|
|||
const listingId = pageData.listing.id;
|
||||
const { bookingStart, bookingEnd } = pageData.bookingDates;
|
||||
|
||||
// Convert picked date to date that will be coneverted on the API as
|
||||
// Convert picked date to date that will be converted on the API as
|
||||
// a noon of correct year-month-date combo in UTC
|
||||
const bookingStartForAPI = dateFromLocalToAPI(bookingStart);
|
||||
const bookingEndForAPI = dateFromLocalToAPI(bookingEnd);
|
||||
|
|
|
|||
|
|
@ -20,14 +20,15 @@ export const END_DATE = 'endDate';
|
|||
*
|
||||
* So, this function adds those removed hours back.
|
||||
*
|
||||
* NOTE: server-side rendering won't work for pages that render bookinDates given by API
|
||||
*
|
||||
* @param {Date} date is a local date object
|
||||
*
|
||||
* @returns {Date} date (given by API as UTC 00:00) converted back to local noon.
|
||||
*/
|
||||
export const dateFromAPIToLocalNoon = date => {
|
||||
const timezoneDiffInMinutes = moment(date).utcOffset();
|
||||
// Example timezone SST:
|
||||
// We get a Fri 00:00 UTC aka "Thu Mar 29 2018 13:00:00 GMT-1100 (SST)"
|
||||
// We need to subtract timezone difference (-11h), effectively adding 11h - to get to correct date
|
||||
const momentInLocalTimezone = moment(date).subtract(timezoneDiffInMinutes, 'minutes');
|
||||
// To be on the safe zone with leap seconds and stuff when using day / night picker
|
||||
// we'll add 12 h to get to the noon of day in local timezone.
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue