Warning: Can't use blame annotator:
svn blame failed on branches/version-2_13-dev/data/class/SC_Date.php: バイナリファイル 'file:///home/svn/open/branches/version-2_13-dev/data/class/SC_Date.php' に対しては blame で各行の最終変更者を計算できません 195004

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

Revision 23124, 6.2 KB checked in by kimoto, 11 years ago (diff)

#2043 typo修正・ソース整形・ソースコメントの改善 for 2.13.0
PHP4的な書き方の修正

  • 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
RevLine 
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    public $start_year;
28    public $month;
29    public $day;
30    public $end_year;
31
32    public static $arrHoliday = NULL;
33    public static $arrRegularHoliday = NULL;
34
35    // コンストラクタ
36    public 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    public function setStartYear($year)
43    {
44        $this->start_year = $year;
45    }
46
47    public function getStartYear()
48    {
49        return $this->start_year;
50    }
51
52    public function setEndYear($endYear)
53    {
54        $this->end_year = $endYear;
55    }
56
57    public function getEndYear()
58    {
59        return $this->end_year;
60    }
61
62    public function setMonth($month)
63    {
64        $this->month = $month;
65    }
66
67    public 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    public 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
105        return $year_array;
106    }
107
108    public function getZeroYear($year = '')
109    {
110        if ($year) $this->setStartYear($year);
111
112        $year = $this->start_year;
113        if (! $year) $year = DATE('Y');
114
115        $end_year = $this->end_year;
116        if (! $end_year) $end_year = (DATE('Y') + 3);
117
118        $year_array = array();
119
120        for ($i = $year; $i <= $end_year; $i++) {
121            $key = substr($i, -2);
122            $year_array[$key] = $key;
123        }
124
125        return $year_array;
126    }
127
128    public function getZeroMonth()
129    {
130        $month_array = array();
131        for ($i=1; $i <= 12; $i++) {
132            $val = sprintf('%02d', $i);
133            $month_array[$val] = $val;
134        }
135
136        return $month_array;
137    }
138
139    public function getMonth($default = false)
140    {
141        $month_array = array();
142
143        if ($default) $month_array[''] = '--';
144
145        for ($i=0; $i < 12; $i++) {
146            $month_array[$i + 1 ] = $i + 1;
147        }
148
149        return $month_array;
150    }
151
152    public function getDay($default = false)
153    {
154        $day_array = array();
155
156        if ($default) $day_array[''] = '--';
157
158        for ($i=0; $i < 31; $i++) {
159            $day_array[ $i + 1 ] = $i + 1;
160        }
161
162        return $day_array;
163    }
164
165    public function getHour()
166    {
167        $hour_array = array();
168        for ($i=0; $i<=23; $i++) {
169            $hour_array[$i] = $i;
170        }
171
172        return $hour_array;
173    }
174
175    public function getMinutes()
176    {
177        $minutes_array = array();
178        for ($i=0; $i<=59; $i++) {
179            $minutes_array[$i] = $i;
180        }
181
182        return $minutes_array;
183    }
184
185    public function getMinutesInterval()
186    {
187        $minutes_array = array('00'=>'00', '30'=>'30');
188
189        return $minutes_array;
190    }
191
192    /**
193     * 休日の判定.
194     *
195     * @param  integer $year
196     * @param  integer $month
197     * @param  integer $day
198     * @return boolean 休日の場合はtrue
199     */
200    public function isHoliday($year, $month, $day)
201    {
202        if (is_null(SC_Date_Ex::$arrHoliday)) $this->setArrHoliday();
203        if (is_null(SC_Date_Ex::$arrRegularHoliday)) $this->setRegularHoliday();
204
205        if (!empty(SC_Date_Ex::$arrHoliday[$month])) {
206            if (in_array($day, SC_Date_Ex::$arrHoliday[$month])) {
207                return true;
208            }
209        }
210        if (!empty(SC_Date_Ex::$arrRegularHoliday)) {
211            $day = date('w', mktime(0,0,0 ,$month, $day, $year));
212            if (in_array($day, SC_Date_Ex::$arrRegularHoliday)) {
213                return true;
214            }
215        }
216
217        return false;
218    }
219
220    /**
221     * 休日情報をスタティック変数にセット.
222     *
223     * @return void
224     */
225    private function setArrHoliday()
226    {
227        $objHoliday = new SC_Helper_Holiday_Ex();
228        $holiday = $objHoliday->getList();
229        $arrHoliday = array();
230        foreach ($holiday AS $val) {
231            $arrHoliday[$val['month']][] = $val['day'];
232        }
233        SC_Date_Ex::$arrHoliday = $arrHoliday;
234    }
235
236    /**
237     * 定休日情報をスタティック変数にセット.
238     *
239     * @return void
240     */
241    private function setRegularHoliday()
242    {
243        $arrInfo = SC_Helper_DB_Ex::sfGetBasisData();
244        SC_Date_Ex::$arrRegularHoliday = explode('|', $arrInfo['regular_holiday_ids']);
245    }
246}
Note: See TracBrowser for help on using the repository browser.