1-line-opening-hours 中文文档教程

发布于 4年前 浏览 25 项目主页 更新于 3年前

1-line-opening-hours

通过使用 OpenStreetMap opening_hours 格式,在使用简单开放时间时摆脱来自 API 的大量响应。

这首先是从 wbkd 分叉出来的。 该项目的目标是更大,因此重写了大量代码并添加了新功能。

它仅支持人类可读部分,而不支持这个完全疯狂的过度设计规范

Supported opening_hours examples

  • Mo-Sa 06:00-22:00
  • Mo-Fr 08:00-18:00; Sa 10:00-14:00
  • Mo-Fr 08:00-18:00; Sa,Su 10:00-20:00
  • Mo-Fr 08:00-12:00, We 14:00-18:00
  • Mo-Fr 08:00-12:00, 14:00-18:00
  • Mo-Fr 08:00+
  • Mo-Fr 08:00-01:00
  • Mo-Fr 08:00-18:00; We off
  • 24/7

Getting started

Install

npm install 1-line-opening-hours --save
yarn add 1-line-opening-hours

Usage

const openingHours = new OpeningHours('Mo-Sa 06:00-22:00');

console.log('Is this open now?', openingHours.isOpenNow());
console.log('Is this open on 2016-10-01 18:00?', openingHours.isOpenOn(new Date('2016-10-01 18:00')));
console.table(openingHours.getTable());

API

MethodDescriptionReturn value
isOpenNow()Check whether the establishment is open now based on the provided opening hourtrue or false
isOpenOn(date: Date)Same than above for any datetrue or false
getTable()Get an array of each day and the corresponding opening time{ su: [], mo: ['06:00-22:00'] ... }
getFullStatusOfToday()Send more information about the current opening status, the next day that it will be opened…{ open: false openUntil: null, nextReopening: { hour: '11:00', day: 'tu', opensInDay: 0 }
getFullStatusOfDay(date: Date)Same than above for any date{ open: false openUntil: null, nextReopening: { hour: '11:00', day: 'tu', opensInDay: 0 }

1-line-opening-hours

Get rid of heavy responses from API when using simple opening hours, by using the OpenStreetMap opening_hours format.

This was first forked from wbkd. The project then aimed to be bigger, so a lot of code has been rewrote and new features added.

It only supports the human readable parts and not this complete crazy overengineered specification.

Supported opening_hours examples

  • Mo-Sa 06:00-22:00
  • Mo-Fr 08:00-18:00; Sa 10:00-14:00
  • Mo-Fr 08:00-18:00; Sa,Su 10:00-20:00
  • Mo-Fr 08:00-12:00, We 14:00-18:00
  • Mo-Fr 08:00-12:00, 14:00-18:00
  • Mo-Fr 08:00+
  • Mo-Fr 08:00-01:00
  • Mo-Fr 08:00-18:00; We off
  • 24/7

Getting started

Install

npm install 1-line-opening-hours --save
yarn add 1-line-opening-hours

Usage

const openingHours = new OpeningHours('Mo-Sa 06:00-22:00');

console.log('Is this open now?', openingHours.isOpenNow());
console.log('Is this open on 2016-10-01 18:00?', openingHours.isOpenOn(new Date('2016-10-01 18:00')));
console.table(openingHours.getTable());

API

MethodDescriptionReturn value
isOpenNow()Check whether the establishment is open now based on the provided opening hourtrue or false
isOpenOn(date: Date)Same than above for any datetrue or false
getTable()Get an array of each day and the corresponding opening time{ su: [], mo: ['06:00-22:00'] ... }
getFullStatusOfToday()Send more information about the current opening status, the next day that it will be opened…{ open: false openUntil: null, nextReopening: { hour: '11:00', day: 'tu', opensInDay: 0 }
getFullStatusOfDay(date: Date)Same than above for any date{ open: false openUntil: null, nextReopening: { hour: '11:00', day: 'tu', opensInDay: 0 }
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文