From 5fc38753458da04f4d15891ec44b93c592846b79 Mon Sep 17 00:00:00 2001 From: Jamie McClymont Date: Tue, 27 Nov 2018 15:26:53 +1300 Subject: [PATCH] Pull the freebusy floating-time handling into a function --- inc/RRule.php | 12 ++++++++++++ inc/freebusy-functions.php | 8 +------- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/inc/RRule.php b/inc/RRule.php index bf4dc9b8..db215567 100644 --- a/inc/RRule.php +++ b/inc/RRule.php @@ -305,6 +305,18 @@ class RepeatRuleDateTime extends DateTime { return $this; } + public static function withFallbackTzid( $date, $fallback_tzid ) { + // Floating times or dates (either VALUE=DATE or with no TZID) can default to the collection's tzid, if one is set + + if ($date->GetParameterValue('VALUE') == 'DATE' && isset($fallback_tzid)) { + return new RepeatRuleDateTime($date->Value()."T000000", new RepeatRuleTimeZone($fallback_tzid)); + } else if ($date->GetParameterValue('TZID') === null && isset($fallback_tzid)) { + return new RepeatRuleDateTime($date->Value(), new RepeatRuleTimeZone($fallback_tzid)); + } else { + return new RepeatRuleDateTime($date); + } + } + public function __toString() { return (string)parent::format(self::$Format) . ' ' . parent::getTimeZone()->getName(); diff --git a/inc/freebusy-functions.php b/inc/freebusy-functions.php index 888c6f1e..d0ab2fe9 100644 --- a/inc/freebusy-functions.php +++ b/inc/freebusy-functions.php @@ -66,13 +66,7 @@ function get_freebusy( $path_match, $range_start, $range_end, $bin_privs = null } // Floating dtstarts (either VALUE=DATE or with no TZID) can default to the collection's tzid, if one is set - if ($start_date->GetParameterValue('VALUE') == 'DATE' && isset($collection_tzid)) { - $start_date = new RepeatRuleDateTime($start_date->Value()."T000000", new RepeatRuleTimeZone($collection_tzid)); - } else if ($start_date->GetParameterValue('TZID') === null && isset($collection_tzid)) { - $start_date = new RepeatRuleDateTime($start_date->Value(), new RepeatRuleTimeZone($collection_tzid)); - } else { - $start_date = new RepeatRuleDateTime($start_date); - } + $start_date = RepeatRuleDateTime::withFallbackTzid( $start_date, $collection_tzid ); $duration = $v->GetProperty('DURATION'); $duration = ( !isset($duration) ? 'P1D' : $duration->Value());