Mercurial > hg > rc1
comparison vendor/sabre/vobject/lib/Property/Time.php @ 7:430dbd5346f7
vendor sabre as distributed
| author | Charlie Root |
|---|---|
| date | Sat, 13 Jan 2018 09:06:10 -0500 |
| parents | |
| children |
comparison
equal
deleted
inserted
replaced
| 6:cec75ba50afc | 7:430dbd5346f7 |
|---|---|
| 1 <?php | |
| 2 | |
| 3 namespace Sabre\VObject\Property; | |
| 4 | |
| 5 use Sabre\VObject\DateTimeParser; | |
| 6 | |
| 7 /** | |
| 8 * Time property | |
| 9 * | |
| 10 * This object encodes TIME values. | |
| 11 * | |
| 12 * @copyright Copyright (C) 2011-2015 fruux GmbH (https://fruux.com/). | |
| 13 * @author Evert Pot (http://evertpot.com/) | |
| 14 * @license http://sabre.io/license/ Modified BSD License | |
| 15 */ | |
| 16 class Time extends Text { | |
| 17 | |
| 18 /** | |
| 19 * In case this is a multi-value property. This string will be used as a | |
| 20 * delimiter. | |
| 21 * | |
| 22 * @var string|null | |
| 23 */ | |
| 24 public $delimiter = null; | |
| 25 | |
| 26 /** | |
| 27 * Returns the type of value. | |
| 28 * | |
| 29 * This corresponds to the VALUE= parameter. Every property also has a | |
| 30 * 'default' valueType. | |
| 31 * | |
| 32 * @return string | |
| 33 */ | |
| 34 public function getValueType() { | |
| 35 | |
| 36 return "TIME"; | |
| 37 | |
| 38 } | |
| 39 | |
| 40 /** | |
| 41 * Returns the value, in the format it should be encoded for json. | |
| 42 * | |
| 43 * This method must always return an array. | |
| 44 * | |
| 45 * @return array | |
| 46 */ | |
| 47 public function getJsonValue() { | |
| 48 | |
| 49 $parts = DateTimeParser::parseVCardTime($this->getValue()); | |
| 50 | |
| 51 $timeStr = ''; | |
| 52 | |
| 53 // Hour | |
| 54 if (!is_null($parts['hour'])) { | |
| 55 $timeStr.=$parts['hour']; | |
| 56 | |
| 57 if (!is_null($parts['minute'])) { | |
| 58 $timeStr.=':'; | |
| 59 } | |
| 60 } else { | |
| 61 // We know either minute or second _must_ be set, so we insert a | |
| 62 // dash for an empty value. | |
| 63 $timeStr.='-'; | |
| 64 } | |
| 65 | |
| 66 // Minute | |
| 67 if (!is_null($parts['minute'])) { | |
| 68 $timeStr.=$parts['minute']; | |
| 69 | |
| 70 if (!is_null($parts['second'])) { | |
| 71 $timeStr.=':'; | |
| 72 } | |
| 73 } else { | |
| 74 if (isset($parts['second'])) { | |
| 75 // Dash for empty minute | |
| 76 $timeStr.='-'; | |
| 77 } | |
| 78 } | |
| 79 | |
| 80 // Second | |
| 81 if (!is_null($parts['second'])) { | |
| 82 $timeStr.=$parts['second']; | |
| 83 } | |
| 84 | |
| 85 // Timezone | |
| 86 if (!is_null($parts['timezone'])) { | |
| 87 $timeStr.=$parts['timezone']; | |
| 88 } | |
| 89 | |
| 90 return array($timeStr); | |
| 91 | |
| 92 } | |
| 93 | |
| 94 } |
