【发布时间】:2019-06-02 12:56:38
【问题描述】:
我想做什么:
getOpenStatus = (restaurant: _Restaurant) => {
const closeHour = moment(restaurant.close_at, "HH:mm A").hours();
const closeMin = moment(restaurant.close_at, "HH:mm A").minutes();
const openHour = moment(restaurant.open_at, "HH:mm A").hours();
const openMin = moment(restaurant.open_at, "HH:mm A").minutes();
const closeMoment = moment({ hours: closeHour, minutes: closeMin });
const openMoment = moment({ hours: openHour, minutes: openMin });
return moment().isAfter(openMoment) && moment().isBefore(closeMoment);
}
假设当前时间是下午 4:00
上午 10:30 开门,晚上 11:30 关门
在这种情况下工作完美,因为时间在同一日期。
但是如果餐厅 23 小时营业呢:
上午 10:30 开门,上午 9:30 关门
那该如何处理呢?
【问题讨论】:
标签: javascript time momentjs