summaryrefslogtreecommitdiff
path: root/lib/Kolab/Utils/VObjectUtils.php
diff options
context:
space:
mode:
authorThomas Bruederli <bruederli@kolabsys.com>2013-03-07 16:07:08 (GMT)
committerThomas Bruederli <bruederli@kolabsys.com>2013-03-07 16:07:08 (GMT)
commit6b8cdd9ab0d884fa27a0ad4da39e4981bdecf513 (patch)
treef551dc55fdd84ff90b158efad96cadfafcdef24b /lib/Kolab/Utils/VObjectUtils.php
parent598cc5aa7625257f2bd06bdc96836d633b49f452 (diff)
downloadiRony-6b8cdd9ab0d884fa27a0ad4da39e4981bdecf513.tar.gz
Add support for CardDAV
Diffstat (limited to 'lib/Kolab/Utils/VObjectUtils.php')
-rw-r--r--lib/Kolab/Utils/VObjectUtils.php69
1 files changed, 69 insertions, 0 deletions
diff --git a/lib/Kolab/Utils/VObjectUtils.php b/lib/Kolab/Utils/VObjectUtils.php
new file mode 100644
index 0000000..dadd7be
--- /dev/null
+++ b/lib/Kolab/Utils/VObjectUtils.php
@@ -0,0 +1,69 @@
+<?php
+
+namespace Kolab\Utils;
+
+use Sabre\VObject\Property;
+
+/**
+ * Helper class proviting utility functions for VObject data encoding
+ */
+class VObjectUtils
+{
+
+ /**
+ * Helper method to correctly interpret an all-day date value
+ */
+ public static function convert_datetime($prop)
+ {
+ if (empty($prop)) {
+ return null;
+ }
+ else if ($prop instanceof Property\MultiDateTime) {
+ $dt = array();
+ $dateonly = ($prop->getDateType() & Property\DateTime::DATE);
+ foreach ($prop->getDateTimes() as $item) {
+ $item->_dateonly = $dateonly;
+ $dt[] = $item;
+ }
+ }
+ else if ($prop instanceof Property\DateTime) {
+ $dt = $prop->getDateTime();
+ if ($prop->getDateType() & Property\DateTime::DATE) {
+ $dt->_dateonly = true;
+ }
+ }
+ else if ($prop instanceof \DateTime) {
+ $dt = $prop;
+ }
+
+ return $dt;
+ }
+
+
+ /**
+ * Create a Sabre\VObject\Property instance from a PHP DateTime object
+ *
+ * @param string Property name
+ * @param object DateTime
+ */
+ public static function datetime_prop($name, $dt, $utc = false)
+ {
+ $vdt = new Property\DateTime($name);
+ $vdt->setDateTime($dt, $dt->_dateonly ? Property\DateTime::DATE : ($utc ? Property\DateTime::UTC : Property\DateTime::LOCALTZ));
+ return $vdt;
+ }
+
+ /**
+ * Copy values from one hash array to another using a key-map
+ */
+ public static function map_keys($values, $map)
+ {
+ $out = array();
+ foreach ($map as $from => $to) {
+ if (isset($values[$from]))
+ $out[$to] = $values[$from];
+ }
+ return $out;
+ }
+
+} \ No newline at end of file