-
Notifications
You must be signed in to change notification settings - Fork 21
/
oa_date.module
64 lines (57 loc) · 1.29 KB
/
oa_date.module
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
<?php
/**
* @file
* Provides hook implementations and functionality to oa_date.
*/
/**
* Implements hook_date_format_types().
*/
function oa_date_date_format_types() {
return array(
'oa_date' => t('Relative Date'),
);
}
/**
* Implements hook_views_api().
*/
function oa_date_views_api() {
return array('api' => 3);
}
/**
* Implements hook_date_formats().
*/
function oa_date_date_formats() {
$formats = array();
$formats[] = array(
'type' => 'oa_date',
'format' => 'l, F j',
'locales' => array(),
);
return $formats;
}
/**
* Helper function to render the relative date.
*/
function oa_date_format_date($timestamp) {
static $dates;
if (!isset($dates)) {
$dates = array(
'today' => strtotime("today"),
'yesterday' => strtotime("yesterday"),
'year' => strtotime("first day of January")
);
}
if ($timestamp >= $dates['today']) {
return t("Today") . format_date($timestamp, 'custom', ', F j');
}
elseif ($timestamp >= $dates['yesterday']) {
return t("Yesterday") . format_date($timestamp, 'custom', ', F j');
}
elseif ($timestamp < $dates['year']) {
// only add year to dates from previous years
return format_date($timestamp, 'custom', 'l, F j Y');
}
else {
return format_date($timestamp, 'custom', 'l, F j');
}
}