New answers tagged

5

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 $...


4

The function seems okay. In Javascript one could use the method Array.every(), but as this StackOverflow question illustrates there isn't really an equivalent method or functional approach in PHP that will stop the loop as soon as one element does not meet the requirement. You might consider adhering to the PSR PHP Coding standards - especially PSR 12. PSR-...


1

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: This loop: for word in words: in_day = [weekday for weekday in weekdays ...


0

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 ...


0

Why reinvent the wheel? Why not use Get-Date cmdlet, and simplify the code? $StartDate = Get-Date -Day 13 -Month 1 -Year 2019 $EndDate = Get-Date -Day 13 -Month 12 -Year 2020 $IntStartDate = $StartDate.TofileTime() $IntEndDate = $EndDate.TofileTime() do { if ($StartDate.DayOfWeek -eq 'Friday') { Write-Host ($StartDate.tostring("dd-MMMM-yyyy&...


Top 50 recent answers are included