Renamed date helper methods. Added some more helpers
[ajatus.git] / plugins / ajatus / helpers / date.php
blob3c2d7fcb3b9bcb95d29a376433eeb89867be8510
1 <?php
2 /**
3 * This file is part of
4 * Ajatus - Distributed CRM
5 *
6 * Copyright (c) 2008 Jerry Jalava <jerry.jalava@gmail.com>
7 * Copyright (c) 2008 Nemein Oy <http://nemein.com>
8 * Website: http://ajatus.info
9 * Licensed under the GPL license
10 * http://www.gnu.org/licenses/gpl.html
14 class ajatus_helpers_date
16 static function unixtime_to_jsdatetime($unixtime=false)
18 if ($unixtime === false)
20 $unixtime = time();
23 $orig_tz = date_default_timezone_get();
24 date_default_timezone_set('UTC');
26 $date = new DateTime(strftime("%x %X", $unixtime));
27 $date_str = $date->format(DATE_ISO8601);
28 $parts = explode('+', $date_str);
29 $jsdatetime = $parts[0];
31 date_default_timezone_set($orig_tz);
33 return $jsdatetime;
36 static function jsdatetime_to_unixtime($jsdatetime)
38 $orig_tz = date_default_timezone_get();
39 date_default_timezone_set('UTC');
41 $date = new DateTime($jsdatetime);
42 $unixtime = $date->format("U");
44 date_default_timezone_set($orig_tz);
46 return $unixtime;
49 static function jsdate_to_unixtime($jsdate)
51 $orig_tz = date_default_timezone_get();
52 date_default_timezone_set('UTC');
54 $date = new DateTime($jsdatetime);
55 $unixtime = $date->format("U");
57 date_default_timezone_set($orig_tz);
59 return $unixtime;
62 static function unixtime_to_jsdate($unixtime=false)
64 if ( $unixtime === false
65 || !is_numeric($unixtime))
67 $unixtime = time();
70 $orig_tz = date_default_timezone_get();
71 date_default_timezone_set('UTC');
73 $date = new DateTime(strftime("%x %X", $unixtime));
74 $date_str = $date->format(DATE_ISO8601);
75 $parts = explode('T', $date_str);
76 $jsdate = $parts[0];
78 date_default_timezone_set($orig_tz);
80 return $jsdate;
83 static function unixtime_to_jstime($unixtime=false)
85 if ($unixtime === false)
87 $unixtime = time();
90 $orig_tz = date_default_timezone_get();
91 date_default_timezone_set('UTC');
93 $date = new DateTime(strftime("%x %X", $unixtime));
94 $date_str = $date->format(DATE_ISO8601);
95 $parts = explode('T', $date_str);
96 $parts = explode('+', $parts[1]);
97 $jsdate = $parts[0];
99 date_default_timezone_set($orig_tz);
101 return $jsdate;