<?php
/**
 * The Kronolith_Day:: class provides an API for dealing with days.
 *
 * $Horde: kronolith/lib/Day.php,v 1.21 2003/01/10 02:13:01 jan Exp $
 *
 * @author  Chuck Hagenbuch <chuck@horde.org>
 * @version $Revision: 1.21 $
 * @since   Kronolith 0.1
 * @package kronolith
 */
class Kronolith_Day {

    var $month;
    var $mday;
    var $year;
    var $time;
    var $hours;

    function Kronolith_Day($month = null, $day = null, $year = null, $timestamp = null)
    {
        if (!empty($timestamp)) {
            $this->time = $timestamp;
        } else {
            if (empty($month)) {
                $month = date('n');
            }
            if (empty($year)) {
                $year = date('Y');
            }
            if (empty($day)) {
                $day = date('j');
            }

            // now, compensate for any wrap around
            $this->time = mktime(0, 0, 0, $month, $day, $year);
        }

        $this->month = date('m', $this->time);
        $this->year = date('Y', $this->time);
        $this->mday = date('j', $this->time);

        // make the data array
        $this->makeHours();
    }

    function makeHours()
    {
        $this->hours = array();

        $row = 0;
        for ($i = 0; $i < 48; $i++) {
            $this->hours[$i]['timestamp'] = mktime(0, $i * 30, 0, $this->month, $this->mday, $this->year);
        }
    }

    function getTime($format, $offset = 0)
    {
        return strftime($format,
                        mktime(0, 0, 0, $this->month, ($this->mday + $offset), $this->year));
    }

    function getTomorrow()
    {
        return mktime(0, 0, 0, $this->month, $this->mday + 1, $this->year);
    }

    function getStamp()
    {
        return mktime(0, 0, 0, $this->month, $this->mday, $this->year);
    }

    function getDayOfWeek()
    {
        return Kronolith::dayOfWeek($this->year, $this->month, $this->mday);
    }

    function isToday()
    {
        return (mktime(0, 0, 0, $this->month, $this->mday, $this->year) == mktime(0, 0, 0));
    }

    function isTomorrow()
    {
        return (mktime(0, 0, 0, $this->month, $this->mday - 1, $this->year) == mktime(0, 0, 0));
    }

}
