-
-
Save NinoSkopac/babecec7cee9308f5450 to your computer and use it in GitHub Desktop.
Dry cleaner working hours
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 | |
/***** NINO *****/ | |
function working_hours($man_id) { | |
date_default_timezone_set('America/New_York'); | |
$f = file_get_contents('/stripped.txt'); | |
$e = explode("\n\n", $f); | |
foreach($e as $block_id => $store_block) { | |
$e2 = explode("\n", $store_block); | |
list(, $block_id) = array_map('trim', explode(':', $e2[0])); | |
if ($block_id == $man_id) { | |
$today_day = date('D'); | |
// iterate thru days from that block | |
array_shift($e2); | |
foreach($e2 as $days) { | |
if (substr($days, 0, 3) == $today_day) { | |
$day_working_hours_part_e = array_map('trim', explode(':', $days)); | |
$day_working_hours_part = end($day_working_hours_part_e); | |
if ($day_working_hours_part == 'closed') { | |
return 'closed'; | |
} | |
list($open_time, $close_time) = array_map('trim', explode('-', $day_working_hours_part)); | |
$ot_str = "today $open_time"; | |
$ct_str = "today $close_time"; | |
$open_time_t = strtotime($ot_str); | |
$close_time_t = strtotime($ct_str); | |
if (time() >= $open_time_t && time() <= $close_time_t) { | |
return 'open'; | |
} else { | |
return 'closed'; | |
} | |
} | |
} | |
} | |
} | |
} | |
if (isset($manufacturer_id)) { | |
$open_or_not = working_hours($manufacturer_id); | |
} else { | |
trigger_error("manufacturer_id is not set, and the open/closed radio button/text will not execute"); | |
} | |
/***** </NINO *****/ | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment