root / drupal7 / sites / all / libraries / iCalcreator-2.22.1 / lib / iCaldateTime.class.php @ bad93dab
1 |
<?php
|
---|---|
2 |
/*********************************************************************************/
|
3 |
/**
|
4 |
*
|
5 |
* iCalcreator, a PHP rfc2445/rfc5545 solution.
|
6 |
*
|
7 |
* @copyright Copyright (c) 2007-2015 Kjell-Inge Gustafsson, kigkonsult, All rights reserved
|
8 |
* @link http://kigkonsult.se/iCalcreator/index.php
|
9 |
* @license http://kigkonsult.se/downloads/dl.php?f=LGPL
|
10 |
* @package iCalcreator
|
11 |
* @version 2.22
|
12 |
*/
|
13 |
/**
|
14 |
* This library is free software; you can redistribute it and/or
|
15 |
* modify it under the terms of the GNU Lesser General Public
|
16 |
* License as published by the Free Software Foundation; either
|
17 |
* version 2.1 of the License, or (at your option) any later version.
|
18 |
*
|
19 |
* This library is distributed in the hope that it will be useful,
|
20 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
21 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
22 |
* Lesser General Public License for more details.
|
23 |
*
|
24 |
* You should have received a copy of the GNU Lesser General Public
|
25 |
* License along with this library; if not, write to the Free Software
|
26 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
27 |
*/
|
28 |
/*********************************************************************************/
|
29 |
/**
|
30 |
* selectComponent help class
|
31 |
*
|
32 |
* @author Kjell-Inge Gustafsson, kigkonsult <ical@kigkonsult.se>
|
33 |
* @since 2.21.7 - 2015-03-10
|
34 |
*/
|
35 |
class iCaldateTime extends dateTime { |
36 |
/** @var string default date[-time] format */
|
37 |
public $dateFormat = 'Y-m-d H:i:s e'; |
38 |
/** @var string default object instance date[-time] 'key' */
|
39 |
public $key = null; |
40 |
/** @var array date[-time] origin */
|
41 |
public $SCbools = array(); |
42 |
/**
|
43 |
* return time (His) array
|
44 |
*
|
45 |
* @author Kjell-Inge Gustafsson, kigkonsult <ical@kigkonsult.se>
|
46 |
* @since 2.21.7 - 2015-03-07
|
47 |
* @return array
|
48 |
*/
|
49 |
public function getTime() { |
50 |
return explode( ':', $this->format( 'H:i:s' )); |
51 |
} |
52 |
/**
|
53 |
* return the timezone name
|
54 |
*
|
55 |
* @author Kjell-Inge Gustafsson, kigkonsult <ical@kigkonsult.se>
|
56 |
* @since 2.21.7 - 2015-03-07
|
57 |
* @return string
|
58 |
*/
|
59 |
public function getTimezoneName() { |
60 |
$tz = $this->getTimezone(); |
61 |
return $tz->getName(); |
62 |
} |
63 |
/**
|
64 |
* return formatted date
|
65 |
*
|
66 |
* @author Kjell-Inge Gustafsson, kigkonsult <ical@kigkonsult.se>
|
67 |
* @since 2.21.7 - 2015-03-07
|
68 |
* @param string $format
|
69 |
* @uses iCaldateTime::$dateFormat
|
70 |
* @return string
|
71 |
*/
|
72 |
public function format( $format=null ) { |
73 |
if( empty( $format ) && isset( $this->dateFormat )) |
74 |
$format = $this->dateFormat; |
75 |
return parent::format( $format ); |
76 |
} |
77 |
/**
|
78 |
* return iCaldateTime object instance based on date array and timezone(s)
|
79 |
*
|
80 |
* @author Kjell-Inge Gustafsson, kigkonsult <ical@kigkonsult.se>
|
81 |
* @since 2.21.11 - 2015-03-28
|
82 |
* @param array $date
|
83 |
* @param array $params
|
84 |
* @param array $tz
|
85 |
* @param string $dtstartTz
|
86 |
* @uses iCalUtilityFunctions::$fmt
|
87 |
* @uses iCaldateTime::getTimezoneName()
|
88 |
* @uses iCaldateTime::$dateFormat
|
89 |
* @uses iCaldateTime::$key
|
90 |
* @return object instance
|
91 |
*/
|
92 |
public static function factory( array $date, $params=null, $tz=null, $dtstartTz=null ) { |
93 |
if( isset( $params['TZID'] ) && ! empty( $params['TZID'] )) |
94 |
$tz = ( 'Z' == $params['TZID'] ) ? 'UTC' : $params['TZID']; |
95 |
elseif( isset( $tz['tz'] ) && ! empty( $tz['tz'] )) |
96 |
$tz = ( 'Z' == $tz['tz'] ) ? 'UTC' : $tz['tz']; |
97 |
else
|
98 |
$tz = ini_get( 'date_default_timezone_set' ); |
99 |
$strdate = sprintf( iCalUtilityFunctions::$fmt['Ymd'], (int) $date['year'], (int) $date['month'], (int) $date['day'] ); |
100 |
if( isset( $date['hour'] )) |
101 |
$strdate .= 'T'.sprintf( iCalUtilityFunctions::$fmt['His'], (int) $date['hour'], (int) $date['min'], (int) $date['sec'] ); |
102 |
try {
|
103 |
$timezone = new DateTimeZone( $tz ); |
104 |
$d = new iCaldateTime( $strdate, $timezone ); |
105 |
} |
106 |
catch( Exception $e ) { |
107 |
$d = new iCaldateTime( $strdate ); |
108 |
} |
109 |
if( ! empty( $dtstartTz )) { |
110 |
if( 'Z' == $dtstartTz ) |
111 |
$dtstartTz = 'UTC'; |
112 |
if( $dtstartTz != $d->getTimezoneName()) { // set the same timezone as dtstart |
113 |
try {
|
114 |
$timezone = new DateTimeZone( $dtstartTz ); |
115 |
$d->setTimezone( $timezone ); |
116 |
} |
117 |
catch( Exception $e ) {} |
118 |
} |
119 |
} |
120 |
unset( $timezone, $strdate ); |
121 |
if( isset( $params['VALUE'] ) && ( 'DATE' == $params['VALUE'] )) { |
122 |
$d->dateFormat = 'Y-m-d'; |
123 |
$d->key = $d->format( 'Ymd' ); |
124 |
} |
125 |
else
|
126 |
$d->key = $d->format( 'YmdHis' ); |
127 |
return $d; |
128 |
} |
129 |
} |