breadthe / php-simple-calendar
生成显示在日历网格中的月份日期数组
v1.1.0
2022-04-24 03:33 UTC
Requires
- php: ^7.3|^7.4|^8.0
- nesbot/carbon: ^2.32
Requires (Dev)
- phpunit/phpunit: ^9.0
This package is auto-updated.
Last update: 2024-09-24 09:06:09 UTC
README
此PHP 7.3+软件包生成一个7 x 6(42)或7 x 5(35)元素的日期数组,表示所需月份的日期。每个日期是Carbon\Carbon
的一个实例。
它会自动用前一个月或下一个月的日期填充月份的开始/结束。也可以选择用null
填充。
虽然它不包括UI,但你可以使用生成的矩阵使用你选择的任何前端技术构建月度网格日历。
注意 至少目前,周从星期一开始。
要求
- PHP 7.3+
安装
您可以通过composer安装此包
composer require breadthe/php-simple-calendar
用法
日历网格生成
use Breadthe\SimpleCalendar\Calendar; $date = '2020-03-24'; // ISO date $calendar = new Calendar($date); $currentMonth = $calendar->grid(); // or use the static constructor $currentMonth = Calendar::make($date)->grid();
上个月/下个月开始
上个月和下个月的第一天(第一天)是一个方便的功能,可能在构建日历UI中的“上个月”/“下个月”导航时很有用。即使调用padWithNull()
,这些属性也会存在。
$date = '2020-03-17'; $currentMonth = Calendar::make($date); $currentMonth->startOfPrevMonth; // get the start of the previous month - instance of Carbon $currentMonth->startOfPrevMonth->toDateString(); // '2020-02-01' $currentMonth->startOfNextMonth; // get the start of the previous month - instance of Carbon $currentMonth->startOfNextMonth->toDateString(); // '2020-04-01'
UI示例
以下是使用此包可以构建的简单日历UI的示例。
测试
composer test
变更日志
请参阅变更日志了解最近的变化信息。
贡献
请参阅贡献指南了解详细信息。
安全性
如果您发现任何与安全性相关的问题,请通过omigoshdev@protonmail.com发送电子邮件,而不是使用问题跟踪器。
致谢
许可证
MIT许可证(MIT)。请参阅许可证文件了解更多信息。
Laravel/PHP软件包模板
此软件包是使用Laravel软件包模板生成的。