1: <?php
2: /**
3: * Handles Date conversion for the resource handler.
4: *
5: * PHP version 5
6: *
7: * @category Kolab
8: * @package Kolab_Filter
9: * @author Steffen Hansen <steffen@klaralvdalens-datakonsult.se>
10: * @author Gunnar Wrobel <wrobel@pardus.de>
11: * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1
12: * @link http://pear.horde.org/index.php?package=Kolab_Server
13: */
14:
15: /**
16: * Handles Date conversion for the resource handler.
17: *
18: * Copyright 2004-2010 Klarälvdalens Datakonsult AB
19: *
20: * See the enclosed file COPYING for license information (LGPL). If you did not
21: * receive this file, see
22: * http://www.horde.org/licenses/lgpl21.
23: *
24: * @category Kolab
25: * @package Kolab_Filter
26: * @author Steffen Hansen <steffen@klaralvdalens-datakonsult.se>
27: * @author Gunnar Wrobel <wrobel@pardus.de>
28: * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1
29: * @link http://pear.horde.org/index.php?package=Kolab_Server
30: */
31: class Horde_Kolab_Resource_Epoch
32: {
33:
34: /**
35: * The date to be converted.
36: *
37: * @var mixed
38: */
39: private $_date;
40:
41: /**
42: * Constructor.
43: *
44: * @param mixed $date The date to be converted.
45: */
46: public function __construct($date)
47: {
48: $this->_date = $date;
49: }
50:
51: /**
52: * Clear information from a date array.
53: *
54: * @param array $ical_date The array to clear.
55: *
56: * @return array The cleaned array.
57: */
58: private function cleanArray($ical_date)
59: {
60: if (!array_key_exists('hour', $ical_date)) {
61: $temp['DATE'] = '1';
62: }
63: $temp['hour'] = array_key_exists('hour', $ical_date) ? $ical_date['hour'] : '00';
64: $temp['minute'] = array_key_exists('minute', $ical_date) ? $ical_date['minute'] : '00';
65: $temp['second'] = array_key_exists('second', $ical_date) ? $ical_date['second'] : '00';
66: $temp['year'] = array_key_exists('year', $ical_date) ? $ical_date['year'] : '0000';
67: $temp['month'] = array_key_exists('month', $ical_date) ? $ical_date['month'] : '00';
68: $temp['mday'] = array_key_exists('mday', $ical_date) ? $ical_date['mday'] : '00';
69: $temp['zone'] = array_key_exists('zone', $ical_date) ? $ical_date['zone'] : 'UTC';
70:
71: return $temp;
72: }
73:
74: /**
75: * Convert a date to an epoch.
76: *
77: * @param array $values The array to convert.
78: *
79: * @return int Time.
80: */
81: private function convert2epoch($values)
82: {
83: Horde::logMessage(sprintf('Converting to epoch %s',
84: print_r($values, true)), 'DEBUG');
85:
86: if (is_array($values)) {
87: $temp = $this->cleanArray($values);
88: $epoch = gmmktime($temp['hour'], $temp['minute'], $temp['second'],
89: $temp['month'], $temp['mday'], $temp['year']);
90: } else {
91: $epoch=$values;
92: }
93:
94: Horde::logMessage(sprintf('Converted <%s>', $epoch), 'DEBUG');
95: return $epoch;
96: }
97:
98: public function getEpoch()
99: {
100: return $this->convert2Epoch($this->_date);
101: }
102: }