Created
November 13, 2011 11:17
-
-
Save ptz0n/1361995 to your computer and use it in GitHub Desktop.
YN string to dates
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* YN string to dates | |
* | |
* @param string $from | |
* @param string $to | |
* @param string $yn | |
* | |
* @return array $dates | |
*/ | |
function ynToDates($from, $to, $yn) | |
{ | |
$from = strtotime($from); | |
$to = strtotime($to); | |
$days = (int)round(($to - $from) / 86400) + 1; | |
// Validate YN string length to date range | |
if($days != strlen($yn)) { | |
return false; | |
} | |
else { | |
$yn = strrev($yn); | |
$dates = array(); | |
while($days) { | |
if($yn[$days-1] == 'Y') { | |
$dates[] = date('c', $to - ($days-1)*86400); | |
} | |
$days--; | |
} | |
return $dates; | |
} | |
} | |
var_dump(ynToDates('2011-12-11', '2012-12-08', 'NNNNNNNNYYYYYNNNYYYYNNYYYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNNNNNNNNYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYYYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN')); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Output: