source: branches/version-2_12-dev/data/class/SC_Date.php @ 22567

Revision 22567, 4.4 KB checked in by shutta, 11 years ago (diff)

#2043 (typo修正・ソース整形・ソースコメントの改善 for 2.12.4)
Zend Framework PHP 標準コーディング規約のコーディングスタイルへ準拠。
classおよびfunctionの開始波括弧「{」のスタイルを修正。

  • 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    // コンストラクタ
33    function __construct($start_year='', $end_year='')
34    {
35        if ($start_year)  $this->setStartYear($start_year);
36        if ($end_year)    $this->setEndYear($end_year);
37    }
38
39    function setStartYear($year)
40    {
41        $this->start_year = $year;
42    }
43
44    function getStartYear()
45    {
46        return $this->start_year;
47    }
48
49    function setEndYear($endYear)
50    {
51        $this->end_year = $endYear;
52    }
53
54    function getEndYear()
55    {
56        return $this->end_year;
57    }
58
59    function setMonth($month)
60    {
61        $this->month = $month;
62    }
63
64    function setDay($day)
65    {
66        $this->day = $day;
67    }
68
69    /**
70     * 年プルダウン用の配列を返す
71     * FIXME $default_year に一致いる行が無かった場合、先頭か末尾に付加すべきと思われる。
72     * @param string $year    XMLファイル名
73     * @param bool|string $default_year
74     *     false  「選択なし」は含めない。
75     *     true   「選択なし」は含める。
76     *     string 「選択なし」は指定された値の下に付加する。
77     * @param string $default_key
78     */
79    function getYear($year = '', $default_year = false, $default_key = '----')
80    {
81        if ($year) $this->setStartYear($year);
82
83        $year = $this->start_year;
84        if (! $year) $year = DATE('Y');
85
86        $end_year = $this->end_year;
87        if (! $end_year) $end_year = (DATE('Y') + 3);
88
89        $year_array = array();
90
91        if ($default_year === true) {
92            $year_array[$default_key] = '----';
93        }
94
95        for ($i = $year; $i <= $end_year; $i++) {
96            $year_array[$i] = $i;
97            if ($default_year !== true && strlen($default_year) >= 1 && $i == $default_year) {
98                $year_array[$default_key] = '----';
99            }
100        }
101        return $year_array;
102    }
103
104    function getZeroYear($year = '')
105    {
106        if ($year) $this->setStartYear($year);
107
108        $year = $this->start_year;
109        if (! $year) $year = DATE('Y');
110
111        $end_year = $this->end_year;
112        if (! $end_year) $end_year = (DATE('Y') + 3);
113
114        $year_array = array();
115
116        for ($i = $year; $i <= $end_year; $i++) {
117            $key = substr($i, -2);
118            $year_array[$key] = $key;
119        }
120        return $year_array;
121    }
122
123    function getZeroMonth()
124    {
125
126        $month_array = array();
127        for ($i=1; $i <= 12; $i++) {
128            $val = sprintf('%02d', $i);
129            $month_array[$val] = $val;
130        }
131        return $month_array;
132    }   
133
134    function getMonth($default = false)
135    {
136        $month_array = array();
137
138        if ($default) $month_array[''] = '--';
139
140        for ($i=0; $i < 12; $i++) {
141            $month_array[$i + 1 ] = $i + 1;
142        }
143        return $month_array;
144    }   
145
146    function getDay($default = false)
147    {
148        $day_array = array();
149
150        if ($default) $day_array[''] = '--';
151
152        for ($i=0; $i < 31; $i++) {
153            $day_array[ $i + 1 ] = $i + 1;
154        }
155
156        return $day_array;
157    }
158
159    function getHour()
160    {
161
162        $hour_array = array();
163        for ($i=0; $i<=23; $i++) {
164            $hour_array[$i] = $i;
165        }
166
167        return $hour_array;
168    }
169
170    function getMinutes()
171    {
172
173        $minutes_array = array();
174        for ($i=0; $i<=59; $i++) {
175            $minutes_array[$i] = $i;
176        }
177
178        return $minutes_array;
179    }
180
181    function getMinutesInterval()
182    {
183
184        $minutes_array = array('00'=>'00', '30'=>'30');
185        return $minutes_array;
186    }
187}
Note: See TracBrowser for help on using the repository browser.