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

Contents of /to_be_filed/webprojs/php_libraries/php_library/fboprime/t4.inc

Parent Directory Parent Directory | Revision Log Revision Log


Revision 35 - (show annotations) (download)
Sat Oct 8 23:35:33 2016 UTC (7 years, 11 months ago) by dashley
File size: 5279 byte(s)
Initial commit.
1 <?php
2 //$Header: /hl/cvsroots/gpl01/gpl01/webprojs/fboprime/sw/phplib/t4.inc,v 1.4 2006/07/29 04:04:55 dashley Exp $
3 //--------------------------------------------------------------------------------------------------------------
4 //t4.inc--Functions Manipulating the T4 Data Type
5 //Copyright (C) 2006 David T. Ashley
6 //
7 //This program is free software; you can redistribute it and/or
8 //modify it under the terms of the GNU General Public License
9 //as published by the Free Software Foundation; either version 2
10 //of the License, or (at your option) any later version.
11 //
12 //This program is distributed in the hope that it will be useful,
13 //but WITHOUT ANY WARRANTY; without even the implied warranty of
14 //MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 //GNU General Public License for more details.
16 //
17 //You should have received a copy of the GNU General Public License
18 //along with this program; if not, write to the Free Software
19 //Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 //********************************************************************************
21 //This contains functions that deal with the T4 format. The T4 format is
22 //"HHMM", and may range from "0000" through "2359".
23 //--------------------------------------------------------------------------------------------------------------
24 require_once("config.inc");
25 //--------------------------------------------------------------------------------------------------------------
26 //
27 //Returns 1 if the T4 is syntactically valid, or 0 otherwise.
28 //
29 //Unit-tested on 20060414.
30 //
31 function T4_is_valid($t4)
32 {
33 if (!is_string($t4)) //Must be string.
34 return(0);
35
36 if (strlen($t4) != 4) //Must be right length.
37 return(0);
38
39 if (strpos("0123456789", SubStr($t4, 3, 1)) === FALSE) //Minutes character must be 0-9.
40 return(0);
41
42 if (strpos("012345", SubStr($t4, 2, 1)) === FALSE) //Tens of minutes character must be 0-5.
43 return(0);
44
45 $c0 = SubStr($t4, 0, 1); //Extract tens of hours.
46 $c1 = SubStr($t4, 1, 1); //Extract hours.
47
48 if (($c0 == "0") || ($c0 == "1"))
49 {
50 if (strpos("0123456789", $c1) === FALSE) //If tens of hours is 0 or 1, hours must be 0-9.
51 return(0);
52 }
53 else if ($c0 == "2")
54 {
55 if (strpos("0123", $c1) === FALSE) //If tens of hours is 2, hours must be 0-3.
56 return(0);
57 }
58 else
59 {
60 return(0); //The tens of hours digit is invalid.
61 }
62
63 //If we've made it here, it is valid.
64 return(1);
65 }
66 //
67 //
68 //--------------------------------------------------------------------------------------------------------------
69 //
70 //Returns the time captured at page load, as a T4.
71 //
72 //Unit-tested on 20060414.
73 //
74 function T4_now_pageload()
75 {
76 global $GLOBAL_stime_string;
77
78 return(SubStr($GLOBAL_stime_string, 10, 4));
79 }
80 //
81 //
82 //--------------------------------------------------------------------------------------------------------------
83 //
84 //Extract the hours and minutes from a valid T4. The T4 must be known valid.
85 //
86 // t4 : The string to extract from.
87 // hour : The hour, as an integer.
88 // minute : The minute, as an integer.
89 //
90 //Unit-tested on 20060414.
91 //
92 function T4_extract_ints($t4, &$hour, &$minute)
93 {
94 $c0 = SubStr($t4, 0, 1); //Extract tens of hours.
95 $c1 = SubStr($t4, 1, 1); //Extract hours.
96 $c2 = SubStr($t4, 2, 1); //Extract tens of minutes.
97 $c3 = SubStr($t4, 3, 1); //Extract minutes.
98
99 $val0 = strpos("012", $c0);
100 $val1 = strpos("0123456789", $c1);
101 $val2 = strpos("012345", $c2);
102 $val3 = strpos("0123456789", $c3);
103
104 $hour = $val0 * 10 + $val1;
105 $minute = $val2 * 10 + $val3;
106 }
107 //
108 //
109 //--------------------------------------------------------------------------------------------------------------
110 //Maps from a T4 to the integer (0..47) corresponding to the half-hour interval that the T4 is a lower-bound
111 //of. 0 is returned on error. The passed T4 must be on a half-hour for this function to operate correctly.
112 //
113 function T4_lb_int($t4_in)
114 {
115 $result = strpos ( "0000/0030/0100/0130/0200/0230/0300/0330/0400/0430/0500/0530/" .
116 "0600/0630/0700/0730/0800/0830/0900/0930/1000/1030/1100/1130/" .
117 "1200/1230/1300/1330/1400/1430/1500/1530/1600/1630/1700/1730/" .
118 "1800/1830/1900/1930/2000/2030/2100/2130/2200/2230/2300/2330",
119 $t4_in);
120
121 if ($result === FALSE)
122 {
123 return(0);
124 }
125 else
126 {
127 return((int)($result / 5));
128 }
129 }
130 //
131 //--------------------------------------------------------------------------------------------------------------
132 //End of $RCSfile: t4.inc,v $.
133 //--------------------------------------------------------------------------------------------------------------
134 ?>

dashley@gmail.com
ViewVC Help
Powered by ViewVC 1.1.25