source: branches/version-2_13-dev/data/class/SC_Date.php @ 22735

Revision 22735, 6.1 KB checked in by h_yoshimoto, 11 years ago (diff)

#2193 ユニットテストチームのコミットをマージ(from camp/camp-2_13-tests)

  • Property svn:eol-style set to LF
  • Property svn:keywords set to Id
  • Property svn:mime-type set to text/x-httpd-php; charset=UTF-8
Line 
1<?php
2/*
3 * This file is part of EC-CUBE
4 *
5 * Copyright(c) 2000-2013 LOCKON CO.,LTD. All Rights Reserved.
6 *
7 * http://www.lockon.co.jp/
8 *
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License
11 * as published by the Free Software Foundation; either version 2
12 * of the License, or (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
22 */
23
24/* 日時表示用クラス */
25class SC_Date
26{
27    var $start_year;
28    var $month;
29    var $day;
30    var $end_year;
31
32    public static $arrHoliday = NULL;
33    public static $arrRegularHoliday = NULL;
34
35    // コンストラクタ
36    function __construct($start_year='', $end_year='')
37    {
38        if ($start_year)  $this->setStartYear($start_year);
39        if ($end_year)    $this->setEndYear($end_year);
40    }
41
42    function setStartYear($year)
43    {
44        $this->start_year = $year;
45    }
46
47    function getStartYear()
48    {
49        return $this->start_year;
50    }
51
52    function setEndYear($endYear)
53    {
54        $this->end_year = $endYear;
55    }
56
57    function getEndYear()
58    {
59        return $this->end_year;
60    }
61
62    function setMonth($month)
63    {
64        $this->month = $month;
65    }
66
67    function setDay($day)
68    {
69        $this->day = $day;
70    }
71
72    /**
73     * 年プルダウン用の配列を返す
74     * FIXME $default_year に一致いる行が無かった場合、先頭か末尾に付加すべきと思われる。
75     * @param string $year    XMLファイル名
76     * @param bool|string $default_year
77     *     false  「選択なし」は含めない。
78     *     true   「選択なし」は含める。
79     *     string 「選択なし」は指定された値の下に付加する。
80     * @param string $default_key
81     */
82    function getYear($year = '', $default_year = false, $default_key = '----')
83    {
84        if ($year) $this->setStartYear($year);
85
86        $year = $this->start_year;
87        if (! $year) $year = DATE('Y');
88
89        $end_year = $this->end_year;
90        if (! $end_year) $end_year = (DATE('Y') + 3);
91
92        $year_array = array();
93
94        if ($default_year === true) {
95            $year_array[$default_key] = '----';
96        }
97
98        for ($i = $year; $i <= $end_year; $i++) {
99            $year_array[$i] = $i;
100            if ($default_year !== true && strlen($default_year) >= 1 && $i == $default_year) {
101                $year_array[$default_key] = '----';
102            }
103        }
104        return $year_array;
105    }
106
107    function getZeroYear($year = '')
108    {
109        if ($year) $this->setStartYear($year);
110
111        $year = $this->start_year;
112        if (! $year) $year = DATE('Y');
113
114        $end_year = $this->end_year;
115        if (! $end_year) $end_year = (DATE('Y') + 3);
116
117        $year_array = array();
118
119        for ($i = $year; $i <= $end_year; $i++) {
120            $key = substr($i, -2);
121            $year_array[$key] = $key;
122        }
123        return $year_array;
124    }
125
126    function getZeroMonth()
127    {
128
129        $month_array = array();
130        for ($i=1; $i <= 12; $i++) {
131            $val = sprintf('%02d', $i);
132            $month_array[$val] = $val;
133        }
134        return $month_array;
135    }   
136
137    function getMonth($default = false)
138    {
139        $month_array = array();
140
141        if ($default) $month_array[''] = '--';
142
143        for ($i=0; $i < 12; $i++) {
144            $month_array[$i + 1 ] = $i + 1;
145        }
146        return $month_array;
147    }   
148
149    function getDay($default = false)
150    {
151        $day_array = array();
152
153        if ($default) $day_array[''] = '--';
154
155        for ($i=0; $i < 31; $i++) {
156            $day_array[ $i + 1 ] = $i + 1;
157        }
158
159        return $day_array;
160    }
161
162    function getHour()
163    {
164
165        $hour_array = array();
166        for ($i=0; $i<=23; $i++) {
167            $hour_array[$i] = $i;
168        }
169
170        return $hour_array;
171    }
172
173    function getMinutes()
174    {
175
176        $minutes_array = array();
177        for ($i=0; $i<=59; $i++) {
178            $minutes_array[$i] = $i;
179        }
180
181        return $minutes_array;
182    }
183
184    function getMinutesInterval()
185    {
186
187        $minutes_array = array('00'=>'00', '30'=>'30');
188        return $minutes_array;
189    }
190
191    /**
192     * 休日の判定.
193     *
194     * @param integer $year
195     * @param integer $month
196     * @param integer $day
197     * @return boolean 休日の場合はtrue
198     */
199    public function isHoliday($year, $month, $day)
200    {
201        if (is_null(SC_Date_Ex::$arrHoliday)) $this->setArrHoliday();
202        if (is_null(SC_Date_Ex::$arrRegularHoliday)) $this->setRegularHoliday();
203
204        if (!empty(SC_Date_Ex::$arrHoliday[$month])) {
205            if (in_array($day, SC_Date_Ex::$arrHoliday[$month])) {
206                return true;
207            }
208        }
209        if (!empty(SC_Date_Ex::$arrRegularHoliday)) {
210            $day = date('w', mktime(0,0,0 ,$month, $day, $year));
211            if (in_array($day, SC_Date_Ex::$arrRegularHoliday)) {
212                return true;
213            }
214        }
215        return false;
216    }
217
218    /**
219     * 休日情報をスタティック変数にセット.
220     *
221     * @return void
222     */
223    private function setArrHoliday()
224    {
225        $objHoliday = new SC_Helper_Holiday_Ex();
226        $holiday = $objHoliday->getList();
227        $arrHoliday = array();
228        foreach ($holiday AS $val) {
229            $arrHoliday[$val['month']][] = $val['day'];
230        }
231        SC_Date_Ex::$arrHoliday = $arrHoliday;
232    }
233
234    /**
235     * 定休日情報をスタティック変数にセット.
236     *
237     * @return void
238     */
239    private function setRegularHoliday()
240    {
241        $arrInfo = SC_Helper_DB_Ex::sfGetBasisData();
242        SC_Date_Ex::$arrRegularHoliday = explode('|', $arrInfo['regular_holiday_ids']);
243    }
244}
Note: See TracBrowser for help on using the repository browser.