<?php
/*
* Free IT Foundation
* Free Technology Serving Knowledge
* http://www.free-it-foundation.org
*
* This file is part of Knowledge Box.
*
* Knowledge Box is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Knowledge Box is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Knowledge Box. If not, see <http://www.gnu.org/licenses/>.
*/
/*
* formatDateAsInConfig ()
*/
function formatDateAsInConfig ($day, $month, $year, $format, $separator)
{
$format = $format->getStringValue ();
$separator = $separator->getStringValue ();
// day
$format = str_replace ('dd', (string) $day, $format);
$format = str_replace ('d', (int) $day, $format);
// month
$format = str_replace ('mm', (string) $month, $format);
$format = str_replace ('m', (int) $month, $format);
// year
$format = str_replace ('yyyy', (int) $year, $format);
$format = str_replace ('yy', substr ((string) $year, -2), $format);
// separator
$format = str_replace ('.', $separator, $format);
// return
return $format;
}
/*
* unformatDateAsInConfig ()
*/
function unformatDateAsInConfig ($date, $format, $separator)
{
$format = $format->getStringValue ();
$separator = $separator->getStringValue ();
// parts
$parts = explode ($separator, $date);
// format
$format = explode ('.', $format);
// position of information
foreach ($format as $pos => $value)
{
// day
if (substr ($value, 0, 1) == 'd')
$day = $parts [$pos];
// month
elseif (substr ($value, 0, 1) == 'm')
$month = $parts [$pos];
// year
elseif (substr ($value, 0, 1) == 'y')
$year = $parts [$pos];
}
// format
if ((int) $day < 10)
$day = '0' . (int) $day;
if ((int) $month < 10)
$month = '0' . (int) $month;
if ((int) $year < 10)
$year = '0' . (int) $year;
if ((int) $year >= 50 && (int) $year <= 99)
$year = '19' . $year;
elseif ((int) $year >= 0 && (int) $year < 50)
$year = '20' . $year;
// return
return (string) $year . (string) $month . (string) $day;
}
?>