PHP Classes

File: test.php

Recommend this page to a friend!
  Classes of Cale O   Date and Time Calculator   test.php   Download  
File: test.php
Role: Example script
Content type: text/plain
Description: HTML Form to test date/time calculations using this class.
Class: Date and Time Calculator
Add or subtract dates and times in custom formats
Author: By
Last change: Added the syntax generation.
Date: 15 years ago
Size: 8,701 bytes
 

Contents

Class file image Download
<?php

require_once "class.datetimecalc.php";


?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Date and Time Calculator - Examples, Usage, and Syntax</title>
<style type="text/css">
<!--
body,td,th {
    font-family: Verdana, Arial, Helvetica, sans-serif;
    font-size: 14px;
}
.style1 {
    color: #FFFFFF;
    font-weight: bold;
}
.biggertextbox {
    width: 250px;
}
.red {color: #ff0000;}
.blue {color: #0000ff;}
.code {color: #179D17;}
.green {color: #003300;}


-->
</style></head>

<body>
<br>

<?php

if ($_POST['Submit'] == "Calculate") {

   
$obj = new Date_Time_Calc($_POST['input'], $_POST['mask']);
    if (
$_POST['calc'] == "Add") {
       
$output = $obj->add($_POST['unit_of_time'], $_POST['howmuch'], true);
       
$syntax = '$obj = new Date_Time_Calc("' . $_POST['input'] . '", "' . $_POST['mask'] . '");<br>';
       
$syntax .= 'echo $obj->add("' . $_POST['unit_of_time'] . '", ' . $_POST['howmuch'] . ');';
    } else {
       
$output = $obj->subtract($_POST['unit_of_time'], $_POST['howmuch'], true);
       
$syntax = '$obj = new Date_Time_Calc("' . $_POST['input'] . '", "' . $_POST['mask'] . '");<br>';
       
$syntax .= 'echo $obj->subtract("' . $_POST['unit_of_time'] . '", ' . $_POST['howmuch'] . ');';
    }

} else {
   
$_POST['input'] = "05/03/2008";
   
$_POST['mask'] = "m/d/Y";
   
$_POST['calc'] = "Add";
   
$_POST['unit_of_time'] = "day";
   
$_POST['howmuch'] = 10;
}

?>

<form action="test.php" method="post">
<table width="100%" border="0">
   
    <tr>
        <td colspan="2" align="center" bgcolor="#003300"><span class="style1">Date and Time Calculator Tester</span></td>
    </tr>
    <tr>
        <td width="45%" align="right">&nbsp;</td>
        <td width="55%">&nbsp;</td>
    </tr>
    <?php if ($_POST['Submit'] == "Calculate") { ?>
<tr>
        <td align="right" class="red"><b>Output:</b></td>
        <td width="55%" class="red"><?php echo $output;?></td>
    </tr>
    <?php } ?>
<tr>
        <td align="right">Input Date/Time: </td>
        <td><input name="input" type="text" id="input" class="biggertextbox" value="<?php echo $_POST['input'];?>"></td>
    </tr>
    <tr>
        <td align="right">Mask:</td>
        <td><input name="mask" type="text" id="mask" class="biggertextbox" value="<?php echo $_POST['mask'];?>"></td>
    </tr>
    <tr>
        <td align="right">Calculation:</td>
        <td><select name="calc" id="calc" class="biggertextbox">
        <?php if ($_POST['calc'] != "") { ?>
<option value="<?php echo $_POST['calc'];?>"><?php echo $_POST['calc'];?></option>
        <?php } ?>
<option value="Add">Add</option>
            <option value="Subtract">Subtract</option>
        </select> </td>
    </tr>
    <tr>
        <td align="right">Unit Of Time: </td>
        <td><select name="unit_of_time" id="unit_of_time" class="biggertextbox">
        <?php if ($_POST['unit_of_time'] != "") {
           
            switch (
$_POST['unit_of_time']) {
                case
"sec":
                   
$formal_unit = "Seconds";
                    break;
                case
"min":
                   
$formal_unit = "Minutes";
                    break;
                case
"hour":
                   
$formal_unit = "Hours";
                    break;
                case
"day":
                   
$formal_unit = "Days";
                    break;
                case
"week":
                   
$formal_unit = "Weeks";
                    break;
                case
"month":
                   
$formal_unit = "Months";
                    break;
                case
"year":
                   
$formal_unit = "Years";
                    break;
           
            }
           
           
?>
<option value="<?php echo $_POST['unit_of_time'];?>"><?php echo $formal_unit;?></option>
        <?php } ?>
<option value="sec">Seconds</option>
            <option value="min">Minutes</option>
            <option value="hour">Hours</option>
            <option value="day">Days</option>
            <option value="week">Weeks</option>
            <option value="month">Months</option>
            <option value="year">Years</option>
        </select>
        </td>
    </tr>
    <tr>
        <td align="right">How Much: </td>
        <td><input name="howmuch" type="text" id="howmuch" class="biggertextbox" value="<?php echo $_POST['howmuch'];?>"></td>
    </tr>
    <tr>
        <td align="right">&nbsp;</td>
        <td><input type="submit" name="Submit" value="Calculate"></td>
    </tr>
    <tr>
        <td align="right">&nbsp;</td>
        <td>&nbsp;</td>
    </tr>
</table>



<center>

<table border="0">
<tr>
<td>

    <b><span class="green">Syntax: </span></b>
    <br>
    <span class="code">
    <?php if ($_POST['Submit'] == "Calculate") {

        echo
$syntax;

    }
?>
</span>

</td>
</tr>
</table>

</center>



</form>


<br><br>





<br><br>
<center>

<TABLE width="100%" border="1" summary="The following characters are recognized in the format parameter string">
        <COLGROUP>
            <COL>
            <COL>
            <COL>
        </COLGROUP>
        <THEAD>
            <TR>
                <TH width="128" class="style17"><I>format</I> character</TH>
                <TH class="style17">Description</TH>
                <TH width="300" class="style17">Example returned values</TH>
            </TR>
        </THEAD>
        <TBODY>
           
            <TR>
                <TD align="middle" class="style24">Day</TD>
                <TD class="style17">---</TD>
                <TD class="style17">---</TD>
            </TR>
            <TR>
                <TD class="style17">d</TD>
                <TD class="style17">Day of the month, 2 digits with leading zeros</TD>
                <TD class="style17">01 to 31</TD>
            </TR>
            <TR>
                <TD class="style17">j</TD>
                <TD class="style17">Day of the month without leading zeros</TD>
                <TD class="style17">1 to 31</TD>
            </TR>
           
            <TR>
                <TD class="style17">S</TD>
                <TD class="style17">English ordinal suffix for the day of the month, 2 characters</TD>
                <TD class="style17">st, nd, rd or th. Works well with j </TD>
            </TR>
           
            <TR>
                <TD class="style17">D</TD>
                <TD class="style17">A textual representation of a day, three letters</TD>
                <TD class="style17">Mon through Sun</TD>
            </TR>
            <TR>
                <TD align="middle" class="style24">Month</TD>
                <TD class="style17">---</TD>
                <TD class="style17">---</TD>
            </TR>
           
            <TR>
                <TD class="style17">m</TD>
                <TD class="style17">Numeric representation of a month, with leading zeros</TD>
                <TD class="style17">01 through 12</TD>
            </TR>
            <TR>
                <TD class="style17">M</TD>
                <TD class="style17">A short textual representation of a month, three letters</TD>
                <TD class="style17">Jan through Dec</TD>
            </TR>
            <TR>
                <TD class="style17">n</TD>
                <TD class="style17">Numeric representation of a month, without leading zeros</TD>
                <TD class="style17">1 through 12</TD>
            </TR>
           
            <TR>
                <TD align="middle" class="style24"><EM>Year</EM></TD>
                <TD class="style17">---</TD>
                <TD class="style17">---</TD>
            </TR>
           
            <TR>
                <TD class="style17">o</TD>
                <TD class="style17">ISO-8601 year number. This has the same value as Y, except that if the ISO week number (W) belongs to the previous or next year, that year is used instead. (added in PHP 5.1.0)</TD>
                <TD class="style17">Examples: 1999 or 2003</TD>
            </TR>
            <TR>
                <TD class="style17">Y</TD>
                <TD class="style17">A full numeric representation of a year, 4 digits</TD>
                <TD class="style17">Examples: 1999 or 2003</TD>
            </TR>
            <TR>
                <TD class="style17">y</TD>
                <TD class="style17">A two digit representation of a year</TD>
                <TD class="style17">Examples: 99 or 03</TD>
            </TR>
            <TR>
                <TD align="middle" class="style24"><EM>Time</EM></TD>
                <TD class="style17">---</TD>
                <TD class="style17">---</TD>
            </TR>
            <TR>
                <TD class="style17">a</TD>
                <TD class="style17">Lowercase Ante meridiem and Post meridiem</TD>
                <TD class="style17">am or pm</TD>
            </TR>
            <TR>
                <TD class="style17">A</TD>
                <TD class="style17">Uppercase Ante meridiem and Post meridiem</TD>
                <TD class="style17">AM or PM</TD>
            </TR>
           
            <TR>
                <TD class="style17">g</TD>
                <TD class="style17">12-hour format of an hour without leading zeros</TD>
                <TD class="style17">1 through 12</TD>
            </TR>
            <TR>
                <TD class="style17">G</TD>
                <TD class="style17">24-hour format of an hour without leading zeros</TD>
                <TD class="style17">0 through 23</TD>
            </TR>
            <TR>
                <TD class="style17">h</TD>
                <TD class="style17">12-hour format of an hour with leading zeros</TD>
                <TD class="style17">01 through 12</TD>
            </TR>
            <TR>
                <TD class="style17">H</TD>
                <TD class="style17">24-hour format of an hour with leading zeros</TD>
                <TD class="style17">00 through 23</TD>
            </TR>
            <TR>
                <TD class="style17">i</TD>
                <TD class="style17">Minutes with leading zeros</TD>
                <TD class="style17">00 to 59</TD>
            </TR>
            <TR>
                <TD class="style17">s</TD>
                <TD class="style17">Seconds, with leading zeros</TD>
                <TD class="style17">00 through 59</TD>
            </TR>
        </TBODY>
</TABLE>
<br><br><br>

</center>


</body>
</html>