Time.php 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. <?php
  2. namespace Sabre\VObject\Property;
  3. use Sabre\VObject\DateTimeParser;
  4. /**
  5. * Time property
  6. *
  7. * This object encodes TIME values.
  8. *
  9. * @copyright Copyright (C) 2007-2014 fruux GmbH. All rights reserved.
  10. * @author Evert Pot (http://evertpot.com/)
  11. * @license http://sabre.io/license/ Modified BSD License
  12. */
  13. class Time extends Text {
  14. /**
  15. * In case this is a multi-value property. This string will be used as a
  16. * delimiter.
  17. *
  18. * @var string|null
  19. */
  20. public $delimiter = null;
  21. /**
  22. * Returns the type of value.
  23. *
  24. * This corresponds to the VALUE= parameter. Every property also has a
  25. * 'default' valueType.
  26. *
  27. * @return string
  28. */
  29. public function getValueType() {
  30. return "TIME";
  31. }
  32. /**
  33. * Returns the value, in the format it should be encoded for json.
  34. *
  35. * This method must always return an array.
  36. *
  37. * @return array
  38. */
  39. public function getJsonValue() {
  40. $parts = DateTimeParser::parseVCardTime($this->getValue());
  41. $timeStr = '';
  42. // Hour
  43. if (!is_null($parts['hour'])) {
  44. $timeStr.=$parts['hour'];
  45. if (!is_null($parts['minute'])) {
  46. $timeStr.=':';
  47. }
  48. } else {
  49. // We know either minute or second _must_ be set, so we insert a
  50. // dash for an empty value.
  51. $timeStr.='-';
  52. }
  53. // Minute
  54. if (!is_null($parts['minute'])) {
  55. $timeStr.=$parts['minute'];
  56. if (!is_null($parts['second'])) {
  57. $timeStr.=':';
  58. }
  59. } else {
  60. if (isset($parts['second'])) {
  61. // Dash for empty minute
  62. $timeStr.='-';
  63. }
  64. }
  65. // Second
  66. if (!is_null($parts['second'])) {
  67. $timeStr.=$parts['second'];
  68. }
  69. // Timezone
  70. if (!is_null($parts['timezone'])) {
  71. $timeStr.=$parts['timezone'];
  72. }
  73. return array($timeStr);
  74. }
  75. }