PHP Classes
elePHPant
Icontem

File: example.php

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of Michiel de Roo  >  DateUtil  >  example.php  >  Download  
File: example.php
Role: Example script
Content type: text/plain
Description: examples
Class: DateUtil
Parsing, missing values, internationalization, etc
Author: By
Last change: updated example
Date: 11 years ago
Size: 4,466 bytes
 

Contents

Class file image Download
<?
/*
error_reporting(ERROR | FATAL);
@include('log4php/LoggerManager.php');
if(class_exists('LoggerManager')) {
    # clear the log file
    $fp = fopen('/web/lib_dev/log.log', 'w');
    # get the debug logger
    $debug =& LoggerManager::getLogger('debug');
    set_error_handler('debug_log');
    $DEBUG_LEVEL = E_ERROR;
}
function debug_log($errno, $errstr, $errfile, $errline) {
    GLOBAL $debug, $DEBUG_LEVEL;
    if(isset($DEBUG_LEVEL)) if($errno>=$DEBUG_LEVEL && $errno<E_USER_ERROR) return;
    if($debug) $debug->debug(basename($errfile).":".$errline."(".$errno.")"." -> ".$errstr);
}
*/

include("DateUtil.php");
/** General
All setXX() functions return the result of the execute() function of your subclass;
*/

/** Example */
$du = new InternationalDate(); //always initialize one of the subclasses
//return current result

?>

<b>Test the date parsing algorithm</b><br>
<form>
<input name="test_date" size="16" type="text" value="<?=$test_date?>">
<input type="submit" value="test">
<?
if(isset($test_date)) echo "Converted to (Y-m-d H:i): " . $du->setDate($test_date, "Y-m-d H:i");
echo
"<br>";echo "<br>";

$du->setDate();
echo
"<b>Setting and parsing dates</b>"; echo "<br>";
echo
'$du->setFormat("Y-m-d"): '; echo $du->setFormat("Y-m-d"); echo "<br>";
echo
'$du->setDate("3 10 04"): '.$du->setDate("3 10 04"); echo "<br>";
echo
'$du->setDate("4.11.2009"): '.$du->setDate("4.11.2009"); echo "<br>";
echo
'$du->setDate("12.21.06"): '.$du->setDate("12.21.06"); echo "<br>";

echo
"<br>";
echo
"<b>Working with missing data</b>"; echo "<br>";
echo
'$du->setFormat("Y-m-d H:i:s")'; $du->setFormat("l Y-m-d H:i:s"); echo "<br>";
echo
'$du->setDate("22-01-07 12:01:32"): '.$du->setDate("22-01-07 12:01:32"); echo "<br>";
echo
'$du->setDate("22-01-07 12:??"): '.$du->setDate("22-01-07 12:??"); echo "<br>";
echo
'$du->setDate("22-??-07 ??:01:32"): '.$du->setDate("22-??-2007 ??:01:32"); echo "<br>";
echo
'$du->setDate("??-??-2007 12:??:??"): '.$du->setDate("??-??-2007 12:??:??"); echo "<br>";
echo
"<br>";

$du->setDate("now");
echo
"<b>Changing format</b>"; echo "<br>";
echo
'$du->setFormat("l Y-m-d H:i"): '.$du->setFormat("l Y-m-d H:i"); echo "<br>";
echo
'$du->setFormat("l d F Y H:i"): '.$du->setFormat("l d F Y H:i"); echo "<br>";
echo
"<br>";

echo
"<b>Changing language</b>"; echo "<br>";
echo
"<table cellpadding=0 cellspacing=0 border=0>";

echo
"<tr><td>English: </td><td>"; echo $du->setLanguage("en"); echo "</td></tr>";
echo
"<tr><td>Spanish: </td><td>"; echo $du->setLanguage("es"); echo "</td></tr>";
echo
"<tr><td>Italian: </td><td>"; echo $du->setLanguage("it"); echo "</td></tr>";
echo
"<tr><td>French: </td><td>"; echo $du->setLanguage("fr"); echo "</td></tr>";
echo
"<tr><td>Dutch: </td><td>"; echo $du->setLanguage("nl"); echo "</td></tr>";
echo
"<tr><td>German: </td><td>"; echo $du->setLanguage("de"); echo "</td></tr>";
echo
"<tr><td>Danish: </td><td>"; echo $du->setLanguage("da"); echo "</td></tr>";
echo
"<tr><td>Finnish: </td><td>"; echo $du->setLanguage("fi"); echo "</td></tr>";
echo
"<tr><td>Czech: </td><td>"; echo $du->setLanguage("cz"); echo "</td></tr>";
echo
"<tr><td>Polish: </td><td>"; echo $du->setLanguage("pl"); echo "</td></tr>";
echo
"<tr><td>Greek: </td><td>"; echo $du->setLanguage("el"); echo "</td></tr>";
echo
"<tr><td>Russian: </td><td>"; echo $du->setLanguage("ru"); echo "</td></tr>";

echo
"<tr><td>Argentinian: </td><td>";echo $du->setLanguage("ar"); echo "</td></tr>";
echo
"<tr><td>Brazilian: </td><td>"; echo $du->setLanguage("br"); echo "</td></tr>";
echo
"<tr><td>Japanese: </td><td>"; echo $du->setLanguage("jp"); echo "</td></tr>";
echo
"<tr><td>Indonesian: </td><td>"; echo $du->setLanguage("id"); echo "</td></tr>";
echo
"</table>";
echo
"<br>";

echo
"<b>Calculating with dates</b>";
$du->setFormat("l d F Y"); $du->setLanguage("en"); $du->setDate();
echo
'<br>Add 3 days:<br>$du->add(3, "day");'.$du->add(3, "day"); echo "<br>"; $du->setDate();
echo
'<br>Subtract 100 weeks:<br>$du->subtract(100, "week");'.$du->subtract(100, "week"); echo "<br>"; $du->setDate();
echo
'<br>Yesterday:<br>$du->setDate("yesterday");'.$du->setDate("yesterday"); echo "<br>";
echo
'<br>Tomorrow:<br>$du->setDate("tomorrow");'.$du->setDate("tomorrow"); echo "<br>";
echo
'<br>Last week:<br>$du->setDate("last week");'.$du->setDate("last week"); echo "<br>";
echo
'<br>Next month:<br>$du->setDate("next month");'.$du->setDate("next month"); echo "<br>";

echo
"<br>"; echo "<br>";

?>