Fork me on Github

CalendR

The missing PHP5.3+ calendar management library

Install

 $ curl -s http://getcomposer.org/installer | php
 $ php composer.phar require yohang/calendr
View on Github

Simple calendar generation

<?php
// Use the factory to get your period
$factory = new CalendR\Calendar;
$month = $factory->getMonth(2012, 01);
?>

<table>
    <?php // Iterate over your month and get weeks ?>
    <?php foreach ($month as $week): ?>
    <tr>
        <?php // Iterate over your month and get days ?>
        <?php foreach ($week as $day): ?>
            <?php //Check days that are out of your month ?>
            <td><?php echo $day ?></td>
        <?php endforeach ?>
    </tr>
    <?php endforeach ?>
</table>

Events

<?php
$month = $factory->getMonth(2012, 6)

// Retrieve an event collection from the event manager
$events = $factory->getEvents($month)
?>

<?php foreach ($month as $week): ?>
    <h2>Week #<?php echo $week ?></h2>
    <ul>
        <?php // retrieve events for the subperiod (week) ?>
        <?php foreach ($events->find($week) as $event): ?>
            <li><?php echo $event ?></li>
        <?php endforeach ?>
    </ul>
<?php endforeach ?>