From 911a6b6080a690e807f013bb375fdc2fe459a024 Mon Sep 17 00:00:00 2001 From: Tanguy Pruvot Date: Fri, 29 Oct 2010 09:17:58 +0200 Subject: [PATCH] check duration regexp result and ignore only common warning --- helpers/SG_iCal_Duration.php | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/helpers/SG_iCal_Duration.php b/helpers/SG_iCal_Duration.php index ad0a30b..74b57ef 100755 --- a/helpers/SG_iCal_Duration.php +++ b/helpers/SG_iCal_Duration.php @@ -21,12 +21,16 @@ class SG_iCal_Duration { */ public function __construct( $duration ) { if( $duration{0} == 'P' || (($duration{0} == '+' || $duration{0} == '-') && $duration{1} == 'P') ) { - preg_match('/P((\d+)W)?((\d+)D)?(T)?((\d+)H)?((\d+)M)?((\d+)S)?/', $duration, $matches); - $results = @ array('weeks'=>(int)$matches[2], - 'days'=>(int)$matches[4], - 'hours'=>(int)$matches[7], - 'minutes'=>(int)$matches[9], - 'seconds'=>(int)$matches[11]); + + if (preg_match('/P((\d+)W)?((\d+)D)?(T)?((\d+)H)?((\d+)M)?((\d+)S)?/', $duration, $matches) === 1) { + $results = array( + 'weeks'=> (int) $matches[2], + 'days'=> (int) $matches[4], + 'hours'=> (int)@ $matches[7], + 'minutes'=>(int)@ $matches[9], + 'seconds'=>(int)@ $matches[11] + ); //7-9-11 are optional, so ignore warnings if not found with @ + } $ts = 0; $ts += $results['seconds'];