Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: 18275f0d87
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

executable file 57 lines (47 sloc) 1.392 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
<?php // BUILD: Remove line

/**
* A class for calculating how many seconds a duration-string is
*
* @package SG_iCalReader
* @author Morten Fangel (C) 2008
* @license http://creativecommons.org/licenses/by-sa/2.5/dk/deed.en_GB CC-BY-SA-DK
*/

class SG_iCal_Duration {
protected $dur;

/**
* Constructs a new SG_iCal_Duration from a duration-rule.
* The basic build-up of DURATIONs are:
* (["+"] / "-") "P" (dur-date / dur-date + "T" + dur-time / dur-time / dur-week)
* Is solved via a really fugly reg-exp with way to many ()'s..
*
* @param $duration string
*/
public function __construct( $duration ) {

$ts = 0;

if (preg_match('/[\\+\\-]{0,1}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]
);

$ts += $results['seconds'];
$ts += 60 * $results['minutes'];
$ts += 60 * 60 * $results['hours'];
$ts += 24 * 60 * 60 * $results['days'];
$ts += 7 * 24 * 60 * 60 * $results['weeks'];
} else {
// Invalid duration!
}

$dir = ($duration{0} == '-') ? -1 : 1;

$this->dur = $dir * $ts;
}

/**
* Returns the duration in seconds
* @return int
*/
public function getDuration() {
return $this->dur;
}
}
Something went wrong with that request. Please try again.