File: Day.php

package info (click to toggle)
kronolith 1.1.4-2sarge1
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 2,212 kB
  • ctags: 1,074
  • sloc: php: 4,187; sh: 724; xml: 522; makefile: 96; sql: 42; perl: 20
file content (88 lines) | stat: -rw-r--r-- 2,189 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
<?php
/**
 * The Kronolith_Day:: class provides an API for dealing with days.
 *
 * $Horde: kronolith/lib/Day.php,v 1.16.2.2 2003/04/04 19:23:58 chuck Exp $
 *
 * @author  Chuck Hagenbuch <chuck@horde.org>
 * @version $Revision: 1.16.2.2 $
 * @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));
    }

}