Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Walter Felipe
pad-upe
Commits
a55abd49
Commit
a55abd49
authored
Apr 25, 2024
by
alissonalbuquerque
Browse files
Add implementações parciais de resolução de problema de calculo de reservas
parent
4d7dbd63
Changes
2
Hide whitespace changes
Inline
Side-by-side
app/Models/TaskTime.php
View file @
a55abd49
...
...
@@ -464,21 +464,54 @@ class TaskTime extends Model
* @param $floatValue
* @return string|time
*/
public
static
function
convertFloatToHour
(
$floatValue
)
{
public
static
function
float_to_date_interval
(
$float_value
)
{
// Calcula as horas
$horas
=
floor
(
$float_value
);
// Calcula os minutos
$minutos_decimal
=
(
$float_value
-
$horas
)
*
60
;
$minutos
=
floor
(
$minutos_decimal
);
$percent
=
$floatValue
*
100.0
;
// float to percent
$
one_percent_from_hour
=
0.6
;
// 0.6 min
// Calcula os segundos
$
segundos
=
round
((
$minutos_decimal
-
$minutos
)
*
60
);
$minutes
=
$one_percent_from_hour
*
$percent
;
// minutes
/** @var DateInterval */
$date_interval
=
new
DateInterval
(
"PT
{
$horas
}
H
{
$minutos
}
M
{
$segundos
}
S"
);
return
$date_interval
;
}
/**
* @param $floatValue
* @return string|time
*/
public
static
function
convertFloatToHour
(
$float_value
)
{
// Calcula as horas
$horas
=
floor
(
$float_value
);
// Calcula os minutos
$minutos_decimal
=
(
$float_value
-
$horas
)
*
60
;
$minutos
=
floor
(
$minutos_decimal
);
// Calcula os segundos
$segundos
=
round
((
$minutos_decimal
-
$minutos
)
*
60
);
/
/ Criar um objeto DateTime com um intervalo de minutos
$interval
=
new
DateInterval
(
'
PT
'
.
$minutes
.
'M'
);
/
** @var DateInterval */
$
date_
interval
=
new
DateInterval
(
"
PT
{
$horas
}
H
{
$minutos
}
M
{
$segundos
}
S"
);
// Criar um objeto DateTime base com 0 horas e 0 minutos
$dateTime
=
new
DateTime
(
'00:00'
);
$dateTime
->
add
(
$interval
);
// Popular com Interval
return
$date_interval
;
// /** @var DateTime */
// $date_time = new DateTime('00:00');
// $date_time->add($date_interval);
return
$dateTime
->
format
(
'H:i:s'
);
// dd(
// $date_time->format('H:i:s')
// );
// return $date_time->format('H:i:s');
}
/**
...
...
@@ -521,6 +554,30 @@ class TaskTime extends Model
return
$sumDateTime
;
}
/**
* @param $taskTimes
* @return DateTime
*/
public
static
function
sum_interval_times
(
Collection
$task_times
)
{
[
$total_hours
,
$total_minutes
]
=
[
0
,
0
];
foreach
(
$task_times
as
$task_time
)
{
$date_time_start
=
new
DateTime
(
$task_time
->
start_time
);
$date_time_end
=
new
DateTime
(
$task_time
->
end_time
);
/** @return DateInternal|null */
$diff
=
$date_time_end
->
diff
(
$date_time_start
);
$total_hours
=
$total_hours
+
$diff
->
h
;
$total_minutes
=
$total_minutes
+
$diff
->
m
;
}
$date_interval
=
new
DateInterval
(
"PT
{
$total_hours
}
H
{
$total_minutes
}
M"
);
return
$date_interval
;
}
/**
* @param DateTime $dateTimeX
* @param DateTime $dateTimeY
...
...
app/Rules/ValidationLimitTime.php
View file @
a55abd49
...
...
@@ -3,6 +3,7 @@
namespace
App\Rules
;
use
App\Models\TaskTime
;
use
DateInterval
;
use
DateTime
;
use
Illuminate\Contracts\Validation\Rule
;
use
Illuminate\Database\Eloquent\Collection
;
...
...
@@ -42,6 +43,9 @@ class ValidationLimitTime implements Rule
/** @var Collection */
protected
$taskTimes
;
/** @var DateInterval */
protected
$limit_date_interval
;
/**
* Create a new rule instance.
*
...
...
@@ -62,13 +66,38 @@ class ValidationLimitTime implements Rule
$this
->
task
=
TaskTime
::
tarefaByStatic
(
$this
->
type
,
$this
->
tarefa_id
);
$this
->
limit_hours
=
TaskTime
::
convertFloatToHour
(
$this
->
task
->
ch_semanal
);
$this
->
limit_date_interval
=
TaskTime
::
float_to_date_interval
(
$this
->
task
->
ch_semanal
);
$this
->
limit_hours
=
TaskTime
::
convertFloatToHour
(
$this
->
task
->
ch_semanal
);
// deprected
$this
->
taskTimes
=
$this
->
getTaskTimes
();
$this
->
taskTime
=
$this
->
createTaskTime
();
}
/**
* Determine if the validation rule passes.
*
* @param string $attribute
* @param mixed $value
* @return bool
*/
// public function passes($attribute, $value)
// {
// $limitDateTime = new DateTime($this->limit_hours);
// $sumDateTime = TaskTime::sumIntervalTimes($this->taskTimes);
// $newDateTime = new DateTime($this->taskTime->intervalTime());
// $totalDateTime = TaskTime::sumDateTimes($sumDateTime, $newDateTime);
// dd($totalDateTime);
// $this->outLineTime = $totalDateTime->diff($limitDateTime);
// return $limitDateTime >= $totalDateTime;
// }
/**
* Determine if the validation rule passes.
*
...
...
@@ -78,16 +107,29 @@ class ValidationLimitTime implements Rule
*/
public
function
passes
(
$attribute
,
$value
)
{
$limitDateTime
=
new
DateTime
(
$this
->
limit_hours
);
$sumDateTime
=
TaskTime
::
sumIntervalTimes
(
$this
->
taskTimes
);
$date_time_start
=
new
DateTime
(
$this
->
taskTime
->
start_time
);
$date_time_end
=
new
DateTime
(
$this
->
taskTime
->
end_time
);
/** @return DateInternal|null */
$diff
=
$date_time_end
->
diff
(
$date_time_start
);
[
$hours
,
$minutes
]
=
[
$diff
->
h
,
$diff
->
m
];
$new_model_date_interval
=
new
DateInterval
(
"PT
{
$hours
}
H
{
$minutes
}
M"
);
//--------------------------------------------------------------
$limit_date_interval
=
$this
->
limit_date_interval
;
$date_interval
=
TaskTime
::
sum_interval_times
(
$this
->
taskTimes
);
$newDateTime
=
new
DateTime
(
$this
->
taskTime
->
interval
Time
()
);
// $date_interval->add($new_date_
interval);
$totalDateTime
=
TaskTime
::
sumDateTimes
(
$sumDateTime
,
$newDateTime
);
//
$totalDateTime = TaskTime::sumDateTimes($sumDateTime, $newDateTime);
$this
->
outLineTime
=
$totalDateTime
->
diff
(
$limitDateTime
);
//
$this->outLineTime = $totalDateTime->diff($limitDateTime);
return
$limitDateTime
>=
$totalDateTime
;
//
return $limitDateTime >= $totalDateTime;
}
/**
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment