mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
Merged r49479 from branches/2.1.1-madebyme
git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@49651 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
parent
90c0b9f9fc
commit
4f8d656067
@ -139,6 +139,46 @@ class Date extends DBField {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the time difference, but always returns it in a certain format
|
||||
* @param string $format The format, could be one of these:
|
||||
* 'seconds', 'minutes', 'hours', 'days', 'months', 'years'.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
function TimeDiffIn($format) {
|
||||
if($this->value) {
|
||||
$ago = abs(time() - strtotime($this->value));
|
||||
|
||||
switch($format) {
|
||||
case "seconds":
|
||||
$span = $ago;
|
||||
return ($span != 1) ? "{$span} seconds" : "{$span} second";
|
||||
break;
|
||||
case "minutes":
|
||||
$span = round($ago/60);
|
||||
return ($span != 1) ? "{$span} minutes" : "{$span} minute";
|
||||
break;
|
||||
case "hours":
|
||||
$span = round($ago/3600);
|
||||
return ($span != 1) ? "{$span} hours" : "{$span} hour";
|
||||
break;
|
||||
case "days":
|
||||
$span = round($ago/86400);
|
||||
return ($span != 1) ? "{$span} days" : "{$span} day";
|
||||
break;
|
||||
case "months":
|
||||
$span = round($ago/86400/30);
|
||||
return ($span != 1) ? "{$span} months" : "{$span} month";
|
||||
break;
|
||||
case "years":
|
||||
$span = round($ago/86400/365);
|
||||
return ($span != 1) ? "{$span} years" : "{$span} year";
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function requireField() {
|
||||
DB::requireField($this->tableName, $this->name, "date");
|
||||
|
Loading…
Reference in New Issue
Block a user