DateUtils - provides support for date/time manipulation.
More...
|
static | getMonthDays ($m, $y) |
| Returns the number of days in the specified month. More...
|
|
static | getMonthWeekDays ($month, $year) |
| Get the number of week days in the specified month. More...
|
|
static | formatStartDateToEndDate ($start, $end) |
|
static | addMonths (&$date, $months) |
| DateTime will fail to increment month correctly when current date is last day of 31 day month. More...
|
|
static | addYears (&$date, $years) |
| DateTime will fail to increment year correctly in some instances. More...
|
|
static | fuzzyDate ($date) |
| Fuzzy approximates of some time in the past. More...
|
|
static | getMonths () |
| Return an array of month names in the currently selected locale, indexed by month number. More...
|
|
DateUtils - provides support for date/time manipulation.
Definition at line 38 of file date_utils.inc.
◆ addMonths()
static DateUtils::addMonths |
( |
& |
$date, |
|
|
|
$months |
|
) |
| |
|
static |
DateTime will fail to increment month correctly when current date is last day of 31 day month.
Use addMonths instead.
- Parameters
-
| DateTime | object $date |
Number | $months | (can be positive or negative) |
Definition at line 126 of file date_utils.inc.
129 $modifier = $months.
' months';
130 $back_modifier = -$months.
' months';
132 $date->modify($modifier);
133 $back_to_init = clone $date;
134 $back_to_init->modify($back_modifier);
136 while($init->format(
'm') != $back_to_init->format(
'm'))
138 $date->modify(
'-1 day');
139 $back_to_init = clone $date;
140 $back_to_init->modify($back_modifier);
◆ addYears()
static DateUtils::addYears |
( |
& |
$date, |
|
|
|
$years |
|
) |
| |
|
static |
DateTime will fail to increment year correctly in some instances.
- Parameters
-
| DateTime | object $date |
Number | $years | (can be positive or negative) |
Definition at line 151 of file date_utils.inc.
154 $modifier = $years.
' years';
155 $date->modify($modifier);
157 while($date->format(
'm')!=$init->format(
'm'))
159 $date->modify(
'-1 day');
◆ DateUtils()
◆ formatStartDateToEndDate()
static DateUtils::formatStartDateToEndDate |
( |
|
$start, |
|
|
|
$end |
|
) |
| |
|
static |
Definition at line 94 of file date_utils.inc.
96 $yyyy = substr($start,0,4);
97 $yyyy_2 = substr($end,0,4);
98 $mm = substr($start,5,2);
99 $mm_2 = substr($end,5,2);
100 $dd = substr($start,8,2);
101 $dd_2 = substr($end,8,2);
103 if($yyyy != $yyyy_2 || $mm != $mm_2 || $dd != $dd_2)
109 $hh = substr($start,11,2);
110 $mi = substr($start,14,2);
111 $hh_2 = substr($end,11,2);
112 $mi_2 = substr($end,14,2);
113 $s_time = date(
"g:ia", mktime($hh,$mi));
114 $e_time = date(
"g:ia", mktime($hh_2,$mi_2));
formatDateShort($date)
Utility function to format date in short form (MM/DD/YYYY), with no time component.
formatDateTime12Hr($datetime)
◆ fuzzyDate()
static DateUtils::fuzzyDate |
( |
|
$date | ) |
|
|
static |
Fuzzy approximates of some time in the past.
- Parameters
-
- Returns
- string
Definition at line 168 of file date_utils.inc.
170 $time = strtotime($date);
176 $s = ($when == 1)?
"second":
"seconds";
177 return "$when $s ago";
179 else if ($ago < 3600)
181 $when = round($ago / 60);
182 $m = ($when == 1)?
"minute":
"minutes";
183 return "$when $m ago";
185 else if ($ago >= 3600 && $ago < 86400)
187 $when = round($ago / 60 / 60);
188 $h = ($when == 1)?
"hour":
"hours";
189 return "$when $h ago";
191 else if ($ago >= 86400 && $ago < 2629743.83)
193 $when = round($ago / 60 / 60 / 24);
194 $d = ($when == 1)?
"day":
"days";
195 return "$when $d ago";
197 else if ($ago >= 2629743.83 && $ago < 31556926)
199 $when = round($ago / 60 / 60 / 24 / 30.4375);
200 $m = ($when == 1)?
"month":
"months";
201 return "$when $m ago";
205 $when = round($ago / 60 / 60 / 24 / 365);
206 $y = ($when == 1)?
"year":
"years";
207 return "$when $y ago";
◆ getMonthDays()
static DateUtils::getMonthDays |
( |
|
$m, |
|
|
|
$y |
|
) |
| |
|
static |
Returns the number of days in the specified month.
- Parameters
-
number | $m | the month number |
number | $y | the year |
- Returns
- number the number of days in that month
Definition at line 52 of file date_utils.inc.
54 $monthDays = array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
55 $d = $monthDays[$m - 1];
56 if ($m == 2 && ($y % 4) == 0 && ($y % 100) != 0) $d++;
◆ getMonths()
static DateUtils::getMonths |
( |
| ) |
|
|
static |
Return an array of month names in the currently selected locale, indexed by month number.
This is a format suitable for use with a SelectFieldRenderer
- Returns
- array month names indexed by month number
Definition at line 216 of file date_utils.inc.
219 for($i = 1; $i < 13; ++$i)
221 $months[$i] = date(
"F", mktime(0, 0, 0, $i, 10));
◆ getMonthWeekDays()
static DateUtils::getMonthWeekDays |
( |
|
$month, |
|
|
|
$year |
|
) |
| |
|
static |
Get the number of week days in the specified month.
- Parameters
-
number | $m | the month number |
number | $y | the year |
- Returns
- number the number of week days in that month
Definition at line 68 of file date_utils.inc.
70 $weekDaysInMonth = array
72 28 => array(20, 20, 20, 20, 20, 20, 20),
73 29 => array(21, 21, 21, 21, 21, 20, 20),
74 30 => array(22, 22, 22, 22, 21, 20, 21),
75 31 => array(23, 23, 23, 22, 21, 21, 22)
79 $date = strtotime(
"$year-$month-01");
81 $first = date(
"N", $date) - 1;
82 return $weekDaysInMonth[$days][$first];
static getMonthDays($m, $y)
Returns the number of days in the specified month.
The documentation for this class was generated from the following file: