36 lines
918 B
PHP
36 lines
918 B
PHP
<?php
|
|
|
|
include_once './includes/exceptions/BadFormatException.inc.php';
|
|
|
|
/**
|
|
* This class is responsible for parsing the different date format entered.
|
|
*
|
|
* @author Thomas Schwery <thomas.schwery@epfl.ch>
|
|
*/
|
|
class DateParser {
|
|
|
|
/**
|
|
* Parses a date entered in the "Day / Month / Year" format
|
|
*
|
|
* @param string $humanDate a date
|
|
* @return int the timestamp corresponding to the given date
|
|
*
|
|
* @throws BadFormatException if the given date is not well formed.
|
|
*/
|
|
public static function parseDMY($humanDate) {
|
|
$dateArray = explode(" / ", $humanDate);
|
|
|
|
if ((!$dateArray) || (count($dateArray) != 3)) {
|
|
throw new BadFormatException();
|
|
}
|
|
|
|
$time = mktime(0,0,0,$dateArray[1], $dateArray[0], $dateArray[2]);
|
|
|
|
return $time;
|
|
}
|
|
|
|
public static function parseSQL($sqlDate) {
|
|
return strtotime($sqlDate);
|
|
}
|
|
}
|
|
?>
|