Duration.php 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. <?php
  2. namespace Sabre\VObject\Property\ICalendar;
  3. use Sabre\VObject\DateTimeParser;
  4. use Sabre\VObject\Property;
  5. /**
  6. * Duration property.
  7. *
  8. * This object represents DURATION values, as defined here:
  9. *
  10. * http://tools.ietf.org/html/rfc5545#section-3.3.6
  11. *
  12. * @copyright Copyright (C) fruux GmbH (https://fruux.com/)
  13. * @author Evert Pot (http://evertpot.com/)
  14. * @license http://sabre.io/license/ Modified BSD License
  15. */
  16. class Duration extends Property
  17. {
  18. /**
  19. * In case this is a multi-value property. This string will be used as a
  20. * delimiter.
  21. *
  22. * @var string
  23. */
  24. public $delimiter = ',';
  25. /**
  26. * Sets a raw value coming from a mimedir (iCalendar/vCard) file.
  27. *
  28. * This has been 'unfolded', so only 1 line will be passed. Unescaping is
  29. * not yet done, but parameters are not included.
  30. *
  31. * @param string $val
  32. */
  33. public function setRawMimeDirValue($val)
  34. {
  35. $this->setValue(explode($this->delimiter, $val));
  36. }
  37. /**
  38. * Returns a raw mime-dir representation of the value.
  39. *
  40. * @return string
  41. */
  42. public function getRawMimeDirValue()
  43. {
  44. return implode($this->delimiter, $this->getParts());
  45. }
  46. /**
  47. * Returns the type of value.
  48. *
  49. * This corresponds to the VALUE= parameter. Every property also has a
  50. * 'default' valueType.
  51. *
  52. * @return string
  53. */
  54. public function getValueType()
  55. {
  56. return 'DURATION';
  57. }
  58. /**
  59. * Returns a DateInterval representation of the Duration property.
  60. *
  61. * If the property has more than one value, only the first is returned.
  62. *
  63. * @return \DateInterval
  64. */
  65. public function getDateInterval()
  66. {
  67. $parts = $this->getParts();
  68. $value = $parts[0];
  69. return DateTimeParser::parseDuration($value);
  70. }
  71. }