CWIS Developer Documentation

- Home
- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

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