carvefx / calendar
简单的PHP日历库
v0.1
2014-08-02 13:30 UTC
Requires
- php: >=5.4
- nesbot/carbon: ~1.0
Requires (Dev)
- phpspec/phpspec: 2.0.*@dev
This package is not auto-updated.
Last update: 2024-09-28 16:25:47 UTC
README
calendar
使用PHP编写的日历库
用法
require('vendor/autoload.php');
use Carvefx\Calendar\Calendar;
$calendar = new Calendar(2014, 8);
foreach($calendar->getWeeks() as $week) {
foreach($week->getDays() as $day) {
$day->toDateString(); // 2014-07-27
$day->isBlankDay(); // true
}
}
文档
Calendar 包含3个主要类
- Calendar: 代表当前月份的显示,包括属于前一个月或下一个月的空白天数
- Week: 代表7天,不考虑它所属的月份
- Day: 代表一个单独的日子,并包装在 \Carbon\Carbon 类中
Day API
$day = new Day(2014, 07, 01);
$day->setBlankDay(false);
$day->isBlankDay(); // returns a bool value, shows whether the current day is part of the current month
// Any of the \Carbon\Carbon methods work
$day->getDateString(); // 2014-07-01
$day->month; // 7
Week API
$first_day = new Day(2014, 07, 01);
$week = new Week($first_day); // constructor requires the day the week starts at
$week->getDays(); // will result in an array containing 7 Day objects
Calendar API
$calendar = new Calendar(2014, 8);
$calendar->setYear(2015);
$calendar->setMonth(7);
$calendar->getFirstDay(); // returns the first day of the month
$calendar->getLastDay(); // returns the last day of tyhe month
$calendar->getWeeks() // results in a number of Week objects