Pull the freebusy floating-time handling into a function

This commit is contained in:
Jamie McClymont 2018-11-27 15:26:53 +13:00
parent 28c78023b5
commit 5fc3875345
2 changed files with 13 additions and 7 deletions

View File

@ -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();

View File

@ -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());