HEX
Server: LiteSpeed
System: Linux houston.panomity.com 6.8.0-100-generic #100-Ubuntu SMP PREEMPT_DYNAMIC Tue Jan 13 16:40:06 UTC 2026 x86_64
User: nudepix (1011)
PHP: 7.4.33
Disabled: pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare,
Upload Files
File: /home/timetracker.panomity.com/src/Timesheet/TrackingMode/AbstractTrackingMode.php
<?php

/*
 * This file is part of the Kimai time-tracking app.
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace App\Timesheet\TrackingMode;

use App\Entity\Timesheet;
use DateTime;
use Symfony\Component\HttpFoundation\Request;

abstract class AbstractTrackingMode implements TrackingModeInterface
{
    use TrackingModeTrait;

    public function create(Timesheet $timesheet, ?Request $request = null): void
    {
        if (null === $request) {
            return;
        }

        $this->setBeginEndFromRequest($timesheet, $request);
        $this->setFromToFromRequest($timesheet, $request);
    }

    protected function setBeginEndFromRequest(Timesheet $entry, Request $request)
    {
        $start = $request->get('begin');
        if (null === $start) {
            return;
        }

        $start = DateTime::createFromFormat('Y-m-d', $start, $this->getTimezone($entry));
        if (false === $start) {
            return;
        }

        $entry->setBegin($start);

        // only check for an end date if a begin date was given
        $end = $request->get('end');
        if (null === $end) {
            return;
        }

        $end = DateTime::createFromFormat('Y-m-d', $end, $this->getTimezone($entry));
        if (false === $end) {
            return;
        }

        $start->setTime(10, 0, 0);
        $end->setTime(18, 0, 0);

        $entry->setEnd($end);
        $entry->setDuration($end->getTimestamp() - $start->getTimestamp());
    }

    protected function setFromToFromRequest(Timesheet $entry, Request $request)
    {
        $from = $request->get('from');
        if (null === $from) {
            return;
        }

        try {
            $from = new DateTime($from, $this->getTimezone($entry));
        } catch (\Exception $ex) {
            return;
        }

        $entry->setBegin($from);

        $to = $request->get('to');
        if (null === $to) {
            return;
        }

        try {
            $to = new DateTime($to, $this->getTimezone($entry));
        } catch (\Exception $ex) {
            return;
        }

        $entry->setEnd($to);
        $entry->setDuration($to->getTimestamp() - $from->getTimestamp());
    }
}