Overview

Namespaces

  • Peach
    • DF
    • DT
    • Http
      • Body
      • Header
    • Markup
    • Util

Classes

  • Peach\DF\Base64Codec
  • Peach\DF\CodecChain
  • Peach\DF\JsonCodec
  • Peach\DF\SerializationCodec
  • Peach\DF\Utf8Codec
  • Peach\DT\AbstractTime
  • Peach\DT\Clock
  • Peach\DT\Date
  • Peach\DT\Datetime
  • Peach\DT\DefaultClock
  • Peach\DT\FixedClock
  • Peach\DT\FormatWrapper
  • Peach\DT\HttpDateFormat
  • Peach\DT\OffsetClock
  • Peach\DT\ShiftFormat
  • Peach\DT\SimpleFormat
  • Peach\DT\TimeEquator
  • Peach\DT\Timestamp
  • Peach\DT\TimeWrapper
  • Peach\DT\UnixTimeFormat
  • Peach\DT\Util
  • Peach\DT\W3cDatetimeFormat
  • Peach\Http\Body
  • Peach\Http\Body\CodecRenderer
  • Peach\Http\Body\StringRenderer
  • Peach\Http\DefaultEndpoint
  • Peach\Http\Header\CookieItem
  • Peach\Http\Header\CookieOptions
  • Peach\Http\Header\HttpDate
  • Peach\Http\Header\NoField
  • Peach\Http\Header\QualityValues
  • Peach\Http\Header\Raw
  • Peach\Http\Header\SetCookie
  • Peach\Http\Header\Status
  • Peach\Http\Request
  • Peach\Http\Response
  • Peach\Http\Util
  • Peach\Markup\AbstractHelper
  • Peach\Markup\AbstractRenderer
  • Peach\Markup\BaseHelper
  • Peach\Markup\BreakControlWrapper
  • Peach\Markup\Builder
  • Peach\Markup\Code
  • Peach\Markup\Comment
  • Peach\Markup\ContainerElement
  • Peach\Markup\Context
  • Peach\Markup\DebugBuilder
  • Peach\Markup\DebugContext
  • Peach\Markup\DefaultBreakControl
  • Peach\Markup\DefaultBuilder
  • Peach\Markup\DefaultContext
  • Peach\Markup\Element
  • Peach\Markup\EmptyElement
  • Peach\Markup\HelperObject
  • Peach\Markup\HtmlHelper
  • Peach\Markup\Indent
  • Peach\Markup\MinimalBreakControl
  • Peach\Markup\NameBreakControl
  • Peach\Markup\NameValidator
  • Peach\Markup\NodeList
  • Peach\Markup\None
  • Peach\Markup\SgmlRenderer
  • Peach\Markup\Text
  • Peach\Markup\XmlRenderer
  • Peach\Util\AbstractMapEntry
  • Peach\Util\ArrayMap
  • Peach\Util\ArrayMapEntry
  • Peach\Util\Arrays
  • Peach\Util\DefaultComparator
  • Peach\Util\DefaultEquator
  • Peach\Util\HashMap
  • Peach\Util\HashMapEntry
  • Peach\Util\Strings
  • Peach\Util\Values

Interfaces

  • Peach\DF\Codec
  • Peach\DT\Format
  • Peach\DT\Time
  • Peach\Http\BodyRenderer
  • Peach\Http\Endpoint
  • Peach\Http\HeaderField
  • Peach\Http\MultiHeaderField
  • Peach\Http\SingleHeaderField
  • Peach\Markup\BreakControl
  • Peach\Markup\Component
  • Peach\Markup\Container
  • Peach\Markup\Helper
  • Peach\Markup\Node
  • Peach\Markup\Renderer
  • Peach\Util\Comparable
  • Peach\Util\Comparator
  • Peach\Util\Equator
  • Peach\Util\Map
  • Peach\Util\MapEntry
  • Overview
  • Namespace
  • Class
  1: <?php
  2: /*
  3:  * Copyright (c) 2014 @trashtoy
  4:  * https://github.com/trashtoy/
  5:  * 
  6:  * Permission is hereby granted, free of charge, to any person obtaining a copy of
  7:  * this software and associated documentation files (the "Software"), to deal in
  8:  * the Software without restriction, including without limitation the rights to use,
  9:  * copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
 10:  * Software, and to permit persons to whom the Software is furnished to do so,
 11:  * subject to the following conditions:
 12:  * 
 13:  * The above copyright notice and this permission notice shall be included in all
 14:  * copies or substantial portions of the Software.
 15:  * 
 16:  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 17:  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
 18:  * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
 19:  * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
 20:  * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
 21:  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 22:  */
 23: /**
 24:  * PHP class file.
 25:  * @auhtor trashtoy
 26:  * @since  2.0.0
 27:  */
 28: namespace Peach\DT;
 29: 
 30: /**
 31:  * Unix time ({@link http://www.php.net/manual/function.time.php time()} の返り値や
 32:  * {@link http://www.php.net/manual/function.date.php date()} の引数として使用される整数)
 33:  * と時間オブジェクトの相互変換を行うクラスです.
 34:  * 
 35:  * このクラスはシングルトンです. {@link UnixTimeFormat::getInstance()}
 36:  * からオブジェクトを取得してください.
 37:  */
 38: class UnixTimeFormat implements Format
 39: {
 40:     /**
 41:      * このクラスは getInstance() からインスタンス化します.
 42:      */
 43:     private function __construct() {}
 44:     
 45:     /**
 46:      * このクラスのインスタンスを取得します.
 47:      * @return UnixTimeFormat
 48:      * @codeCoverageIgnore
 49:      */
 50:     public static function getInstance()
 51:     {
 52:         static $instance = null;
 53:         if (!isset($instance)) {
 54:             $instance = new self();
 55:         }
 56:         return $instance;
 57:     }
 58:     
 59:     /**
 60:      * 指定されたタイムスタンプを Date に変換します.
 61:      * 
 62:      * @param  string $format タイムスタンプ
 63:      * @return Date           変換結果
 64:      */
 65:     public function parseDate($format)
 66:     {
 67:         $time  = intval($format);
 68:         $year  = date("Y", $time);
 69:         $month = date("n", $time);
 70:         $date  = date("d", $time);
 71:         return new Date($year, $month, $date);
 72:     }
 73:     
 74:     /**
 75:      * 指定されたタイムスタンプを Datetime に変換します.
 76:      * 
 77:      * @param  string $format タイムスタンプ
 78:      * @return Datetime       変換結果
 79:      */
 80:     public function parseDatetime($format)
 81:     {
 82:         $time  = intval($format);
 83:         $year  = date("Y", $time);
 84:         $month = date("n", $time);
 85:         $date  = date("d", $time);
 86:         $hour  = date("H", $time);
 87:         $min   = date("i", $time);
 88:         return new Datetime($year, $month, $date, $hour, $min);
 89:     }
 90:     
 91:     /**
 92:      * 指定されたタイムスタンプを Timestamp に変換します.
 93:      * @param  string $format タイムスタンプ
 94:      * @return Timestamp      変換結果
 95:      */
 96:     public function parseTimestamp($format)
 97:     {
 98:         $time  = intval($format);
 99:         $year  = date("Y", $time);
100:         $month = date("n", $time);
101:         $date  = date("d", $time);
102:         $hour  = date("H", $time);
103:         $min   = date("i", $time);
104:         $sec   = date("s", $time);
105:         return new Timestamp($year, $month, $date, $hour, $min, $sec);
106:     }
107:     
108:     /**
109:      * 指定されたオブジェクトを Timestamp 型にキャストして
110:      * {@link UnixTimeFormat::formatTimestamp()}
111:      * を実行した結果を返します.
112:      * 
113:      * @param  Date $d 書式化する時間オブジェクト
114:      * @return string  指定された日付の 0 時 0 分 0 秒のタイムスタンプ
115:      */
116:     public function formatDate(Date $d)
117:     {
118:         return $this->formatTimestamp($d->toTimestamp());
119:     }
120:     
121:     /**
122:      * 指定されたオブジェクトを Timestamp 型にキャストして
123:      * {@link UnixTimeFormat::formatTimestamp()}
124:      * を実行した結果を返します.
125:      * 
126:      * @param  Datetime $d 書式化する時間オブジェクト
127:      * @return string      指定された時刻の 0 秒のタイムスタンプ
128:      */
129:     public function formatDatetime(Datetime $d)
130:     {
131:         return $this->formatTimestamp($d->toTimestamp());
132:     }
133:     
134:     /**
135:      * 指定された時刻をタイムスタンプに変換します.
136:      * 
137:      * このメソッドは、引数の Timestamp オブジェクトが持つ各フィールド
138:      * (年月日・時分秒) の値から {@link http://www.php.net/manual/function.mktime.php mktime()}
139:      * を行い, その結果を返り値とします.
140:      * 
141:      * ただし, 返り値が string 型となることに注意してください.
142:      * 
143:      * @param  Timestamp $d 書式化対象の時間オブジェクト
144:      * @return string       指定された時刻のタイムスタンプ
145:      */
146:     public function formatTimestamp(Timestamp $d)
147:     {
148:         $hour  = $d->get('hour');
149:         $min   = $d->get('minute');
150:         $sec   = $d->get('second');
151:         $month = $d->get('month');
152:         $date  = $d->get('date');
153:         $year  = $d->get('year');
154:         return strval(mktime($hour, $min, $sec, $month, $date, $year));
155:     }
156: }
157: 
PEACH2 API documentation generated by ApiGen