/[dtapublic]/to_be_filed/webprojs/php_libraries/php_library/fboprime/datefunc.inc
ViewVC logotype

Annotation of /to_be_filed/webprojs/php_libraries/php_library/fboprime/datefunc.inc

Parent Directory Parent Directory | Revision Log Revision Log


Revision 35 - (hide annotations) (download)
Sat Oct 8 23:35:33 2016 UTC (7 years, 11 months ago) by dashley
File size: 30017 byte(s)
Initial commit.
1 dashley 35 <?php
2     //$Header: /hl/cvsroots/gpl01/gpl01/webprojs/fboprime/sw/phplib/datefunc.inc,v 1.10 2006/08/01 23:14:06 dashley Exp $
3     //********************************************************************************
4     //Copyright (C)2006 David T. Ashley
5     //********************************************************************************
6     //This program or source file is free software; you can redistribute it and/or
7     //modify it under the terms of the GNU General Public License as published by
8     //the Free Software Foundation; either version 2 of the License, or (at your
9     //option) any later version.
10     //
11     //This program or source file is distributed in the hope that it will
12     //be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
13     //MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14     //GNU General Public License for more details.
15     //
16     //You may have received a copy of the GNU General Public License
17     //along with this program; if not, write to the Free Software
18     //Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19     //********************************************************************************
20     //Dave Ashley, 04/06
21     //
22     //This source file contains date and time calculation and
23     //manipulation functions.
24     //
25     require_once("config.inc"); //Scheduling configuration.
26     require_once("confighard.inc"); //Necessary for date minimums and maximums.
27     //
28     //================================================================================
29     //================================================================================
30     //==== R A W C A L C U L A T I O N ==========================================
31     //================================================================================
32     //================================================================================
33     //Returns the number of days in the year.
34     //
35     //Unit-tested 20060408.
36     //
37     function DATEFUNC_year_days($year)
38     {
39     //May need to be changed if confighard.inc is modified for a longer calendar
40     //range.
41     $mod_4 = $year % 4;
42     $mod_100 = $year % 100;
43     $mod_400 = $year % 400;
44    
45     if ($mod_4 != 0)
46     {
47     //We can't have a leap year unless it is divisible by 4.
48     return(365);
49     }
50     else if (($mod_100 == 0) && ($mod_400 != 0))
51     {
52     //Divisible by 100 and not divible by 400. Not a leap year.
53     return(365);
54     }
55     else
56     {
57     //Divisible by 4 and not meeting the exception case: leap year.
58     return(366);
59     }
60     }
61     //
62     //
63     //--------------------------------------------------------------------------------
64     //Returns the number of days in all years preceding but not including the
65     //start year. This is used for modulo arithmetic to determine day of week
66     //and so on. An array is much faster (I think and hope) than an iterative method
67     //involving summing the years.
68     //
69     //Note: this function has not yet been unit-tested (after it was changed from
70     //a lookup table). This is still todo.
71     //
72     function DATEFUNC_year_predecessor_sum($year_in)
73     {
74     //Customized for lower limit of 1700, upper limit if 2300.
75     //
76     if (($year_in >= CONFIGHARD_DATEFUNC_MINYEAR) && ($year_in < CONFIGHARD_DATEFUNC_MAXYEAR))
77     {
78     //In year $year_in, the number of prior years where the year was divisible
79     //by 4 is given by the expression below.
80     if ($year_in == CONFIGHARD_DATEFUNC_MINYEAR)
81     {
82     $years_prior_div_4 = 0;
83     }
84     else
85     {
86     $years_prior_div_4 = (int)(($year_in - 1 - CONFIGHARD_DATEFUNC_MINYEAR) / 4);
87     //Verified in the PHP docs that cast to int from float behaves with classic
88     //div behavior (rounding down), so will be OK.
89     }
90    
91     //Correct for the fact that 1800, 1900, 2100, and 2200 are not leap years, but 2000 is.
92     if (($year_in > 1800) && ($year_in <= 1900))
93     {
94     //1800 was not a leap year, so we need to deduct 1 from the total leap years encountered.
95     $years_prior_div_4 -= 1;
96     }
97     else if (($year_in > 1900) && ($year_in <= 2100))
98     {
99     //1800 was not a leap year, and 1900 was not a leap year (but 2000 was),
100     //so we need to deduct 2 from the total leap years encountered.
101     $years_prior_div_4 -= 2;
102     }
103     else if (($year_in > 2100) && ($year_in <= 2200))
104     {
105     //1800, 1900, and 2100 were not leap years (but 2000 was),
106     //so we need to deduct 3 from the total leap years encountered.
107     $years_prior_div_4 -= 3;
108     }
109     else /* if (($year_in > 2200) && ($year_in <= 2300)) */
110     {
111     //1800, 1900, 2100, and 2200 were not leap years (but 2000 was),
112     //so we need to deduct 4 from the total leap years encountered.
113     $years_prior_div_4 -= 4;
114     }
115    
116     //The total number of days in years prior is going to be 365 times the number
117     //of years prior, except we need to add a day for each leap year prior.
118     if ($year_in == CONFIGHARD_DATEFUNC_MINYEAR)
119     {
120     return(0);
121     }
122     else
123     {
124     return((int)(($year_in - CONFIGHARD_DATEFUNC_MINYEAR) * 365 + $years_prior_div_4));
125     }
126     }
127     else
128     {
129     //Not a year we can calculate about. Don't want to error-trap at such a
130     //low level. Just return zero.
131     return(0);
132     }
133     }
134     //
135     //
136     //--------------------------------------------------------------------------------
137     //Calculates the number of days in a given month of a given year. Years are
138     //2000 ... (i.e. full-sized integer), and months are referenced in the traditional
139     //way, 1..12.
140     //
141     //Unit-tested 20060408.
142     //
143     function DATEFUNC_year_month_days($year, $month)
144     {
145     switch ($month)
146     {
147     default:
148     case 1:
149     return(31);
150     break;
151     case 2:
152     if (DATEFUNC_year_days($year) == 365)
153     {
154     return(28);
155     }
156     else
157     {
158     return(29);
159     }
160     break;
161     case 3:
162     return(31);
163     break;
164     case 4:
165     return(30);
166     break;
167     case 5:
168     return(31);
169     break;
170     case 6:
171     return(30);
172     break;
173     case 7:
174     return(31);
175     break;
176     case 8:
177     return(31);
178     break;
179     case 9:
180     return(30);
181     break;
182     case 10:
183     return(31);
184     break;
185     case 11:
186     return(30);
187     break;
188     case 12:
189     return(31);
190     break;
191     }
192     }
193     //
194     //
195     //--------------------------------------------------------------------------------
196     //Calcualtes the Julian offset of a date within a certain year. The offset
197     //of January 1 of any year is 0. Year, month, and day are 2000 ..., 1 ..., and
198     //1 ..., respectively.
199     //
200     //Unit-tested 20060408.
201     //
202     function DATEFUNC_year_julian_offset($year, $month, $day)
203     {
204     switch ($month)
205     {
206     default:
207     case 1:
208     return($day - 1);
209     break;
210     case 2:
211     return(31 + $day - 1);
212     case 3:
213     if (DATEFUNC_year_days($year) == 365)
214     {
215     return(59 + $day - 1);
216     }
217     else
218     {
219     return(59 + $day);
220     }
221     break;
222     case 4:
223     if (DATEFUNC_year_days($year) == 365)
224     {
225     return(90 + $day - 1);
226     }
227     else
228     {
229     return(90 + $day);
230     }
231     break;
232     case 5:
233     if (DATEFUNC_year_days($year) == 365)
234     {
235     return(120 + $day - 1);
236     }
237     else
238     {
239     return(120 + $day);
240     }
241     break;
242     case 6:
243     if (DATEFUNC_year_days($year) == 365)
244     {
245     return(151 + $day - 1);
246     }
247     else
248     {
249     return(151 + $day);
250     }
251     break;
252     case 7:
253     if (DATEFUNC_year_days($year) == 365)
254     {
255     return(181 + $day - 1);
256     }
257     else
258     {
259     return(181 + $day);
260     }
261     break;
262     case 8:
263     if (DATEFUNC_year_days($year) == 365)
264     {
265     return(212 + $day - 1);
266     }
267     else
268     {
269     return(212 + $day);
270     }
271     break;
272     case 9:
273     if (DATEFUNC_year_days($year) == 365)
274     {
275     return(243 + $day - 1);
276     }
277     else
278     {
279     return(243 + $day);
280     }
281     break;
282     case 10:
283     if (DATEFUNC_year_days($year) == 365)
284     {
285     return(273 + $day - 1);
286     }
287     else
288     {
289     return(273 + $day);
290     }
291     break;
292     case 11:
293     if (DATEFUNC_year_days($year) == 365)
294     {
295     return(304 + $day - 1);
296     }
297     else
298     {
299     return(304 + $day);
300     }
301     break;
302     case 12:
303     if (DATEFUNC_year_days($year) == 365)
304     {
305     return(334 + $day - 1);
306     }
307     else
308     {
309     return(334 + $day);
310     }
311     break;
312     }
313     }
314     //
315     //
316     //--------------------------------------------------------------------------------
317     //Given year, month, and day (2000 ..., 1 ..., 1 ...), returns an integer
318     //representing the day of the week.
319     // 0 : Sunday
320     // 1 : Monday
321     // 2 : Tuesday
322     // 3 : Wednesday
323     // 4 : Thursday
324     // 5 : Friday
325     // 6 : Saturday
326     //
327     //Unit-tested 20060408.
328     //
329     function DATEFUNC_intdayofweek_intdate($year, $month, $day)
330     {
331     $int_differential = CONFIGHARD_DATEFUNC_EPOCH_DOW
332     + DATEFUNC_year_predecessor_sum($year)
333     + DATEFUNC_year_julian_offset($year, $month, $day);
334     return($int_differential % 7);
335     }
336     //--------------------------------------------------------------------------------
337     //Compares two dates, expressed as integers. Both must be properly formatted
338     //(i.e. valid years, months, and days). Returns:
339     // -1 if a < b.
340     // 0 if a == b.
341     // 1 if a > b.
342     //
343     function DATEFUNC_cmp($ya, $ma, $da, $yb, $mb, $db)
344     {
345     if ($ya < $yb)
346     {
347     return(-1);
348     }
349     else if ($ya > $yb)
350     {
351     return(1);
352     }
353     else
354     {
355     if ($ma < $mb)
356     {
357     return(-1);
358     }
359     else if ($ma > $mb)
360     {
361     return(1);
362     }
363     else
364     {
365     if ($da < $db)
366     {
367     return(-1);
368     }
369     else if ($da > $db)
370     {
371     return(1);
372     }
373     else
374     {
375     return(0);
376     }
377     }
378     }
379     }
380     //
381     //
382     //--------------------------------------------------------------------------------
383     //Given a year, a month, and a month offset, moves the passed date backward
384     //(in the case of negative month offset) or forward (in the case of positive
385     //month offset) and calculates a new year and month. The calculated returned
386     //value will not go outside the range set in CONFIGHARD.INC for the
387     //scheduling range.
388     //
389     //A result flag is set to:
390     // -1 : If the result had to be clipped because it went outside the calendar
391     // functionality window.
392     // 0 : If the result did not have to be clipped.
393     // 1 : If the result had to be clipped because it went outside the calendar
394     // functionality window.
395     //
396     //The values passed in must be valid.
397     //
398     //The ordinal month approach is used because integer math tends to be
399     //very fast.
400     //
401     function DATEFUNC_offset_month($year_in, $month_in, $month_offset_in, &$year_out, &$month_out, &$result_out)
402     {
403     //Default value of result.
404     $result_out = 0;
405    
406     //Create ordinal month representations of the min and max allowable months. Using this
407     //scheme, the 0'th month would be January of 0 A.D.
408     $min_ordinal_month = CONFIGHARD_DATEFUNC_MINYEAR * 12;
409     $max_ordinal_month = CONFIGHARD_DATEFUNC_MAXYEAR * 12 - 1;
410    
411     //Create ordinal month representation of the input year, month.
412     $in_ordinal_month = $year_in * 12 + $month_in - 1;
413    
414     //Create the ordinal month reprsentation of the input + offset.
415     $calcd_ordinal_month = $in_ordinal_month + $month_offset_in;
416    
417     //Clip the result to be within the scheduling range of the FBO-prime software.
418     if ($calcd_ordinal_month < $min_ordinal_month)
419     {
420     $calcd_ordinal_month = $min_ordinal_month;
421     $result_out = -1;
422     }
423     else if ($calcd_ordinal_month > $max_ordinal_month)
424     {
425     $calcd_ordinal_month = $max_ordinal_month;
426     $result_out = 1;
427     }
428    
429     //Convert back to calendar year and month format.
430     $year_out = (int) ($calcd_ordinal_month / 12);
431     $month_out = ($calcd_ordinal_month % 12) + 1;
432     }
433     //
434     //
435     //--------------------------------------------------------------------------------
436     //Calculates the date one week ago. The date passed in must be within the
437     //calendaring range and the date one week before must be also within
438     //calendaring range.
439     //
440     function DATEFUNC_one_week_ago($year_in, $month_in, $day_in, &$year_out, &$month_out, &$day_out)
441     {
442     if (($day_in - 7) > 0)
443     {
444     //Simplest case. Different date within the same month.
445     $year_out = $year_in;
446     $month_out = $month_in;
447     $day_out = $day_in - 7;
448     }
449     else
450     {
451     //Have to roll the month backwards.
452     if ($month_in > 1)
453     {
454     //Have to roll day and month backwards, but not the year.
455     $year_out = $year_in;
456     $month_out = $month_in - 1;
457     $day_out = $day_in - 7 + DATEFUNC_year_month_days($year_in, $month_in - 1);
458     }
459     else
460     {
461     //Have to roll back the day, month, and year.
462     $year_out = $year_in - 1;
463     $month_out = 12;
464     $day_out = $day_in - 7 + DATEFUNC_year_month_days($year_in - 1, 12);
465     }
466     }
467     }
468     //
469     //--------------------------------------------------------------------------------
470     //Calculates the date one week in the future. The date passed in must be within the
471     //calendaring range and the date one week in the future must be also within
472     //calendaring range.
473     //
474     function DATEFUNC_one_week_future($year_in, $month_in, $day_in, &$year_out, &$month_out, &$day_out)
475     {
476     $days_in_month = DATEFUNC_year_month_days($year_in, $month_in);
477    
478     if (($day_in + 7) <= $days_in_month)
479     {
480     //Simplest case. Different date within the same month.
481     $year_out = $year_in;
482     $month_out = $month_in;
483     $day_out = $day_in + 7;
484     }
485     else
486     {
487     //Have to roll the month forward.
488     if ($month_in < 12)
489     {
490     //Have to roll day and month forward, but not the year.
491     $year_out = $year_in;
492     $month_out = $month_in + 1;
493     $day_out = $day_in + 7 - $days_in_month;
494     }
495     else
496     {
497     //Have to roll forward the day, month, and year.
498     $year_out = $year_in + 1;
499     $month_out = 1;
500     $day_out = $day_in + 7 - $days_in_month;
501     }
502     }
503     }
504     //
505     //--------------------------------------------------------------------------------
506     //Calculates the date one day ago. The date passed in must be within the
507     //calendaring range and the date one day before must be also within
508     //calendaring range.
509     //
510     function DATEFUNC_one_day_ago($year_in, $month_in, $day_in, &$year_out, &$month_out, &$day_out)
511     {
512     if ($day_in > 1)
513     {
514     //Simplest case. Different date within the same month.
515     $year_out = $year_in;
516     $month_out = $month_in;
517     $day_out = $day_in - 1;
518     }
519     else
520     {
521     //Have to roll the month backwards.
522     if ($month_in > 1)
523     {
524     //Have to roll day and month backwards, but not the year.
525     $year_out = $year_in;
526     $month_out = $month_in - 1;
527     $day_out = DATEFUNC_year_month_days($year_in, $month_in - 1);
528     }
529     else
530     {
531     //Have to roll back the day, month, and year.
532     $year_out = $year_in - 1;
533     $month_out = 12;
534     $day_out = DATEFUNC_year_month_days($year_in - 1, 12);
535     }
536     }
537     }
538     //
539     //--------------------------------------------------------------------------------
540     //Calculates the date one day in the future. The date passed in must be within the
541     //calendaring range and the date one day in the future must be also within
542     //calendaring range.
543     //
544     function DATEFUNC_one_day_future($year_in, $month_in, $day_in, &$year_out, &$month_out, &$day_out)
545     {
546     $days_in_month = DATEFUNC_year_month_days($year_in, $month_in);
547    
548     if ($day_in < $days_in_month)
549     {
550     //Simplest case. Different date within the same month.
551     $year_out = $year_in;
552     $month_out = $month_in;
553     $day_out = $day_in + 1;
554     }
555     else
556     {
557     //Have to roll the month forwards.
558     if ($month_in < 12)
559     {
560     //Have to roll day and month forward, but not the year.
561     $year_out = $year_in;
562     $month_out = $month_in + 1;
563     $day_out = 1;
564     }
565     else
566     {
567     //Have to roll forward the day, month, and year.
568     $year_out = $year_in + 1;
569     $month_out = 1;
570     $day_out = 1;
571     }
572     }
573     }
574     //
575     //--------------------------------------------------------------------------------
576     //Given a year and a month, indicates whether it is within the window of
577     //what should be viewable for scheduling.
578     //
579     //The criteria for displaying the month are:
580     // a)The month is not outside the calendaring functionality window.
581     // b)The month is not outside the parameters set by the
582     // configuration constants CONFIG_SCHED_SCHEDACC_PREV_MO or
583     // CONFIG_SCHED_SCHEDACC_FUTU_MO, which specify how many months
584     // previous and future may be viewed.
585     //
586     //Returns:
587     // -1 : If the year/month is too early to be
588     // schedulable.
589     // 0 : If the year/month should be schedulable.
590     // 1 : If the year/month is too late to be schedulable.
591     //
592     function DATEFUNC_is_not_displayable($year_in, $month_in)
593     {
594     global $GLOBAL_stime_year;
595     global $GLOBAL_stime_month;
596    
597     //If the year is out of bounds, it is a no-go.
598     if ($year_in < CONFIGHARD_DATEFUNC_MINYEAR)
599     return(-1);
600     else if ($year_in >= CONFIGHARD_DATEFUNC_MAXYEAR)
601     return(1);
602    
603     //If the month is out of bounds, it is a no-go.
604     if (($month_in < 1) || ($month_in > 12))
605     return(1); //Arbitrary, as long as it isn't 0.
606    
607     //For reference, find the year/month that is CONFIG_SCHED_SCHEDACC_PREV_MO
608     //behind the passed year/month. If this is clipped, no harm done.
609     DATEFUNC_offset_month($GLOBAL_stime_year,
610     $GLOBAL_stime_month,
611     -CONFIG_SCHED_SCHEDACC_PREV_MO,
612     $year_lower_limit,
613     $month_lower_limit,
614     $result_flag);
615    
616     //For reference, find the year/month that is CONFIG_SCHED_SCHEDACC_FUTU_MO
617     //ahead of the passed year/month. If this is clipped, no harm done.
618     DATEFUNC_offset_month($GLOBAL_stime_year,
619     $GLOBAL_stime_month,
620     CONFIG_SCHED_SCHEDACC_FUTU_MO,
621     $year_upper_limit,
622     $month_upper_limit,
623     $result_flag);
624    
625     //echo " year upper limit : " . $year_upper_limit . " month_upper_limit : " . $month_upper_limit . " ";
626    
627     //If the passed year/month are below the lower limit, this means it isn't
628     //displayable.
629     if (DATEFUNC_cmp($year_in, $month_in, 1, $year_lower_limit, $month_lower_limit, 1) == -1)
630     return(-1);
631    
632     //If the passed year/month are above the upper limit, this means it isn't
633     //displayable.
634     if (DATEFUNC_cmp($year_in, $month_in, 1, $year_upper_limit, $month_upper_limit, 1) == 1)
635     return(1);
636    
637     //If we're here, it is displayable.
638     return(0);
639     }
640     //
641     //================================================================================
642     //================================================================================
643     //==== S T R I N G M A P P I N G ============================================
644     //================================================================================
645     //================================================================================
646     //
647     //Returns the string associated with an ordinal month number 1-12.
648     //
649     function DATEFUNC_string_month_long($month_no)
650     {
651     $lookup = array("January",
652     "February",
653     "March",
654     "April",
655     "May",
656     "June",
657     "July",
658     "August",
659     "September",
660     "October",
661     "November",
662     "December");
663    
664     if (($month_no < 1) || ($month_no > 12))
665     {
666     return("INVALID");
667     }
668     else
669     {
670     return($lookup[$month_no - 1]);
671     }
672     }
673     //
674     //--------------------------------------------------------------------------------
675     //Returns the string associated with a day of the week 0-6.
676     //
677     function DATEFUNC_string_dow_long($dow_no)
678     {
679     $lookup = array("Sunday",
680     "Monday",
681     "Tuesday",
682     "Wednesday",
683     "Thursday",
684     "Friday",
685     "Saturday");
686    
687     if (($dow_no < 0) || ($dow_no > 6))
688     {
689     return("INVALID");
690     }
691     else
692     {
693     return($lookup[$dow_no]);
694     }
695     }
696     //--------------------------------------------------------------------------------
697     //Returns a string representing the standard date, i.e. "January 19, 2009" or
698     //whatever.
699     //
700     function DATEFUNC_stdlongdate($year, $month, $day)
701     {
702     return(DATEFUNC_string_month_long($month) . " " . $day . ", " . $year);
703     }
704     //
705     //--------------------------------------------------------------------------------
706     //Returns a string representing the standard date with day of the week,
707     //i.e. "Friday, January 19, 2009" or whatever.
708     //
709     function DATEFUNC_stdlongdate_w_dow($year, $month, $day)
710     {
711     $dow = DATEFUNC_intdayofweek_intdate($year, $month, $day);
712     return( DATEFUNC_string_dow_long($dow)
713     . ", "
714     . DATEFUNC_string_month_long($month)
715     . " "
716     . $day
717     . ", "
718     . $year);
719     }
720     //
721     //--------------------------------------------------------------------------------
722     //Returns a string representing the standard time. In non-military format,
723     //this will be something like 5:04 p.m. In military time, something like
724     //17:04.
725     //
726     function DATEFUNC_stdtimenosec($hour, $minute)
727     {
728     if (CONFIG_TIME_FORMAT_24HR)
729     {
730     //24-hour format.
731     return(sprintf("%02d", $hour) . ":" . sprintf("%02d", $minute));
732     }
733     else
734     {
735     //12-hour format.
736     if ($hour == 0)
737     {
738     return(sprintf("%d", 12) . ":" . sprintf("%02d", $minute) . " a.m.");
739     }
740     else if ($hour < 12)
741     {
742     return(sprintf("%d", $hour) . ":" . sprintf("%02d", $minute) . " a.m.");
743     }
744     else if ($hour == 12)
745     {
746     return(sprintf("%d", $hour) . ":" . sprintf("%02d", $minute) . " p.m.");
747     }
748     else
749     {
750     return(sprintf("%d", $hour - 12) . ":" . sprintf("%02d", $minute) . " p.m.");
751     }
752     }
753     }
754     //
755     //--------------------------------------------------------------------------------
756     //Calculate and return an array of Boolean results to determine whether it is OK
757     //to view/schedule the indicated date/time. Each Boolean result is TRUE if it is
758     //OK to view/schedule or FALSE if not.
759     //
760     // a)[0] A month ago.
761     // b)[1] A week ago.
762     // c)[2] A day ago.
763     // d)[3] One panel back.
764     // e)[4] One panel forward.
765     // f)[5] One day forward.
766     // g)[6] One week forward.
767     // h)[7] One month forward.
768     //
769     function DATEFUNC_viewschedtime_differential_array($dispyear, $dispmonth, $dispday,
770     $disphour, $dispminute)
771     {
772     global $CONFIG_SCHED_DAY_PANELS;
773    
774     //Default to all FALSE so we don't forget anything.
775     //
776     $rv = array(FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE);
777    
778     //NOW
779     //---
780     //For reference, determine if the base display date passed in is
781     //displayable/schedulable.
782     //
783     if (DATEFUNC_is_not_displayable($dispyear, $dispmonth) == 0)
784     $base_date_is_ok = TRUE;
785     else
786     $base_date_is_ok = FALSE;
787    
788     //A MONTH AGO
789     //-----------
790     //First, try to back off one month to get to the previous month. If we fail on this
791     //(because we're at the lower limit of what the calendar functionality can handle),
792     //then we definitely can't display the previous month.
793     //
794     DATEFUNC_offset_month($dispyear, $dispmonth, -1, $prev_month_year, $prev_month_month, $prev_month_result_code);
795    
796     if ($prev_month_result_code == 0)
797     {
798     //We are not up against the limit of the calendaring functionality.
799     //Evaluate the previous month.
800     //
801     if (DATEFUNC_is_not_displayable($prev_month_year, $prev_month_month) == 0)
802     {
803     $rv[0] = TRUE; //Seems OK.
804     }
805     else
806     {
807     $rv[0] = FALSE; //Is outside the viewable range.
808     }
809     }
810     else
811     {
812     //We couldn't back off because we were at the limit.
813     $rv[0] = FALSE;
814     }
815    
816     //A WEEK AGO
817     //-----------
818     //The logic for a week ago is that if the day of the month is seven or less, the previous
819     //month is relevant, else the current month is relevant.
820     if ($dispday <= 7)
821     $rv[1] = $rv[0];
822     else
823     $rv[1] = $base_date_is_ok;
824    
825     //A DAY AGO
826     //-----------
827     //The logic for a day ago is that if the day of the month is 1, the previous
828     //month is relevant, else the current month is relevant.
829     if ($dispday == 1)
830     $rv[2] = $rv[0];
831     else
832     $rv[2] = $base_date_is_ok;
833    
834     //ONE PANEL BACK
835     //--------------
836     //Get the currently appropriate panel.
837     $panel = TOD_best_panel($disphour, $dispminute, $CONFIG_SCHED_DAY_PANELS);
838     //
839     //If the current panel is not 0, backing off the panel won't change the date,
840     //and so the passed date's status is the right thing to look at.
841     //
842     //If the current panel is 0, backing off will move the date to the previous
843     //day, and we use that status.
844     if ($panel != 0)
845     {
846     $rv[3] = $base_date_is_ok;
847     }
848     else
849     {
850     $rv[3] = $rv[2];
851     }
852    
853     //A MONTH IN THE FUTURE
854     //---------------------
855     //First, try to go forward one month to get to the next month. If we fail on this
856     //(because we're at the upper limit of what the calendar functionality can handle),
857     //then we definitely can't display the next month.
858     //
859     DATEFUNC_offset_month($dispyear, $dispmonth, 1, $next_month_year, $next_month_month, $next_month_result_code);
860    
861     if ($next_month_result_code == 0)
862     {
863     //We are not up against the limit of the calendaring functionality.
864     //Evaluate the next month.
865     //
866     if (DATEFUNC_is_not_displayable($next_month_year, $next_month_month) == 0)
867     {
868     $rv[7] = TRUE; //Seems OK.
869     }
870     else
871     {
872     $rv[7] = FALSE; //Is outside the viewable range.
873     }
874     }
875     else
876     {
877     //We couldn't go forward because we were at the limit.
878     $rv[7] = FALSE;
879     }
880    
881     //A WEEK IN THE FUTURE
882     //--------------------
883     //The logic for a week in the future is that if going forward 7 days will put us
884     //into the next month, then the validity of that applies, otherwise the
885     //validity for the current month applies.
886     $days_in_base_month = DATEFUNC_year_month_days($dispyear, $dispmonth);
887    
888     if (($dispday + 7) > $days_in_base_month)
889     {
890     //Get value from next month.
891     $rv[6] = $rv[7];
892     }
893     else
894     {
895     //Get value from this month.
896     $rv[6] = $base_date_is_ok;
897     }
898    
899     //A DAY IN THE FUTURE
900     //-------------------
901     //The logic for a day in the future is that if the current day is the last day of
902     //the month, then next month's value applies, otherwise this month's
903     //value applies.
904     if ($dispday >= $days_in_base_month)
905     $rv[5] = $rv[7]; //Next month's value.
906     else
907     $rv[5] = $base_date_is_ok; //This month's value.
908    
909     //ONE PANEL IN THE FUTURE
910     //-----------------------
911     //If the current panel is not the last one, going to the next panel won't change
912     //the date, and so the passed date's status is the right thing to look at.
913     //
914     //If the current panel is the last one, going forward will move the date to the
915     //next day, and we use that status.
916     $npanels = (int)(count($CONFIG_SCHED_DAY_PANELS) / 2);
917     if ($panel >= ($npanels - 1)) //Last penel test.
918     {
919     $rv[4] = $rv[5];
920     }
921     else
922     {
923     $rv[4] = $base_date_is_ok;
924     }
925    
926     //Return the return value.
927     return($rv);
928     }
929     //
930     //--------------------------------------------------------------------------------
931     //End of $RCSfile: datefunc.inc,v $.
932     //--------------------------------------------------------------------------------
933     ?>

dashley@gmail.com
ViewVC Help
Powered by ViewVC 1.1.25