add support for 2 digit years, fixes FS#53

This commit is contained in:
John Bintz 2009-10-27 07:03:22 -04:00
parent b352efe93c
commit 1a83597ba5
2 changed files with 13 additions and 10 deletions

View File

@ -176,20 +176,22 @@ function cpm_breakdown_comic_filename($filename, $allow_override = false) {
if (isset($_POST['upload-date-format']) && !empty($_POST['upload-date-format'])) { $pattern = $_POST['upload-date-format']; }
}
$pattern = cpm_transform_date_string($pattern, array("Y" => '[0-9]{4,4}',
"m" => '[0-9]{2,2}',
"d" => '[0-9]{2,2}'));
foreach (array('[0-9]{4}', '[0-9]{2}') as $year_pattern) {
$new_pattern = cpm_transform_date_string($pattern, array("Y" => $year_pattern,
"m" => '[0-9]{2}',
"d" => '[0-9]{2}'));
if (@preg_match("#^(${pattern})(.*)\.[^\.]+$#", $filename, $matches) > 0) {
if (@preg_match("#^(${new_pattern})(.*)\.[^\.]+$#", $filename, $matches) > 0) {
list($all, $date, $title) = $matches;
if (strtotime($date) === false) { return false; }
$converted_title = ucwords(trim(preg_replace('/[\-\_]/', ' ', $title)));
$date = date($pattern, strtotime($date));
return compact('date', 'title', 'converted_title');
} else {
return false;
}
}
return false;
}
/**

View File

@ -55,6 +55,7 @@ class TestComicPressManagerLibrary extends UnitTestCase {
array("${test_date}-Test.jpg", array("title" => "-Test", "date" => $test_date, "converted_title" => "Test")),
array("${test_date}-test.jpg", array("title" => "-test", "date" => $test_date, "converted_title" => "Test")),
array("1900-01-01.jpg", false),
array("08-01-01.jpg", array("title" => "", "date" => $test_date, "converted_title" => "")),
) as $test) {
list($filename, $expected_value) = $test;
$this->assertEqual($expected_value, cpm_breakdown_comic_filename($filename, true));