Created
October 28, 2016 17:39
-
-
Save calebporzio/b8d180bb428d633abae0a4edf1b3e9a7 to your computer and use it in GitHub Desktop.
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
<?php | |
// Refactor the following functions using your new skills from 99-bottles. | |
// Sorry about the lack of tests - bonus points if you write tests to get started. | |
function getStartDate() { | |
return preg_match("/^\d\d\d\d-\d\d-\d\d$/", $_GET['dStartDate']) ? $_GET['dStartDate'] : date("Y-m-d", time() - 60 * 60 * 24 * 7); | |
} | |
function getEndDate() { | |
return preg_match("/^\d\d\d\d-\d\d-\d\d$/", $_GET['dEndDate']) ? $_GET['dEndDate'] : date("Y-m-d"); | |
} | |
// The code started as the following variables, but in the spirit of creating | |
// testable seams I converted the variables to function calls. | |
$dStartDate = preg_match("/^\d\d\d\d-\d\d-\d\d$/", $_GET['dStartDate']) ? $_GET['dStartDate'] : date("Y-m-d", time() - 60 * 60 * 24 * 7); | |
$dEndDate = preg_match("/^\d\d\d\d-\d\d-\d\d$/", $_GET['dEndDate']) ? $_GET['dEndDate'] : date("Y-m-d"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment