Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions src/date_formatter.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php

function date_formatter($date_string) {

// make sure passed argument is a string
if (gettype($date_string) !== 'string') {
return '';
}

// split string into year, month, date components
$date_parse_arr = explode('-', $date_string);

// checks to make sure that exactly 3 parts split by dashes were passed
if (count($date_parse_arr) !== 3) {
return '';
}

// assign friendly variable names
$year = $date_parse_arr[0];
$month = $date_parse_arr[1];
$day = $date_parse_arr[2];

// make sure all components are numeric values
if (is_numeric($year) && is_numeric($month) && is_numeric($day)) {

// make sure components build into a valid date
if (checkdate((int)$month, (int)$day, (int)$year)) {
// combine into unix timestamp for date() function
$timestamp = mktime(0, 0, 0, $month, $day, $year);
$format = 'l, F jS Y';

return date($format, $timestamp);

} else {
return '';
}
} else {
return '';
}

}

?>