Merge branch 'maint/7.0'
[ninja.git] / application / helpers / date.php
blob6d205f328379124a566b50ec135d40b701e293e5
1 <?php defined('SYSPATH') or die('No direct access allowed.');
2 /**
3 * Help with formatting datestamps
4 */
5 class date {
7 private static function _nice_format_duration($start_time, $end_time) {
8 $duration = $end_time - $start_time;
9 $days = $duration / 86400;
10 $hours = ($duration % 86400) / 3600;
11 $minutes = ($duration % 3600) / 60;
12 $seconds = ($duration % 60);
13 return sprintf("%s: %dd %dh %dm %ds", _("Duration"),
14 $days, $hours, $minutes, $seconds);
17 /**
18 * Outputs a nicely formatted version of "2003-03-12 21:14:34 to 2003-03-12 21:14:35<br>
19 * Duration: 0d 0h 0m 1s"
21 * @param $start_time int timestamp
22 * @param $end_time int timestamp
24 public static function duration($start_time, $end_time)
26 $fmt = "Y-m-d H:i:s";
27 $duration = date($fmt, $start_time) . " to " .
28 date($fmt, $end_time) . "<br />\n";
30 $duration .= self::_nice_format_duration($start_time, $end_time)."\n";
31 return $duration;
34 /**
35 * Return array of abbrivated weekday names
36 * NOTE: Are you Really Sure you need this?
38 static function abbr_day_names()
40 return array(
41 _('Sun'),
42 _('Mon'),
43 _('Tue'),
44 _('Wed'),
45 _('Thu'),
46 _('Fri'),
47 _('Sat')
51 /**
52 * Return array of abbrivated month names
53 * NOTE: Are you Really Sure you need this?
55 static function abbr_month_names()
57 return array(
58 _('Jan'),
59 _('Feb'),
60 _('Mar'),
61 _('Apr'),
62 _('May'),
63 _('Jun'),
64 _('Jul'),
65 _('Aug'),
66 _('Sep'),
67 _('Oct'),
68 _('Nov'),
69 _('Dec')
73 /**
74 * Return array of full weekday names
75 * NOTE: Are you Really Sure you need this?
77 static function day_names()
79 return array(
80 _('Sunday'),
81 _('Monday'),
82 _('Tuesday'),
83 _('Wednesday'),
84 _('Thursday'),
85 _('Friday'),
86 _('Saturday')
90 /**
91 * Return array of full month names
92 * NOTE: Are you Really Sure you need this?
94 static function month_names()
96 return array(
97 _('January'),
98 _('February'),
99 _('March'),
100 _('April'),
101 _('May'),
102 _('June'),
103 _('July'),
104 _('August'),
105 _('September'),
106 _('October'),
107 _('November'),
108 _('December')
113 * Offset from UTC
115 * @param $timezone string = null, defaults to php.ini's value
116 * @return int seconds
118 static function utc_offset($timezone = null) {
119 if(!$timezone) {
120 $timezone = date_default_timezone_get();
122 if($timezone == 'UTC') {
123 return 0;
125 $utc = new DateTimeZone('UTC');
126 $remote_dtz = new DateTimeZone($timezone);
128 $origin_dt = new DateTime("now", $utc);
129 $remote_dt = new DateTime("now", $remote_dtz);
131 return $remote_dtz->getOffset($remote_dt);