共计 1307 个字符,预计需要花费 4 分钟才能阅读完成。
对于几个不同的客户,咱们须要在他们的网站上显示凋谢工夫的时间表。他们还想在您拜访该网站的那一刻显示百货公司 / 商店 /… 是否凋谢。我的共事 Seb 将凋谢工夫四周的所有性能提取到新公布的 opening-hours
包中。
您创立了一个 OpeningHours
形容企业营业时间的对象。它能够查问 open
或closed
日期或特定日期,或用于显示每天的工夫。
通过传入惯例时间表和例外列表来创立一组凋谢工夫。
$openingHours = OpeningHours::create(['monday' => ['09:00-12:00', '13:00-18:00'],
'tuesday' => ['09:00-12:00', '13:00-18:00'],
'wednesday' => ['09:00-12:00'],
'thursday' => ['09:00-12:00', '13:00-18:00'],
'friday' => ['09:00-12:00', '13:00-20:00'],
'saturday' => ['09:00-12:00', '13:00-16:00'],
'sunday' => [],
'exceptions' => ['2016-11-11' => ['09:00-12:00'],
'2016-12-25' => [],],
]);
该对象能够查问一周中的一天,它会依据惯例时间表返回后果:
// Open on Mondays:
$openingHours->isOpenOn('monday'); // true
// Closed on Sundays:
$openingHours->isOpenOn('sunday'); // false
也能够查问特定的日期和工夫:
// Closed because it's after hours:
$openingHours->isOpenAt(new DateTime('2016-09-26 19:00:00')); // false
// Closed because Christmas was set as an exception
$openingHours->isOpenAt(new DateTime('2016-12-25')); // false
它还能够返回一周或一天的凋谢工夫数组:
// OpeningHoursForDay object for the regular schedule
$openingHours->forDay('monday');
// OpeningHoursForDay[] for the regular schedule, keyed by day name
$openingHours->forWeek();
// OpeningHoursForDay object for a specific day
$openingHours->forDate(new DateTime('2016-12-25'));
// OpeningHoursForDay[] of all exceptions, keyed by date
$openingHours->exceptions();
查看 GitHub 上的包以理解残缺的 api。查看咱们之前制作的 PHP 包列表,看看咱们是否制作了其余可能对您有用的货色。
正文完