1: <?php
2:
3: 4: 5: 6: 7:
8:
9: namespace academicpuma\citeproc;
10:
11: 12: 13: 14: 15:
16:
17:
18: class DatePart extends Format {
19:
20: function render($date, $mode = NULL) {
21: $text = '';
22:
23: switch ($this->name) {
24: case 'year':
25: $text = (isset($date[0])) ? $date[0] : '';
26: if ($text > 0 && $text < 500) {
27: $text = $text . $this->citeproc->get_locale('term', 'ad');
28: } elseif ($text < 0) {
29: $text = $text * -1;
30: $text = $text . $this->citeproc->get_locale('term', 'bc');
31: }
32:
33: break;
34: case 'month':
35: $text = (isset($date[1])) ? $date[1] : '';
36: if (empty($text) || $text < 1 || $text > 12)
37: return;
38:
39: switch ($this->form) {
40: case 'numeric': break;
41: case 'numeric-leading-zeros':
42: if ($text < 10) {
43: $text = '0' . $text;
44: break;
45: }
46: break;
47: case 'short':
48: $month = 'month-' . sprintf('%02d', $text);
49: $text = $this->citeproc->get_locale('term', $month, 'short');
50: break;
51: default:
52: $month = 'month-' . sprintf('%02d', $text);
53: $text = $this->citeproc->get_locale('term', $month);
54: break;
55: }
56: break;
57: case 'day':
58: $text = (isset($date[2])) ? $date[2] : '';
59: break;
60: }
61:
62: return $this->format($text);
63: }
64:
65: }
66: