Source for file OCSP_DATE.phpclass
Documentation is available at OCSP_DATE.phpclass
* Common Date Functions and Class
* @project Open CSP-Management
* @author Peter Krebs (pk)<pitlinz@users.sourceforge.net>
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
* Note: it seams that the php function mktime has problems with dates > 2037
* @project Open CSP-Management
* @author Peter Krebs (pk)<pitlinz@users.sourceforge.net>
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
* @param boolean $setNow (if true the current timestamp is set to the object
// echo "<pre>setNow()\n";print_r($this);echo "</pre>";
* returns if the Date is null
* NOTE: if year is 0 and day or month lower 1 the date is considered as null
* @version pk-06-08-08 $this->myYear == 0 &&
* @version pk-06-11-27 return true if ((intval($this->myDay) < 1) || (intval($this->myMonth) < 1))
// <pk-06-08-08> it seams mktime has problems with dates > 2037
// return ($this->getLinuxTime() ? False : True);
* sets the date to a linux timestamp
* @var double $aTime if 0 -> the date is set to NULL
* @returns boolean True if not zero else false
// echo "<pre>";print_r($this);echo "</pre>";
* sets the date from a db string
if (ereg("^([0-9]{4}).([0-9]{1,2}).([0-9]{1,2}).([0-9]{1,2}):([0-9]{1,2}):([0-9]{1,2})(.*)",$dbValue,$arr_res))
$this->myDay=
$arr_res[3];
if (ereg("^([0-9]{4}).([0-9]{1,2}).([0-9]{1,2})(.*)",$dbValue,$arr_res))
$this->myDay=
$arr_res[3];
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
* returns the year as integer (4 digets)
* sets the year as integer (4 digets)
* returns if $this->myYear is a leap year (feb 29 days)
if (($this->myYear %
4) !=
0) return False;
if (($this->myYear %
400) ==
0) return True;
if (($this->myYear %
100) ==
0) return False;
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
* returns the month as integer (1..12)
* @param boolean $with2Digets add leading zero?
* returns the monthname from the global array $OCSP_VAL['monthNames']
* if $aMonth > 0 the method can be called as static function
* @global array $OCSP_VAL
return $OCSP_VAL['monthNames'][$aMonth];
* returns a short monthname (4 letters or 3 letter and dot)
return $GLOBALS['MONTHNAMES'][$this->myMonth];
* returns the days of the current month
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
* returns the ISO-8601 week number
* returns the ISO-8601 week number of
* the week of the 1st day of a month
* calculate the first monday of year due to ISO8601 and returns
* the linux timestamp of it
// Sunday .. Wednesday calc back
* sets to the Monday in week (ISO8601)
$i_days =
(intval($week)-
1)*
7;
* sets to the Monday 00:00:00 of the current week
* Numeric representation of the day of the weekday
* 0 (for Sunday) through 6 (for Saturday)
// if ($this->isHoliday()) return 0;
* returns if the day is a workday or not
* returns True for Monday - Friday
* returns False for Saturday, Sunday and holidays
if ($this->isHoliday()) return False; // pk-05-12-23
return (($wd >
0 &&
$wd <
6) ?
True :
False);
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
* returns the day (of month [1..31])
* returns the day of the week (0 Sunday,1 Monday,....6 Saturday)
* taken from: http://www.terra.es/personal2/grimmer/
$i_ret=
$i_y2+
floor($i_y2/
4);
$arr_mCode=
array(1=>
6,2=>
2,3=>
2,4=>
5,5=>
0,6=>
3,7=>
5,8=>
1,9=>
4,10=>
6,11=>
2,12=>
4);
while($i_ret <
0) $i_ret=
$i_ret+
7;
//return date('w',$this->getLinuxTime());
* @global array $OCSP_VAL
return $OCSP_VAL['dayNameShort'][$dayNr];
* returns if the current date is a holiday
* @return array (the ical entry)
if (!is_array($OCSP_VAL['holidays_'.
$country]))
//print_r($OCSP_VAL['holidays_'.$country]);
foreach($OCSP_VAL['holidays_'.
$country] as $a_ical)
if (substr(trim($a_ical['DTSTART']['VALUE']),0,8) ==
$str_date)
} else if ($a_ical['RRULE']['FREQ'] ==
'YEARLY') {
//echo "\n\n".substr(trim($a_ical['DTSTART']['VALUE']),4,4)." == $str_mday \n\n";
if (substr(trim($a_ical['DTSTART']['VALUE']),4,4) ==
$str_mday)
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// mysql_timestamp methods
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
* sets the current date out of a mysql timestamp value
* @param string $mysql_timestamp (YYYYMMDDHHMMSS)
if (ereg("^([0-9]{4})([0-9]{2})([0-9]{2})([0-9]{2})([0-9]{2})([0-9]{2})",$mysql_timestamp,$res)) {
* returns the date as string with format $aFormat
* for $aFormat see http://at.php.net/manual/en/function.date.php
* @version pk-06-08-08 check if the year > 2036
* @version pk-06-08-18 check for NULL
* @todo implement format according to: http://www.php.net/manual/en/function.date.php
function dateStr($aFormat=
"r",$debug=
False) {
if ($this->isNULL()) return ""; // <pk-08-18 />
if (empty($aFormat)) $aFormat=
"r";
// day ---------------------------------------
// time ---------------------------------------
if ($this->isNULL()) return $ret;
$ret['DAY'] =
$this->myDay;
* sets the date from an array with at least YEAR set
* if $dataArray is not an array or $dateArray['YEAR'] is not set
* the object is set to null and False is returned
* @param array $dataArray
// $res=array_change_key_case($dateArray, CASE_UPPER); PHP Version >= 4.2
if ((intval($res['YEAR'])==
0) ||
(intval($res['MONTH'])==
0) ||
(intval($res['DAY'])==
0)) { // <pk-06-09-06 > bugfix for empty dates
if ($debug) echoDebug(__FILE__
,"<pre style=\"padding-left:30px;font-size:85%\">".
print_r($res,True).
"</pre>");
if (isset
($res['YEAR'])) {
* sets the date from a date string with yyyy-MM-dd [HH:mm:ss] format
* @param boolean $debug since pk-05-03-30
function setDateStr($aString,$debug=
False) { // yyyy-MM-dd [HH:mm:ss]
if ($debug) echo
"<p><b>OCSP_DATE::setDateStr($aString)</b> (".
get_class($this).
")</p><blockquote>";
if ($debug) echo
"<p>empty setNULL()</p>";
} else if ($dT=
explode(" ",$aString)) {
if ($debug) echo
"<p>date: ".
$dT[0].
"</p>";
if (!isset
($date[1])) { // <pk-07-02-08> E_ALL
if ($debug) echo
"<p>setNULL</p>";
if ((!empty($dT[1])) &&
($time=
explode(":",$dT[1]))) {
if ($debug) echo
"<p>time: ".
$dT[1].
"</p>";
if ($debug) echo
"<p>setNULL</p>";
if ($debug) echo
"<p>Date set to: ".
$this->dateStr().
"</p></blockquote>";
if (empty($aString)) $this->setTimeStr("00:00:00");
if ($timeArr=
explode(":",$aString)) {
* checks if the current date is in past
* @version pk-07-11-19 $this->myYear > 2037 save
* checks if the current date is in futur
* @version pk-07-11-19 $this->myYear > 2037 save
* calculates the difference between two dates
* returns the rounded granularity between $this and a Date
* granularity values are:
* @param char $granularity
* @version pk-06-07-17 granularity added
* @todo check if date is > 2037
function diff($aDate,$granularity=
's',$round=
0,$debug=
False) {
if ($debug) echoDebugMethod(__FILE__
,get_class($this),"OCSP_DATE::diff()","\$granularity=$granularity\n\$round=$round\n\$aDate:<pre>".
print_r($aDate,True).
"</pre>\$this:<pre>".
print_r($this,True).
"</pre>");
case "i":
return round(($d_secons/
60),$round);
case "h":
return round((($d_secons/
60)/
60),$round);
case "d":
return round(((($d_secons/
60)/
60)/
24),$round);
$f_month=
($aDate->getYear() -
$this->myYear)*
12.0;
$f_month=
$f_month+
($aDate->getMonth() -
$this->myMonth);
$f_month=
$f_month+
(($aDate->getDay() -
$this->myDay)/
30);
return round($f_month,$round);
case "y":
return round(($this->diff($aDate,'m')/
12),$round);
default:
return $d_secons; // seconds
* add $sec seconds to the date
* @todo check if date is > 2037
* add $days days to the date
* @param since pk-05-04-07
* @todo check if date is > 2037
* subtract $sec seconds from the date
* @todo check if date is > 2037
* subtract $days from the date
* @todo check if date is > 2037
* @todo check if date is > 2037
return (($this->getLinuxTime()==
$aDate->getLinuxTimeStamp()) ?
True :
False);
* returns if to date objectes have the same date;
* @param OCSP_DATE $aDate
if ($this->myYear !=
$aDate->year) return False;
if ($this->myMonth !=
$aDate->month) return False;
if ($this->myDay !=
$aDate->day) return False;
preg_match_all('/(BEGIN:VEVENT.*?END:VEVENT)/si', $ical, $result, PREG_PATTERN_ORDER);
for ($i =
0; $i <
count($result[0]); $i++
)
$tmpbyline =
explode("\r\n", $result[0][$i]);
foreach ($tmpbyline as $item) {
$tmpholderarray =
explode(":",$item);
switch($tmpholderarray[0])
$majorarray['UID'] =
$tmpholderarray[1];
$a_tmp=
explode(";",$tmpholderarray[1]);
for ($j=
0;$j<
sizeof($a_tmp);$j++
)
list
($s_key,$s_val)=
explode("=",$a_tmp[$j]);
$majorarray['RRULE'][$s_key]=
$s_val;
$a_tmp=
explode(";",$tmpholderarray[0]);
for ($j=
1;$j<
sizeof($a_tmp);$j++
)
list
($s_key,$s_val)=
explode("=",$a_tmp[$j]);
$majorarray[$a_tmp[0]]['ATTR'][$s_key]=
$s_val;
if (count($tmpholderarray) >
1) {
$majorarray[$a_tmp[0]]['VALUE'] =
$tmpholderarray[1];
lets just finish what we started..
if (preg_match('/DESCRIPTION:(.*)END:VEVENT/si', $result[0][$i], $regs)) {
$icalarray[] =
$majorarray;
Documentation generated on Thu, 08 Jan 2009 17:45:26 +0100 by phpDocumentor 1.4.0a2