Last active
July 20, 2020 14:31
-
-
Save Driver86/89f5bb13198a7f1ed8c929e2051a2b74 to your computer and use it in GitHub Desktop.
Test
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 | |
function getWorkingDays($startDate, $endDate, $holidays) { | |
$endDate = strtotime($endDate); | |
$startDate = strtotime($startDate); | |
$days = ($endDate - $startDate) / 86400 + 1; | |
$no_full_weeks = floor($days / 7); | |
$no_remaining_days = fmod($days, 7); | |
$the_first_day_of_week = date("N", $startDate); | |
$the_last_day_of_week = date("N", $endDate); | |
if ($the_first_day_of_week <= $the_last_day_of_week) { | |
if ($the_first_day_of_week <= 6 && 6 <= $the_last_day_of_week) { | |
$no_remaining_days--; | |
} | |
if ($the_first_day_of_week <= 7 && 7 <= $the_last_day_of_week) { | |
$no_remaining_days--; | |
} | |
} else { | |
if ($the_first_day_of_week == 7) { | |
$no_remaining_days--; | |
if ($the_last_day_of_week == 6) { | |
$no_remaining_days--; | |
} | |
} else { | |
$no_remaining_days -= 2; | |
} | |
} | |
$workingDays = $no_full_weeks * 5; | |
if ($no_remaining_days > 0) { | |
$workingDays += $no_remaining_days; | |
} | |
foreach($holidays as $holiday) { | |
$time_stamp=strtotime($holiday); | |
if ($startDate <= $time_stamp && $time_stamp <= $endDate && date("N",$time_stamp) != 6 && date("N",$time_stamp) != 7) { | |
$workingDays--; | |
} | |
} | |
return $workingDays; | |
} | |
$answers = $mysql->query('SELECT * FROM answers WHERE DATEDIFF(FROM_UNIXTIME(NOW()), last_answer_time ) > 2'); | |
$answers = array_filter($answers, function ($answer) { | |
return getWorkingDays(date('r', $answer->last_answer_time), date('r'), [date('Y') . '-01-07', '...']) > 2; | |
}); |
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 | |
// Tech stack: | |
// Workerman for websocket | |
// Yii2 for queue (and more...) | |
use Workerman\Worker; | |
require_once __DIR__ . '/vendor/autoload.php'; | |
$ws_worker = new Worker('websocket://0.0.0.0:2346'); | |
$ws_worker->onConnect = function ($connection) { | |
echo "New connection\n"; | |
}; | |
$ws_worker->onMessage = function ($connection, $data) { | |
Yii::$app->queue->delay(60)->push(new SaveIntoDb($data)); | |
}; | |
$ws_worker->onClose = function ($connection) { | |
echo "Connection closed\n"; | |
}; | |
Worker::runAll(); |
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 | |
if (preg_match('/\[SPOILER=".*?"\]/', $text)) { | |
if (strpos($text, '[/SPOILER]') === false) { | |
$text .= '[/SPOILER]'; | |
} | |
$text = preg_replace_callback('/(\[SPOILER=".*?"\])(.*)(\[\/SPOILER\])/', function ($math) { | |
return $match[1] . preg_replace('/\[SPOILER=".*?"\]|\[\/SPOILER\]/', '', $match[2]) . $match[3]; | |
}, $text); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment