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