Check start/end/days of week in cron and active/deactivate flights accordingly

This commit is contained in:
Nabeel Shahzad
2018-04-12 16:12:32 -05:00
parent 395642f69c
commit 9d3d284df7
6 changed files with 224 additions and 6 deletions

View File

@@ -39,6 +39,19 @@ class Days extends Enum
'Su' => Days::SUNDAY,
];
/**
* Map the ISO8601 numeric today to day
*/
public static $isoDayMap = [
1 => Days::MONDAY,
2 => Days::TUESDAY,
3 => Days::WEDNESDAY,
4 => Days::THURSDAY,
5 => Days::FRIDAY,
6 => Days::SATURDAY,
7 => Days::SUNDAY,
];
/**
* Create the masked value for the days of week
* @param array $days
@@ -64,4 +77,14 @@ class Days extends Enum
{
return ($mask & $day) === $day;
}
/**
* Does the mask contain today?
* @param $val
* @return bool
*/
public static function isToday($val): bool
{
return static::in($val, static::$isoDayMap[(int) date('N')]);
}
}

View File

@@ -6,6 +6,7 @@ use App\Interfaces\Model;
use App\Models\Enums\Days;
use App\Models\Traits\HashIdTrait;
use App\Support\Units\Distance;
use Carbon\Carbon;
use Illuminate\Support\Collection;
use PhpUnitsOfMeasure\Exception\NonNumericValue;
use PhpUnitsOfMeasure\Exception\NonStringUnitName;
@@ -26,6 +27,9 @@ use PhpUnitsOfMeasure\Exception\NonStringUnitName;
* @property string dpt_airport_id
* @property string arr_airport_id
* @property string alt_airport_id
* @property int active
* @property Carbon start_date
* @property Carbon end_date
*/
class Flight extends Model
{
@@ -178,6 +182,20 @@ class Flight extends Model
return '';
}
/**
* Set the days parameter. If an array is passed, it's
* AND'd together to create the mask value
* @param array|int $val
*/
public function setDaysAttribute($val): void
{
if (\is_array($val)) {
$val = Days::getDaysMask($val);
}
$this->attributes['days'] = $val;
}
/**
* Relationship
*/