Skip to content

Allowing creation of timesheet records with begin and end time - #26

Open
vworldat wants to merge 1 commit into
kimai:masterfrom
vworldat:enhancement/record-start-and-end-time
Open

vworldat wants to merge 1 commit into
kimai:masterfrom
vworldat:enhancement/record-start-and-end-time

Conversation

@vworldat

@vworldat vworldat commented Jan 5, 2026

Copy link
Copy Markdown

I added --begin/-b and --end/-e options to the kimai start command. This would resolve both #7 as well as parts of #8 (no --end option for kimai stop yet).

Had to add a phpstan baseline to ignore errors caused by kimai/api-php declaring nullable getters as non-nullable.

@kevinpapst kevinpapst left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did not test it, but look good to me.

Thanks @vworldat 👍

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds support for creating timesheet records with explicit begin/end timestamps via the kimai start command, enabling scripted/bulk inserts and “forgot to start/stop” workflows discussed in #7 and parts of #8.

Changes:

  • Added --begin/-b and --end/-e options to kimai start, with interactive refinement for invalid date inputs.
  • Updated CLI output to include an optional End timestamp.
  • Added PHPStan baseline configuration to suppress a nullsafe-call finding originating from upstream API typings.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
src/Command/TimesheetCommandTrait.php Adds a helper for parsing DateTime values (currently implemented recursively).
src/Command/StartCommand.php Introduces --begin/--end options, parses them into the form, and prints End in output.
README.md Documents new --begin/--end options with examples and refinement prompt behavior.
phpstan.neon Includes the baseline file in PHPStan configuration.
phpstan-baseline.neon Suppresses a specific PHPStan nullsafe-call rule for StartCommand.php.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 26 to 29
->setName('start')
->setDescription('Starts a new timesheet')
->setHelp('This command lets you start a new timesheet')
->setHelp('This command lets you start a new timesheet and optionally end it immediately.')
->addOption('customer', 'c', InputOption::VALUE_OPTIONAL, 'The customer to filter the project list, can be an ID or a search term or empty (you will be prompted for a customer).')
Comment on lines +325 to +340
/**
* Try to convert the given string into a DateTime object and recursively ask for clarification if necessary.
*/
private function parseAndRefineDateTime(SymfonyStyle $io, string $begin, string $valueName): \DateTime
{
try {
return new \DateTime($begin);
} catch (\Exception $e) {
}

return $this->parseAndRefineDateTime(
$io,
$io->ask(\sprintf('Value "%s" for field "%s" is not a valid DateTime. Please refine:', $begin, $valueName), $begin),
$valueName,
);
}
@parthitce

Copy link
Copy Markdown

Thanks for this PR and it works. one fix is needed to make it to use the timezone setup of the machine instead of always UTC.

commit 9333efd642b9f72ff5a517eec3e48a4f608fcfe0 (HEAD -> build-2.0.0-pr26)
Author: Parthiban Nallathambi <parthiban@linumiz.com>
Date:   Sat Sep 19 20:00:49 2026 +0530

    Fix: interpret --begin/--end in the configured PHP timezone
    
    new DateTime($value) assumed the PHP process timezone implicitly,
    so backdated entries shifted by the UTC offset. Pass the value with
    date_default_timezone_get() so times match the configured zone.
    
    Signed-off-by: Parthiban Nallathambi <parthiban@linumiz.com>

diff --git a/src/Command/TimesheetCommandTrait.php b/src/Command/TimesheetCommandTrait.php
index 5ab15fc..fb315a8 100644
--- a/src/Command/TimesheetCommandTrait.php
+++ b/src/Command/TimesheetCommandTrait.php
@@ -328,7 +328,7 @@ trait TimesheetCommandTrait
     private function parseAndRefineDateTime(SymfonyStyle $io, string $begin, string $valueName): \DateTime
     {
         try {
-            return new \DateTime($begin);
+            return new \DateTime($begin, new \DateTimeZone(date_default_timezone_get()));
         } catch (\Exception $e) {
         }

It would be great if this PR can be merged.

@kevinpapst kevinpapst added the enhancement New feature or request label Sep 19, 2026
@kevinpapst

Copy link
Copy Markdown
Member

@parthitce do you want to take over and send an updated PR?

@parthitce

Copy link
Copy Markdown

@parthitce do you want to take over and send an updated PR?

Yeah sure. I will retain the original author and add the fix. may be additional signed-off. does that work?

@kevinpapst

Copy link
Copy Markdown
Member

Did you check what happens if the current timezone is different from the API users timezone?
Shall we add an option to pass an explicit timezone?

@parthitce

Copy link
Copy Markdown

Did you check what happens if the current timezone is different from the API users timezone? Shall we add an option to pass an explicit timezone?

Addressed with #36 , IMO this PR can be closed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants