This repository has been archived on 2025-02-01. You can view files and clone it, but cannot push or open issues or pull requests.
accm-website/includes/utils/DateParser.inc.php
2010-08-14 22:32:09 +02:00

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);
}
}
?>