To me it looks fine, other than it makes me scroll the code to read it. On this ground I agree with Sam, that line ought to be shortened. To do so I would
use the fact that you don't need to convert mysql format dates to compare them
remove excessive bracing
use De Morgan's law to invert the condition
and get this
function dates_in_range( string $...
You might consider adhering to the PSR PHP Coding standards - especially PSR 12.
in_day = [weekday for weekday in weekdays if word in weekday]
if len(in_day) == 1:
seems odd. You make the entire list, put it in memory, take its length and then throw it away. Consider instead
n_matching = sum(1 for weekday in weekdays if word in weekday)
if n_matching == 1:
for word in words:
in_day = [weekday for weekday in weekdays ...
I don't see the need to do so much dynamic work. I would establish a lookup array to access. This will be clean, direct, and easy to maintain. If the incoming format is not found, just fallback to m-d-Y using the null coalescing operator.
private $formatLookup = [
'YYYY-MM-DD' => 'Y-m-d',
'YYYY/MM/DD' => 'Y/m/d',
public function ...