Duration.php 1.9 KB

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