review changes

This commit is contained in:
Vesa Luusua 2018-03-28 23:32:49 +13:00
parent cec498d30f
commit 598c3ab99e
3 changed files with 7 additions and 6 deletions

View file

@ -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()
);

View file

@ -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);

View file

@ -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.