Overview

Packages

  • Jyxo_Beholder
  • Jyxo_Charset
  • Jyxo_Color
  • Jyxo_Css
  • Jyxo_ErrorHandling
  • Jyxo_FirePhp
  • Jyxo_Gettext
    • Parser
  • Jyxo_Html
  • Jyxo_Input
    • Chain
    • Filter
    • Validator
  • Jyxo_Mail
    • Email
    • Parser
    • Sender
  • Jyxo_Rpc
    • Json
    • Xml
  • Jyxo_Shell
  • Jyxo_SpamFilter
  • Jyxo_Spl
  • Jyxo_String
  • Jyxo_Svn
  • Jyxo_Time
  • Jyxo_Timer
  • Jyxo_Webdav
  • Jyxo_XmlReader
  • PHP

Classes

  • Jyxo_Time_Composer
  • Jyxo_Time_Time
  • Jyxo_Time_Util

Exceptions

  • Jyxo_Time_ComposerException
  • Overview
  • Package
  • Class
  • Tree
  • Deprecated
  1: <?php
  2: 
  3: /**
  4:  * Jyxo PHP Library
  5:  *
  6:  * LICENSE
  7:  *
  8:  * This source file is subject to the new BSD license that is bundled
  9:  * with this package in the file license.txt.
 10:  * It is also available through the world-wide-web at this URL:
 11:  * https://github.com/jyxo/php/blob/master/license.txt
 12:  */
 13: 
 14: /**
 15:  * Time composer used to compose a date/time part by part.
 16:  *
 17:  * @category Jyxo
 18:  * @package Jyxo_Time
 19:  * @copyright Copyright (c) 2005-2011 Jyxo, s.r.o.
 20:  * @license https://github.com/jyxo/php/blob/master/license.txt
 21:  * @author Martin Šamšula
 22:  */
 23: class Jyxo_Time_Composer
 24: {
 25:     /**
 26:      * Maximal year.
 27:      *
 28:      * @var integer
 29:      */
 30:     const YEAR_MAX = 2037;
 31: 
 32:     /**
 33:      * Minimal year.
 34:      *
 35:      * @var integer
 36:      */
 37:     const YEAR_MIN = 1902;
 38: 
 39:     /**
 40:      * Day.
 41:      *
 42:      * @var integer
 43:      */
 44:     private $day = 0;
 45: 
 46:     /**
 47:      * Month.
 48:      *
 49:      * @var integer
 50:      */
 51:     private $month = 0;
 52: 
 53:     /**
 54:      * Year.
 55:      *
 56:      * @var integer
 57:      */
 58:     private $year = 0;
 59: 
 60:     /**
 61:      * Second.
 62:      *
 63:      * @var integer
 64:      */
 65:     private $second = 0;
 66: 
 67:     /**
 68:      * Minute.
 69:      *
 70:      * @var integer
 71:      */
 72:     private $minute = 0;
 73: 
 74:     /**
 75:      * Hour.
 76:      *
 77:      * @var integer
 78:      */
 79:     private $hour = 0;
 80: 
 81:     /**
 82:      * Returns the composed date/time.
 83:      *
 84:      * @return Jyxo_Time_Time
 85:      * @throws Jyxo_Time_ComposerException If the date is incomplete or invalid
 86:      */
 87:     public function getTime()
 88:     {
 89:         if ($this->month === 0 || $this->year === 0 || $this->day === 0) {
 90:             throw new Jyxo_Time_ComposerException('Date not complete.', Jyxo_Time_ComposerException::NOT_COMPLETE);
 91:         }
 92: 
 93:         // Checkdate checks if the provided day is valid. Month and year are validated in their getters.
 94:         // The year is between 1 and 32767 inclusive.
 95:         if (!checkdate($this->month, $this->day, $this->year)) {
 96:             throw new Jyxo_Time_ComposerException('Day out of range.', Jyxo_Time_ComposerException::INVALID);
 97:         }
 98: 
 99:         $time = mktime($this->hour, $this->minute, $this->second, $this->month, $this->day, $this->year);
100:         return new Jyxo_Time_Time($time);
101:     }
102: 
103:     /**
104:      * Sets the day.
105:      *
106:      * @param integer $day Day of the month
107:      * @return Jyxo_Time_Composer
108:      * @throws Jyxo_Time_ComposerException If the provided day is invalid
109:      */
110:     public function setDay($day)
111:     {
112:         $day = (integer) $day;
113: 
114:         if ($day < 1 || $day > 31) {
115:             throw new Jyxo_Time_ComposerException('Day out of range.', Jyxo_Time_ComposerException::DAY);
116:         }
117: 
118:         $this->day = $day;
119: 
120:         return $this;
121:     }
122: 
123:     /**
124:      * Sets the month.
125:      *
126:      * @param integer $month Month
127:      * @return Jyxo_Time_Composer
128:      * @throws Jyxo_Time_ComposerException If the month is invalid.
129:      */
130:     public function setMonth($month)
131:     {
132:         $month = (integer) $month;
133: 
134:         if ($month < 1 || $month > 12) {
135:             throw new Jyxo_Time_ComposerException('Month out of range.', Jyxo_Time_ComposerException::MONTH);
136:         }
137: 
138:         $this->month = $month;
139: 
140:         return $this;
141:     }
142: 
143:     /**
144:      * Sets the year.
145:      *
146:      * @param integer $year Year
147:      * @return Jyxo_Time_Composer
148:      * @throws Jyxo_Time_ComposerException If the year is invalid.
149:      */
150:     public function setYear($year)
151:     {
152:         $year = (integer) $year;
153: 
154:         if ($year > self::YEAR_MAX || $year < self::YEAR_MIN) {
155:             throw new Jyxo_Time_ComposerException('Year out of range.', Jyxo_Time_ComposerException::YEAR);
156:         }
157: 
158:         $this->year = $year;
159: 
160:         return $this;
161:     }
162: 
163:     /**
164:      * Sets seconds.
165:      *
166:      * @param integer $second Seconds
167:      * @return Jyxo_Time_Composer
168:      * @throws Jyxo_Time_ComposerException If seconds are invalid.
169:      */
170:     public function setSecond($second)
171:     {
172:         $second = (integer) $second;
173: 
174:         if ($second < 0 || $second > 60) {
175:             throw new Jyxo_Time_ComposerException('Second out of range.', Jyxo_Time_ComposerException::SECOND);
176:         }
177: 
178:         $this->second = $second;
179: 
180:         return $this;
181:     }
182: 
183:     /**
184:      * Sets minutes.
185:      *
186:      * @param integer $minute Minutes
187:      * @return Jyxo_Time_Composer
188:      * @throws Jyxo_Time_ComposerException If minutes are invalid.
189:      */
190:     public function setMinute($minute)
191:     {
192:         $minute = (integer) $minute;
193: 
194:         if ($minute < 0 || $minute > 60) {
195:             throw new Jyxo_Time_ComposerException('Minute out of range.', Jyxo_Time_ComposerException::MINUTE);
196:         }
197: 
198:         $this->minute = $minute;
199: 
200:         return $this;
201:     }
202: 
203:     /**
204:      * Sets hours.
205:      *
206:      * @param integer $hour Hours
207:      * @return Jyxo_Time_Composer
208:      * @throws Jyxo_Time_ComposerException If hours are invalid.
209:      */
210:     public function setHour($hour)
211:     {
212:         $hour = (integer) $hour;
213: 
214:         if ($hour < 0 || $hour > 24) {
215:             throw new Jyxo_Time_ComposerException('Hour out of range.', Jyxo_Time_ComposerException::HOUR);
216:         }
217: 
218:         $this->hour = $hour;
219: 
220:         return $this;
221:     }
222: }
223: 
Jyxo PHP Library API documentation generated by ApiGen 2.3.0