scortes / calendar
此包已被废弃且不再维护。未建议替代包。
月度事件日历
v1.0.0
2015-08-24 09:54 UTC
Requires (Dev)
- hamcrest/hamcrest-php: *
- johnkary/phpunit-speedtrap: ~1.0@dev
- phpunit/phpunit: *
This package is auto-updated.
Last update: 2021-05-23 20:36:00 UTC
README
安装
composer require scortes/calendar
日历
- 添加事件 - 每个事件都需要日期,事件内容完全由您决定(可以是字符串、对象等)
- 可选地,您可以在
dateStart/dateEnd
中设置 最小/最大日期。否则它们将自动计算。 - 显示日历,您可以使用辅助函数
\Scortes\Calendar\HTML\monthsToTables
用于经典日历。
// configure calendar $request = new \Scortes\Calendar\CalendarRequest(); $request->dateStart = new DateTime('now - 2 month'); $request->dateEnd = null; // use max date from events $request->events = [ "now - 1 month" => 'Day in previous month', date('Y-n-') . 1 => 'First day in month', date('Y-n-') . 16 => '16th day in month', "now + 1 month" => 'Day in next month', ]; $request->addEvent(new DateTime('now + 2 months'), 'now + 2 months'); // build calendar $calendar = Scortes\Calendar\createCalendar($request); // display calendar \Scortes\Calendar\HTML\monthsToTables( $calendar, array( 'hideMonthsWithoutEvent' => true, 'selectors' => array( 'table' => ' class=calendar', 'month' => ' id=currentMonth', 'week' => ' id=currentWeek', 'day' => ' id=today', ), 'monthName' => function (Scortes\Calendar\Month\Month $month, $monthId) { return "<h3{$monthId}>Month {$month->monthNumber}/{$month->year}</h3>"; }, 'day' => array( 'withEvent' => function ($event, $currentDay) { return "<strong title='{$event}'>{$currentDay}</strong>"; }, 'withoutEvent' => function ($currentDay) { return "<strong>{$currentDay}</strong>"; }, 'empty' => '<td class="noDay"> </td>' ) ) );
组件
日历由两个独立的组件组成
分析两个日期时间之间的月份
$dateStart = new DateTime('now - 1 month'); $dateEnd = new DateTime('now + 2 months'); $months = \Scortes\Calendar\createMonthsInterval($dateStart, $dateEnd);
年 | 月 | 天数 | 周数 | 周的第一天 | 第一周数 |
---|---|---|---|---|---|
2015 | 7 | 31 | 5 | 3 | 27 |
2015 | 8 | 31 | 6 | 6 | 31 |
2015 | 9 | 30 | 5 | 2 | 36 |
2015 | 10 | 31 | 5 | 4 | 40 |
### 事件的数据结构(由分隔符分隔的 trie)
$events = new \Scortes\Calendar\Events\Events(' '); $events->set('John', 'John'); $events->set('John Doe', 'John Doe'); $events->set('John Black', 'John Black'); $events->set('John Black', 'Another John Black'); $events->set('Paul Carter', 'Paul Carter'); $events->get('John Doe'); // John Doe $events->get('John Black'); // [John Black, Another John Black] $events->iterate('John'); // [John, John Doe, [John Black, Another John Black]]
贡献
非常欢迎其他人的贡献!请发送 pull request/issue。谢谢!
许可证
版权(c)2015 Scortes。MIT 许可,详情见 LICENSE。