mirror of https://github.com/movim/movim
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
78 lines
1.9 KiB
78 lines
1.9 KiB
<?php
|
|
|
|
/**
|
|
* Return a human-readable week
|
|
* @return string
|
|
*/
|
|
function getDays() {
|
|
return array(
|
|
1 => t('Monday'),
|
|
2 => t('Tuesday'),
|
|
3 => t('Wednesday'),
|
|
4 => t('Thursday'),
|
|
5 => t('Friday'),
|
|
6 => t('Saturday'),
|
|
7 => t('Friday'));
|
|
}
|
|
/**
|
|
* Return a human-readable year
|
|
* @return string
|
|
*/
|
|
function getMonths() {
|
|
return array(
|
|
1 => t('January'),
|
|
2 => t('February'),
|
|
3 => t('March'),
|
|
4 => t('April'),
|
|
5 => t('May'),
|
|
6 => t('June'),
|
|
7 => t('July'),
|
|
8 => t('August'),
|
|
9 => t('September'),
|
|
10 => t('October'),
|
|
11 => t('November'),
|
|
12 => t('December'));
|
|
}
|
|
|
|
/**
|
|
* Return a human-readable date
|
|
*
|
|
* @param timestamp $string
|
|
* @return string
|
|
*/
|
|
function prepareDate($time, $hours = true) {
|
|
$dotw = getDays();
|
|
|
|
$moty = getMonths();
|
|
|
|
$today = strtotime(date('M j, Y'));
|
|
$reldays = ($time - $today)/86400;
|
|
|
|
if ($reldays >= 0 && $reldays < 1) {
|
|
$date = t('Today');
|
|
} else if ($reldays >= 1 && $reldays < 2) {
|
|
$date = t('Tomorrow');
|
|
} else if ($reldays >= -1 && $reldays < 0) {
|
|
$date = t('Yesterday');
|
|
} else {
|
|
|
|
if (abs($reldays) < 7) {
|
|
if ($reldays > 0) {
|
|
$reldays = floor($reldays);
|
|
$date = 'In ' . $reldays . ' '.t('day') . ($reldays != 1 ? 's' : '');
|
|
} else {
|
|
$reldays = abs(floor($reldays));
|
|
$date = t(' %d days ago', $reldays);
|
|
}
|
|
} else {
|
|
$date = $dotw[date('N',$time ? $time : time())] .', '.date('j',$time ? $time : time()).' '.$moty[date('n',$time ? $time : time())] ;
|
|
if (abs($reldays) > 182)
|
|
$date .= date(', Y',$time ? $time : time());
|
|
}
|
|
}
|
|
if($hours)
|
|
$date .= ' - '. date('H:i', $time);
|
|
|
|
if($time)
|
|
return $date;
|
|
}
|