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