-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathPARSEMONTH.php
117 lines (113 loc) · 2.69 KB
/
PARSEMONTH.php
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
<?php
/*
Released through http://bibliophile.sourceforge.net under the GPL licence.
Do whatever you like with this -- some credit to the author(s) would be appreciated.
A collection of PHP classes to manipulate bibtex files.
If you make improvements, please consider contacting the administrators at bibliophile.sourceforge.net so
that your improvements can be added to the release package.
Mark Grimshaw 2005
http://bibliophile.sourceforge.net
*/
/*****
* PARSEMONTH: BibTeX MONTH import class
*
* BibTeX month field can come in as:
* jan
* "8~" # jan
* jan#"~8"
* etc.
* where # is concatenation and '~' can be any non-numeric character.
*****/
// 17/June/2005 - Mark Grimshaw: month fields that have multiple dates (e.g. dec # " 5--9," or nov # " 29" # "--" # dec # " 2") are correctly parsed.
class PARSEMONTH
{
// Constructor
function PARSEMONTH()
{
}
function init($monthField)
{
$startMonth = $this->startDay = $endMonth = $this->endDay = FALSE;
$date = split("#", $monthField);
foreach($date as $field)
{
$field = ucfirst(strtolower(trim($field)));
if($month = array_search($field, $this->monthToLongName()))
{
if(!$startMonth)
$startMonth = $month;
else
$endMonth = $month;
continue;
}
else if($month = array_search($field, $this->monthToShortName()))
{
if(!$startMonth)
$startMonth = $month;
else
$endMonth = $month;
continue;
}
$this->parseDay($field);
}
if($this->endDay && !$endMonth)
$endMonth = $startMonth;
return array($startMonth, $this->startDay, $endMonth, $this->endDay);
}
// extract day of month from field
function parseDay($dayField)
{
preg_match("/([0-9]+).*([0-9]+)|([0-9]+)/", $dayField, $array);
if(array_key_exists(3, $array))
{
if(!$this->startDay)
$this->startDay = $array[3];
else if(!$this->endDay)
$this->endDay = $array[3];
}
else
{
if(array_key_exists(1, $array))
$this->startDay = $array[1];
if(array_key_exists(2, $array))
$this->endDay = $array[2];
}
}
// Convert month to long name
function monthToLongName()
{
return array(
1 => 'January',
2 => 'February',
3 => 'March',
4 => 'April',
5 => 'May',
6 => 'June',
7 => 'July',
8 => 'August',
9 => 'September',
10 => 'October',
11 => 'November',
12 => 'December',
);
}
// Convert month to short name
function monthToShortName()
{
return array(
1 => 'Jan',
2 => 'Feb',
3 => 'Mar',
4 => 'Apr',
5 => 'May',
6 => 'Jun',
7 => 'Jul',
8 => 'Aug',
9 => 'Sep',
10 => 'Oct',
11 => 'Nov',
12 => 'Dec',
);
}
}
?>