/**
* get tomorrow's date in the format requested, default to Y-m-d for MySQL (e.g. 2013-01-04)
*
* @param string
*
* @return string
*/
public static function getTomorrowsDate($format = 'Y-m-d')
{
$date = new DateTime();
$date->add(DateInterval::createFromDateString('tomorrow'));
return $date->format($format);
}
First, coming up with correct abstractions is always a key. key to readability, maintainability, and extendability.
Here, quite obvious candidate is an ISO8601DateTime. There are at least two implementations: first one is a parsed datetime from a string, and the second one is tomorrow. Hence, there are two classes that can be used, and their combination results in (almost) desired outcome:
new Tomorrow(new FromISO8601('2013-01-22'));
Both objects are an ISO8601 datetime, so their textual representation is not exactly what you need. So the final stroke is to make them take a date-form:
new Date(
new Tomorrow(
new FromISO8601('2013-01-22')
)
);
Since you need a textual representation, not just an object, you invoke a value() method.
For more about this approach, take a look at this post.