Skip to content

Instantly share code, notes, and snippets.

@calebporzio
Created October 28, 2016 17:39
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save calebporzio/b8d180bb428d633abae0a4edf1b3e9a7 to your computer and use it in GitHub Desktop.
Save calebporzio/b8d180bb428d633abae0a4edf1b3e9a7 to your computer and use it in GitHub Desktop.
<?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