1 |
<?php
|
2 |
//$Header: /hl/cvsroots/gpl01/gpl01/webprojs/fboprime/sw/phplib/stimex.inc,v 1.3 2006/09/25 20:01:28 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, 08/06
|
21 |
//
|
22 |
//This source file contains functions that operate on STIME, but are not needed
|
23 |
//by the day view scheduler.
|
24 |
//
|
25 |
require_once("datefunc.inc");
|
26 |
require_once("stime.inc");
|
27 |
//
|
28 |
//--------------------------------------------------------------------------------
|
29 |
//Calculates the difference between two STIMEs, and returns a string representing
|
30 |
//that difference. The string returned will be either of the form (by example):
|
31 |
// a)34m
|
32 |
// b)4h 34m
|
33 |
// c)1d 9h
|
34 |
// d)44d
|
35 |
//
|
36 |
//The string returned is absolute value.
|
37 |
//
|
38 |
function STIME_diff_string_a($st0_in, $st1_in)
|
39 |
{
|
40 |
//We require st1 to be no sooner than st0. Reorder if necessary.
|
41 |
if (strcmp($st0_in, $st1_in) > 0)
|
42 |
{
|
43 |
$temp = $st0_in;
|
44 |
$st0_in = $st1_in;
|
45 |
$st1_in = $temp;
|
46 |
}
|
47 |
//
|
48 |
//Extract components.
|
49 |
//
|
50 |
sscanf(SubStr($st0_in, 2), "%04d%02d%02d%02d%02d", $year0, $month0, $day0, $hour0, $minute0);
|
51 |
sscanf(SubStr($st1_in, 2), "%04d%02d%02d%02d%02d", $year1, $month1, $day1, $hour1, $minute1);
|
52 |
//
|
53 |
//Calculate relative offset of dates in minutes.
|
54 |
//
|
55 |
$dayoffset0 = 24 * 60 * (DATEFUNC_year_predecessor_sum($year0) + DATEFUNC_year_julian_offset($year0, $month0, $day0));
|
56 |
$dayoffset1 = 24 * 60 * (DATEFUNC_year_predecessor_sum($year1) + DATEFUNC_year_julian_offset($year1, $month1, $day1));
|
57 |
//
|
58 |
//Calculate relative offset of times in minutes.
|
59 |
$minuteoffset0 = $hour0 * 60 + $minute0;
|
60 |
$minuteoffset1 = $hour1 * 60 + $minute1;
|
61 |
|
62 |
$diffminutes = ($dayoffset1 + $minuteoffset1) - ($dayoffset0 + $minuteoffset0);
|
63 |
|
64 |
//Figure out which display format to use.
|
65 |
if ($diffminutes < 60)
|
66 |
{
|
67 |
//a
|
68 |
$rv = sprintf("%dm", $diffminutes);
|
69 |
}
|
70 |
else if ($diffminutes < 2880)
|
71 |
{
|
72 |
//b
|
73 |
$inthours = (int)($diffminutes/60);
|
74 |
$leftoverminutes = $diffminutes - ($inthours * 60);
|
75 |
$rv = sprintf("%dh %dm", $inthours, $leftoverminutes);
|
76 |
}
|
77 |
else if ($diffminutes < 7200)
|
78 |
{
|
79 |
//c
|
80 |
$intdays = (int)($diffminutes/1440);
|
81 |
$leftoverminutes = $diffminutes - ($intdays * 1440);
|
82 |
$inthours = (int)($leftoverminutes / 60);
|
83 |
|
84 |
$rv = sprintf("%dd %dh", $intdays, $inthours);
|
85 |
}
|
86 |
else
|
87 |
{
|
88 |
//d
|
89 |
$rv = sprintf("%dd", (int)($diffminutes/1440));
|
90 |
}
|
91 |
|
92 |
return($rv);
|
93 |
}
|
94 |
//
|
95 |
//--------------------------------------------------------------------------------
|
96 |
//Returns a 2-character day-of-week representation of the date of an STIME.
|
97 |
//Values are Su, Mo, Tu, We, Th, Fr, Sa.
|
98 |
//
|
99 |
function STIME_dow_string_a($st_in)
|
100 |
{
|
101 |
//Extract components.
|
102 |
//
|
103 |
sscanf(SubStr($st_in, 2), "%04d%02d%02d", $year, $month, $day);
|
104 |
//
|
105 |
//Calculate day of week.
|
106 |
$dow = DATEFUNC_intdayofweek_intdate($year, $month, $day);
|
107 |
//
|
108 |
//Calc the string, return to caller.
|
109 |
return(SubStr("SuMoTuWeThFrSa", $dow*2, 2));
|
110 |
}
|
111 |
//
|
112 |
//--------------------------------------------------------------------------------
|
113 |
//Reformats an STIME string to include dots at strategic places for more
|
114 |
//human-friendly display.
|
115 |
//
|
116 |
function STIME_dotted_display_string_a($stime_in)
|
117 |
{
|
118 |
if (! is_string($stime_in))
|
119 |
{
|
120 |
//Don't know what this is ... it isn't an stime. Just send it back.
|
121 |
return($stime_in);
|
122 |
}
|
123 |
else if (strlen($stime_in) != 22)
|
124 |
{
|
125 |
//This doesn't seem to be the right length for an stime. Give it back.
|
126 |
return($stime_in);
|
127 |
}
|
128 |
else
|
129 |
{
|
130 |
//Seems right.
|
131 |
return(
|
132 |
SubStr($stime_in, 0, 2)
|
133 |
.
|
134 |
"."
|
135 |
.
|
136 |
SubStr($stime_in, 2, 4)
|
137 |
.
|
138 |
"."
|
139 |
.
|
140 |
SubStr($stime_in, 6, 2)
|
141 |
.
|
142 |
"."
|
143 |
.
|
144 |
SubStr($stime_in, 8, 2)
|
145 |
.
|
146 |
"."
|
147 |
.
|
148 |
SubStr($stime_in, 10, 2)
|
149 |
.
|
150 |
"."
|
151 |
.
|
152 |
SubStr($stime_in, 12, 2)
|
153 |
.
|
154 |
"."
|
155 |
.
|
156 |
SubStr($stime_in, 14, 2)
|
157 |
.
|
158 |
"."
|
159 |
.
|
160 |
SubStr($stime_in, 16, 6)
|
161 |
);
|
162 |
}
|
163 |
}
|
164 |
//
|
165 |
//--------------------------------------------------------------------------------
|
166 |
//End of $RCSfile: stimex.inc,v $.
|
167 |
//--------------------------------------------------------------------------------
|
168 |
?>
|