CWIS Developer Documentation
Axis--Date.php
Go to the documentation of this file.
1 <?PHP
2 
3 #
4 # Axis--Date.php
5 # A Date Manipulation Object
6 #
7 # Copyright 1999-2004 Axis Data
8 # This code is free software that can be used or redistributed under the
9 # terms of Version 2 of the GNU General Public License, as published by the
10 # Free Software Foundation (http://www.fsf.org).
11 #
12 # Author: Edward Almasy (almasy@axisdata.com)
13 #
14 # Part of the AxisPHP library v1.2.5
15 # For more information see http://www.axisdata.com/AxisPHP/
16 #
17 
18 class Date {
19 
20  # ---- PUBLIC INTERFACE --------------------------------------------------
21 
22  # object constructor
23  function Date($BeginDate, $EndDate = NULL, $Precision = NULL, $DebugLevel = 0)
24  {
25  # set debug state
26  $this->DebugLevel = $DebugLevel;
27 
28  if ($this->DebugLevel) { print("Date: Date(BeginDate=\"".$BeginDate."\" EndDate=\"".$EndDate."\" Precision=".$this->FormattedPrecision($Precision).")<br>\n"); }
29 
30  $MonthNames = array(
31  "january" => 1,
32  "february" => 2,
33  "march" => 3,
34  "april" => 4,
35  "may" => 5,
36  "june" => 6,
37  "july" => 7,
38  "august" => 8,
39  "september" => 9,
40  "october" => 10,
41  "november" => 11,
42  "december" => 12,
43  "jan" => 1,
44  "feb" => 2,
45  "mar" => 3,
46  "apr" => 4,
47  "may" => 5,
48  "jun" => 6,
49  "jul" => 7,
50  "aug" => 8,
51  "sep" => 9,
52  "oct" => 10,
53  "nov" => 11,
54  "dec" => 12
55  );
56 
57  # Formats we need to parse:
58  # 1999-9-19
59  # 1999-9
60  # 9-19-1999
61  # 19-9-1999
62  # Sep-1999
63  # Sep 1999
64  # Sep 9 1999
65  # September 9, 1999
66  # September 9th, 1999
67  # 1996,1999
68  # c1999
69  # 1996-1999
70  # 9/19/01
71  # 9-19-01
72  # 199909
73  # 19990909
74  # 09-Sep-1999
75  # 09 Sep 1999
76 
77  # append end date to begin date if available
78  $Date = $BeginDate;
79  if ($EndDate!==NULL)
80  {
81  $Date .= " - ".$EndDate;
82  }
83 
84  # strip off any leading or trailing whitespace
85  $Date = trim($Date);
86 
87  # bail out if we don't have anything to parse
88  if (strlen($Date) < 1) { return; }
89 
90  # check for and strip out inferred indicators ("[" and "]")
91  $Prec = 0;
92  if (preg_match("/\\[/", $Date))
93  {
94  $Prec |= DATEPRE_INFERRED;
95  $Date = preg_replace("/[\\[\\]]/", "", $Date);
96  }
97 
98  # check for and strip off copyright indicator (leading "c")
99  if (preg_match("/^c/", $Date))
100  {
101  $Prec |= DATEPRE_COPYRIGHT;
102  $Date = preg_replace("/^c/", "", $Date);
103  }
104 
105  # check for and strip off continuous indicator (trailing "-")
106  if (preg_match("/\\-$/", $Date))
107  {
108  $Prec |= DATEPRE_CONTINUOUS;
109  $Date = preg_replace("/\\-$/", "", $Date);
110  }
111 
112  # strip out any times
113  $Date = preg_replace("/[0-9]{1,2}:[0-9]{2,2}[:]?[0-9]{0,2}/", "", $Date);
114  $Date = trim($Date);
115 
116  $Date = strtolower($Date);
117 
118  # A regex to match short and long month names:
119  $MonthRegex = "(?:jan(?:uary)?|feb(?:ruary)?|mar(?:ch)?|apr(?:il)?|may".
120  "|jun(?:e)?|jul(?:y)?|aug(?:ust)?|sep(?:tember)?|oct(?:ober)?".
121  "|nov(?:ember)?|dec(?:ember)?)";
122 
123  # Here we'll construct a template regex for dates
124  # We want a single regex that covers all the different formats
125  # of date we understand, with the various components of the
126  # date pulled out using named subexpressions (eg: (?P<name>)).
127  # Annoyingly, we can't re-use the same name for subexpressions
128  # that will never both be matched at once.
129  # So, we have to number them (year1, year2, etc) and figure
130  # out which one did match.
131  # Use XX_ThingNumber in the parameterized subexpressions
132  # (eg XX_year1).
133  # We'll use string substitutions later to convert the XX_ to
134  # begin_ and end_
135 
136  $DateRegex = "(".
137  # Matched formats are separated by |, as this isn't used in any of the formats
138  # First alternative will match the following formats:
139  # 1999-09-19 | 19990909 | 1999-09 | 199909 | 1999
140  "(?:(?P<XX_year1>\d{4})(?:-?(?P<XX_month1>\d{1,2})(?:-?(?P<XX_day1>\d{1,2}))?)?)".
141  # Second alternative will match the following formats:
142  # 09-19-1999 | 19-09-1999 | 09/19/01 | 09-19-01
143  "|(?:(?P<XX_month2>\d{1,2})[\/-](?P<XX_day2>\d{1,2})[\/-](?P<XX_year2>(?:\d{2,4})))".
144  # Third alternative will match the following formats:
145  # 09-Sep-1999 | 09 Sep 1999 | Sep-1999 | Sep 1999
146  "|(?:(?:(?P<XX_day3>\d+)[ -])?(?P<XX_month3>".$MonthRegex.")[ -](?P<XX_year3>\d{4}))".
147  # Fourth alternative will match the following formats:
148  # Sep 9 1999 | September 9th, 1999
149  "|(?:(?P<XX_month4>".$MonthRegex.") (?P<XX_day4>\d{1,2})(?:(?:st|nd|rd|th|),)? (?P<XX_year4>\d{4}))".
150  ")";
151 
152  # If more formats are added, bump this.
153  $NumberOfDateRegexes = 4;
154 
155  # Construct the begin and end regexes for the date range
156  $BeginRegex = str_replace('XX','Begin', $DateRegex );
157  $EndRegex = str_replace('XX','End', $DateRegex );
158 
159  # Glue them together, making the second one optional,
160  # and do the matching.
161  if ( preg_match("/".$BeginRegex.
162  "(?:(?:(?: - )|,)".$EndRegex.")?/",
163  $Date, $Matches ) )
164  {
165  # Pull out the Begin and End data from the matches array:
166  foreach( array("Begin","End") as $Time )
167  {
168  eval(
169  # Extract the matching elements from the regex parse
170  '$'.$Time.'Day = $this->ExtractMatchData($Matches,"'.
171  $Time.'_day", $NumberOfDateRegexes );' .
172  '$'.$Time.'Month = $this->ExtractMatchData($Matches,"'.
173  $Time.'_month",$NumberOfDateRegexes );' .
174  '$'.$Time.'Year = $this->ExtractMatchData($Matches,"'.
175  $Time.'_year", $NumberOfDateRegexes );' .
176  # Convert named months to month numbers:
177  'if ( isset($'.$Time.'Month) && ' .
178  ' !is_numeric($'.$Time.'Month))' .
179  '{' .
180  ' $'.$Time.'Month=$MonthNames[$'.$Time.'Month];' .
181  '}' .
182  # Handle 2-digit years
183  'if ( isset($'.$Time.'Year) && ' .
184  ' strlen($'.$Time.'Year)==2)' .
185  '{' .
186  ' $'.$Time.'Year += ($'.$Time.'Year>50)?1900:2000;' .
187  '}' .
188  # Deal with D-M-Y format, where we can
189  'if ( isset($'.$Time.'Month) && $'.$Time.'Month>12)' .
190  '{' .
191  ' $Tmp = $'.$Time.'Month;' .
192  ' $'.$Time.'Month = $'.$Time.'Day;' .
193  ' $'.$Time.'Day = $Tmp;' .
194  '}'
195  );
196  }
197  }
198 
199  # use current month if begin day but no begin month specified
200  if (isset($BeginDay) && !isset($BeginMonth))
201  {
202  $BeginMonth = date("m");
203  }
204 
205  # use current year if begin month but no begin year specified
206  if (isset($BeginMonth) && !isset($BeginYear))
207  {
208  $BeginYear = date("Y");
209  }
210 
211  # use begin year if end month but no end year specified
212  if (isset($EndMonth) && !isset($EndYear))
213  {
214  $EndYear = $BeginYear;
215  }
216 
217  # After we've shuffled around the numbers, check the result to see if
218  # it looks valid, dropping that which doesn't.
219  foreach( array("Begin","End") as $Time)
220  {
221  eval(
222  # Discard invalid looking dates
223  'if ( isset($'.$Time.'Year) && !($'.$Time.'Year >=1)) ' .
224  ' { unset($'.$Time.'Year); } ' .
225  'if ( isset($'.$Time.'Month) && ' .
226  ' !( $'.$Time.'Month>=1 && $'.$Time.'Month<=12)) ' .
227  ' { unset($'.$Time.'Month); } ' .
228  'if ( isset($'.$Time.'Day) && ' .
229  ' !( $'.$Time.'Day >=1 && $'.$Time.'Day <=31)) ' .
230  ' { unset($'.$Time.'Day); } '
231  );
232  }
233 
234  # if no begin date found and begin date value is not illegal
235  if (!isset($BeginYear)
236  && ($BeginDate != "0000-00-00")
237  && ($BeginDate != "0000-00-00 00:00:00"))
238  {
239  # try system call to parse incoming date
240  $UDateStamp = strtotime($BeginDate);
241  if ($this->DebugLevel > 1) { print("Date: calling strtotime to parse BeginDate \"".$BeginDate."\" -- strtotime returned \"".$UDateStamp."\"<br>\n"); }
242 
243  # if system call was able to parse date
244  if (($UDateStamp != -1) && ($UDateStamp !== FALSE))
245  {
246  # set begin date to value returned by system call
247  $BeginYear = date("Y", $UDateStamp);
248  $BeginMonth = date("n", $UDateStamp);
249  $BeginDay = date("j", $UDateStamp);
250  }
251  }
252 
253  # if end date value supplied and no end date found and end date value is not illegal
254  if (($EndDate != NULL) && !isset($EndYear)
255  && ($EndDate != "0000-00-00")
256  && ($EndDate != "0000-00-00 00:00:00"))
257  {
258  # try system call to parse incoming date
259  $UDateStamp = strtotime($EndDate);
260 
261  # if system call was able to parse date
262  if (($UDateStamp != -1) && ($UDateStamp !== FALSE))
263  {
264  # set begin date to value returned by system call
265  $EndYear = date("Y", $UDateStamp);
266  $EndMonth = date("n", $UDateStamp);
267  $EndDay = date("j", $UDateStamp);
268  }
269  }
270 
271  # if end date is before begin date
272  if ((isset($EndYear) && isset($BeginYear) && ($EndYear < $BeginYear))
273  || (isset($BeginYear) && isset($EndYear) && ($EndYear == $BeginYear) &&
274  isset($BeginMonth) && isset($EndMonth) && ($EndMonth < $BeginMonth))
275  || (isset($BeginYear) && isset($EndYear) && ($EndYear == $BeginYear) &&
276  isset($BeginMonth) && isset($EndMonth) && ($EndMonth == $BeginMonth) &&
277  isset($BeginDay) && isset($EndDay) && ($EndDay < $BeginDay)))
278  {
279  # swap begin and end dates
280  $TempYear = $BeginYear;
281  $TempMonth = $BeginMonth;
282  $TempDay = $BeginDay;
285  $BeginDay = $EndDay;
286  $EndYear = $TempYear;
287  $EndMonth = $TempMonth;
288  $EndDay = $TempDay;
289  }
290 
291  # if precision value supplied by caller
292  if ($Precision != NULL)
293  {
294  # use supplied precision value
295  $this->Precision = $Precision;
296  }
297  else
298  {
299  # save new precision value
300  if (isset($BeginYear)) { $Prec |= DATEPRE_BEGINYEAR; }
301  if (isset($BeginMonth)) { $Prec |= DATEPRE_BEGINMONTH; }
302  if (isset($BeginDay)) { $Prec |= DATEPRE_BEGINDAY; }
303  if (isset($EndYear)) { $Prec |= DATEPRE_ENDYEAR; }
304  if (isset($EndMonth)) { $Prec |= DATEPRE_ENDMONTH; }
305  if (isset($EndDay)) { $Prec |= DATEPRE_ENDDAY; }
306  $this->Precision = $Prec;
307  }
308 
309  # save new date values
310  if ($this->DebugLevel > 1) { print("Date: BeginYear = $BeginYear<br>\n"); }
311  if ($this->DebugLevel > 1) { print("Date: BeginMonth = $BeginMonth<br>\n"); }
312  if ($this->DebugLevel > 1) { print("Date: BeginDay = $BeginDay<br>\n"); }
313  if ($this->DebugLevel > 1) { print("Date: EndYear = $EndYear<br>\n"); }
314  if ($this->DebugLevel > 1) { print("Date: EndMonth = $EndMonth<br>\n"); }
315  if ($this->DebugLevel > 1) { print("Date: EndDay = $EndDay<br>\n"); }
316  if ($this->DebugLevel > 1) { print("Date: Precision = ".$this->FormattedPrecision()."<br>\n"); }
317  $this->BeginYear = isset($BeginYear) ? $BeginYear : NULL ;
318  $this->BeginMonth = isset($BeginMonth) ? $BeginMonth : NULL ;
319  $this->BeginDay = isset($BeginDay) ? $BeginDay : NULL ;
320  $this->EndYear = isset($EndYear) ? $EndYear : NULL ;
321  $this->EndMonth = isset($EndMonth) ? $EndMonth : NULL ;
322  $this->EndDay = isset($EndDay) ? $EndDay : NULL ;
323  }
324 
325  # return value suitable for display
326  function Formatted()
327  {
328  # if begin year available
329  $DateString = "";
330  if ($this->Precision & DATEPRE_BEGINYEAR)
331  {
332  # start with begin year
333  $DateString = $this->BeginYear;
334 
335  # if begin month available
336  if ($this->Precision & DATEPRE_BEGINMONTH)
337  {
338  # add begin month
339  $DateString .= "-".$this->BeginMonth;
340 
341  # if begin day available
342  if ($this->Precision & DATEPRE_BEGINDAY)
343  {
344  # add begin day
345  $DateString .= "-".$this->BeginDay;
346  }
347  }
348 
349  # if end year available
350  if ($this->Precision & DATEPRE_ENDYEAR)
351  {
352  # if separate dates
353  if ($this->Precision & DATEPRE_SEPARATE)
354  {
355  # separate dates with comma
356  $DateString .= ", ";
357  }
358  else
359  {
360  # separate dates with dash
361  $DateString .= " - ";
362  }
363 
364  # add end year
365  $DateString .= $this->EndYear;
366 
367  # if end month available
368  if ($this->Precision & DATEPRE_ENDMONTH)
369  {
370  # add end month
371  $DateString .= "-".$this->EndMonth;
372 
373  # if end day available
374  if ($this->Precision & DATEPRE_ENDDAY)
375  {
376  # add end day
377  $DateString .= "-".$this->EndDay;
378  }
379  }
380  }
381  else
382  {
383  # if date is open-ended
384  if ($this->Precision & DATEPRE_CONTINUOUS)
385  {
386  # add dash to indicate open-ended
387  $DateString .= "-";
388  }
389  }
390 
391  # if copyright flag is set
392  if ($this->Precision & DATEPRE_COPYRIGHT)
393  {
394  # add on copyright indicator
395  $DateString = "c".$DateString;
396  }
397 
398  # if flag is set indicating date was inferred
399  if ($this->Precision & DATEPRE_INFERRED)
400  {
401  # add on inferred indicators
402  $DateString = "[".$DateString."]";
403  }
404  }
405 
406  # return formatted date string to caller
407  return $DateString;
408  }
409 
410  # return date in format specified like PHP date() format parameter
411  function PFormatted($Format, $ReturnEndDate = FALSE)
412  {
413  if ($ReturnEndDate)
414  {
415  $Month = ($this->Precision & DATEPRE_ENDMONTH) ? $this->EndMonth : 1;
416  $Day = ($this->Precision & DATEPRE_ENDDAY) ? $this->EndDay : 1;
417  $Year = ($this->Precision & DATEPRE_ENDYEAR) ? $this->EndYear : 1;
418  }
419  else
420  {
421  $Month = ($this->Precision & DATEPRE_BEGINMONTH) ? $this->BeginMonth : 1;
422  $Day = ($this->Precision & DATEPRE_BEGINDAY) ? $this->BeginDay : 1;
423  $Year = ($this->Precision & DATEPRE_BEGINYEAR) ? $this->BeginYear : 1;
424  }
425  return date($Format, mktime(0, 0, 0, $Month, $Day, $Year));
426  }
427 
428  # get begin date/time (or end if requested) formatted for SQL DATETIME field
429  function FormattedForSql($ReturnEndDate = FALSE)
430  {
431  return $this->PFormatted("Y-m-d H:i:s", $ReturnEndDate);
432  }
433 
434  # return begin time in ISO 8601 format
435  function FormattedISO8601()
436  {
437  # if begin year available
438  if ($this->Precision & DATEPRE_BEGINYEAR)
439  {
440  # start with begin year
441  $DateString = sprintf("%04d", $this->BeginYear);
442 
443  # if begin month available
444  if ($this->Precision & DATEPRE_BEGINMONTH)
445  {
446  # add begin month
447  $DateString .= sprintf("-%02d", $this->BeginMonth);
448 
449  # if begin day available
450  if ($this->Precision & DATEPRE_BEGINDAY)
451  {
452  # add begin day
453  $DateString .= sprintf("-%02d", $this->BeginDay);
454  }
455  }
456  }
457 
458  # return ISO 8601 formatted date string to caller
459  return $DateString;
460  }
461 
462  # return values in UTC instead of local time (NOT IMPLEMENTED)
463  function UseUTC()
464  {
465  # if not currently in UTC
466  if ($this->InUTC != TRUE)
467  {
468  # adjust date to UTC
469  # ???
470 
471  # set flag to indicate we are in UTC
472  $this->InUTC = TRUE;
473  }
474  }
475 
476  # return values in local time instead of UTC (NOT IMPLEMENTED)
477  function UseLocalTime()
478  {
479  # if currently in UTC
480  if ($this->InUTC)
481  {
482  # adjust date to local time
483  # ???
484 
485  # set flag to indicate we are in local time
486  $this->InUTC = FALSE;
487  }
488  }
489 
490  # return normalized values (suitable for storing via SQL)
491  function BeginDate()
492  {
493  # build date string based on current precision
494  if ($this->Precision & DATEPRE_BEGINYEAR)
495  {
496  if ($this->Precision & DATEPRE_BEGINMONTH)
497  {
498  if ($this->Precision & DATEPRE_BEGINMONTH)
499  {
500  $DateFormat = "%04d-%02d-%02d";
501  }
502  else
503  {
504  $DateFormat = "%04d-%02d-01";
505  }
506  }
507  else
508  {
509  $DateFormat = "%04d-01-01";
510  }
511 
512  $DateString = sprintf($DateFormat,
513  $this->BeginYear, $this->BeginMonth, $this->BeginDay);
514  }
515  else
516  {
517  $DateString = NULL;
518  }
519 
520  # return date string to caller
521  return $DateString;
522  }
523  function EndDate()
524  {
525  # build date string based on current precision
526  if ($this->Precision & DATEPRE_ENDYEAR)
527  {
528  if ($this->Precision & DATEPRE_ENDMONTH)
529  {
530  if ($this->Precision & DATEPRE_ENDMONTH)
531  {
532  $DateFormat = "%04d-%02d-%02d";
533  }
534  else
535  {
536  $DateFormat = "%04d-%02d-00";
537  }
538  }
539  else
540  {
541  $DateFormat = "%04d-00-00";
542  }
543 
544  $DateString = sprintf($DateFormat,
545  $this->EndYear, $this->EndMonth, $this->EndDay);
546  }
547  else
548  {
549  $DateString = NULL;
550  }
551 
552  # return date string to caller
553  return $DateString;
554  }
555 
556  # get or set precision value (combination of boolean flags)
557  function Precision($NewPrecision = NULL)
558  {
559  if ($NewPrecision != NULL) { $this->Precision = $NewPrecision; }
560  return $this->Precision;
561  }
562 
563  # return text of SQL condition for records that match date
564  function SqlCondition($FieldName, $EndFieldName = NULL, $Operator = "=")
565  {
566  # if no date value is set
567  if ($this->Precision < 1)
568  {
569  # if operator is equals
570  if ($Operator == "=")
571  {
572  # construct conditional that will find null dates
573  $Condition = "(".$FieldName." IS NULL OR ".$FieldName." < '0000-01-01 00:00:01')";
574  }
575  else
576  {
577  # construct conditional that will find non-null dates
578  $Condition = "(".$FieldName." > '0000-01-01 00:00:00')";
579  }
580  }
581  else
582  {
583  # use begin field name as end if no end field specified
584  if ($EndFieldName == NULL) { $EndFieldName = $FieldName; }
585 
586  # determine begin and end of range
588  if ($this->Precision & DATEPRE_BEGINMONTH)
589  {
591  if ($this->Precision & DATEPRE_BEGINDAY)
592  {
593  $BeginDay = $this->BeginDay - 1;
594  }
595  else
596  {
597  $BeginDay = 0;
598  }
599  }
600  else
601  {
602  $BeginMonth = 1;
603  $BeginDay = 0;
604  }
605  if ($this->Precision & DATEPRE_ENDYEAR)
606  {
608  if ($this->Precision & DATEPRE_ENDMONTH)
609  {
611  if ($this->Precision & DATEPRE_ENDDAY)
612  {
614  }
615  else
616  {
617  $EndMonth++;
618  $EndDay = 0;
619  }
620  }
621  else
622  {
623  $EndYear++;
624  $EndMonth = 1;
625  $EndDay = 0;
626  }
627  }
628  else
629  {
631  if ($this->Precision & DATEPRE_BEGINMONTH)
632  {
634  if ($this->Precision & DATEPRE_BEGINDAY)
635  {
636  $EndDay = $BeginDay + 1;
637  }
638  else
639  {
640  $EndMonth++;
641  $EndDay = 0;
642  }
643  }
644  else
645  {
646  $EndYear++;
647  $EndMonth = 1;
648  $EndDay = 0;
649  }
650  }
651  $RangeBegin = "'".date("Y-m-d H:i:s", mktime(23, 59, 59, $BeginMonth, $BeginDay, $BeginYear))."'";
652  $RangeEnd = "'".date("Y-m-d H:i:s", mktime(23, 59, 59, $EndMonth, $EndDay, $EndYear))."'";
653 
654  # construct SQL condition
655  switch ($Operator)
656  {
657  case ">":
658  $Condition = " ${FieldName} > ${RangeEnd} ";
659  break;
660 
661  case ">=":
662  $Condition = " ${FieldName} > ${RangeBegin} ";
663  break;
664 
665  case "<":
666  $Condition = " ${FieldName} <= ${RangeBegin} ";
667  break;
668 
669  case "<=":
670  $Condition = " ${FieldName} <= ${RangeEnd} ";
671  break;
672 
673  case "!=":
674  $Condition = " (${FieldName} <= ${RangeBegin}"
675  ." OR ${FieldName} > ${RangeEnd}) ";
676  break;
677 
678  case "=":
679  default:
680  $Condition = " (${FieldName} > ${RangeBegin}"
681  ." AND ${FieldName} <= ${RangeEnd}) ";
682  break;
683  }
684  }
685 
686  # return condition to caller
687  return $Condition;
688  }
689 
690  # return string containing printable version of precision flags
692  {
693  if ($Precision === NULL) { $Precision = $this->Precision; }
694  $String = "";
695  if ($Precision & DATEPRE_BEGINYEAR) { $String .= "| BEGINYEAR "; }
696  if ($Precision & DATEPRE_BEGINMONTH) { $String .= "| BEGINMONTH "; }
697  if ($Precision & DATEPRE_BEGINDAY) { $String .= "| BEGINDAY "; }
698  if ($Precision & DATEPRE_BEGINDECADE) { $String .= "| BEGINDECADE "; }
699  if ($Precision & DATEPRE_ENDYEAR) { $String .= "| ENDYEAR "; }
700  if ($Precision & DATEPRE_ENDMONTH) { $String .= "| ENDMONTH "; }
701  if ($Precision & DATEPRE_ENDDAY) { $String .= "| ENDDAY "; }
702  if ($Precision & DATEPRE_ENDDECADE) { $String .= "| ENDDECADE "; }
703  if ($Precision & DATEPRE_INFERRED) { $String .= "| INFERRED "; }
704  if ($Precision & DATEPRE_COPYRIGHT) { $String .= "| COPYRIGHT "; }
705  if ($Precision & DATEPRE_CONTINUOUS) { $String .= "| CONTINUOUS "; }
706  if ($Precision & DATEPRE_SEPARATE) { $String .= "| SEPARATE "; }
707  $String = preg_replace("/^\\|/", "", $String);
708  return $String;
709  }
710 
711 
712  # ---- PRIVATE INTERFACE -------------------------------------------------
713 
717  var $EndDay;
719  var $EndYear;
722 
723  # Return the first non-empty parameterized subexpression match
724  # Expects a match array from preg_match()
725  # Expects a number of array elements, eg. match1, match2, match3
726  # Checks each element and returns the first non-empty one
727  # If they are all empty, NULL is returned
728  private function ExtractMatchData( $Matches, $Member, $Max )
729  {
730  for( $i=1; $i<=$Max; $i++ )
731  {
732  if (isset($Matches[$Member.$i]) && strlen($Matches[$Member.$i])>0)
733  {
734  return $Matches[$Member.$i];
735  }
736  }
737  return NULL;
738  }
739 }
740 
741 # date precision flags
742 define("DATEPRE_BEGINYEAR", 1);
743 define("DATEPRE_BEGINMONTH", 2);
744 define("DATEPRE_BEGINDAY", 4);
745 define("DATEPRE_BEGINDECADE", 8);
746 define("DATEPRE_BEGINCENTURY",16);
747 define("DATEPRE_ENDYEAR", 32);
748 define("DATEPRE_ENDMONTH", 64);
749 define("DATEPRE_ENDDAY", 128);
750 define("DATEPRE_ENDDECADE", 256);
751 define("DATEPRE_ENDCENTURY", 512);
752 define("DATEPRE_INFERRED", 1024);
753 define("DATEPRE_COPYRIGHT", 2048);
754 define("DATEPRE_CONTINUOUS", 4096);
755 define("DATEPRE_SEPARATE", 8192);
756 define("DATEPRE_UNSURE", 16384);
757 
758 
759 ?>