Skip to content

Add --begin/--end and --timezone to start - #36

Open
parthitce wants to merge 1 commit into
kimai:masterfrom
linumiz:dev/add-begin-end-tz
Open

parthitce wants to merge 1 commit into
kimai:masterfrom
linumiz:dev/add-begin-end-tz

Conversation

@parthitce

Copy link
Copy Markdown

Allow creating timesheet records with explicit begin/end times, and a -z/--timezone to name the IANA zone used to read them (falls back to the PHP default). Invalid zone fails cleanly without entering the refine prompt.

Co-authored-by: webemerge office@web-emerge.com
Signed-off-by: webemerge office@web-emerge.com
Signed-off-by: Parthiban Nallathambi parthiban@linumiz.com

Comment thread src/Command/TimesheetCommandTrait.php Resolved
@parthitce

Copy link
Copy Markdown
Author

@kevinpapst Please revisit and thanks

@kevinpapst
kevinpapst self-requested a review September 22, 2026 18:57

@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.

Thanks for owning the PR and taking over!

Comment thread src/Command/StartCommand.php Outdated
$form->setDescription($description);
}

$timezone = $input->getOption('timezone');

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.

Timezone: is only validated if either begin or end are passed. always execute the resolveTimezone() - otherwise the user won't recognize some broken value (e.g. --timezone=foo would be silently ignored currently).

Add a try & catch and show an error + Command::FAILURE if parsing fails

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Done. The timezone is now always validated, and an invalid one fails with an error and Command::FAILURE.

Comment thread src/Command/TimesheetCommandTrait.php Outdated
return null;
}

private function parseAndRefineDateTime(string $value, string $valueName, ?string $timezone = null): \DateTime

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.

parseAndRefineDateTime() should be renamed to parseDateTime()

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Renamed to parseDateTime

Comment thread src/Command/StartCommand.php Outdated

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.

The message still says "Started timesheet" when the record is already ended.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Fixed. It now says "Created timesheet" when an end is set.

Comment thread src/Command/StartCommand.php Outdated
Comment on lines +96 to +99
if (null !== ($end = $input->getOption('end'))) {
$end = $this->parseAndRefineDateTime((string) $end, 'end', $timezone);
$form->setEnd($end);
}

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.

two issues:

  • end could be before begin: this is validated in Kimai, but we should catch it early here
  • end could be passed without begin, which shouldn't be possible

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Both are now rejected before any API call: --end requires --begin, and end must not be earlier than begin.

@parthitce
parthitce force-pushed the dev/add-begin-end-tz branch from 6c99e23 to 91943c7 Compare October 20, 2026 16:19
@parthitce

Copy link
Copy Markdown
Author

Thanks for owning the PR and taking over!

Also fixed a phpstan level-7 error: the getEnd()?-> nullsafe call is now an explicit null check. Please revisit.

@parthitce

Copy link
Copy Markdown
Author

@kevinpapst ping. Let me know if any further changes required. Thanks.

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.

🟡 Changes recommended

A moderate active issue remains because optional-value parsing lets missing arguments be silently treated as omitted or defaulted, causing incorrect command behavior instead of validation errors.

1 open issue
What changed in this PR

Adds explicit begin/end timestamps and timezone support to the start command, allowing completed timesheets to be created directly while preserving the existing running-timesheet workflow.

Changes:

  • Adds --begin, --end, and --timezone options.
  • Validates timezone selection, timestamp ordering, and option dependencies.
  • Sends parsed timestamps to the API and displays end-time information for completed records.
  • Updates shared datetime and timezone parsing logic.
File Summary Review notes
src/​Command/​TimesheetCommandTrait.php Provides shared datetime parsing and timezone resolution helpers. Reject blank values and invalid calendar/time values instead of allowing normalization or fallback to the current time.
src/​Command/​StartCommand.php Defines and processes timestamp options, submits begin/end values, and formats completed-timesheet output. Make value-bearing options require arguments, and update the README example/documentation to reflect the new output and options.

This pull request requires changes.

Review effort: Lite

Comment thread src/Command/StartCommand.php Resolved
Allow creating timesheet records with explicit begin/end times, and a
-z/--timezone to name the IANA zone used to read them (falls back to the
PHP default). Invalid zone fails cleanly without entering the refine prompt.

Co-authored-by: webemerge <office@web-emerge.com>
Signed-off-by: webemerge <office@web-emerge.com>
Signed-off-by: Parthiban Nallathambi <parthiban@linumiz.com>
@parthitce
parthitce force-pushed the dev/add-begin-end-tz branch from 91943c7 to 6e559f7 Compare November 20, 2026 12:37
@parthitce

Copy link
Copy Markdown
Author

@kevinpapst Kindly revisit.

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.

🟡 Changes recommended

An active moderate issue remains because empty --begin or --end values are silently interpreted as the current time instead of being rejected before prompts or API calls.

1 open issue
1 resolved since last review

Review effort: Lite

Comment on lines +327 to +331
try {
return new \DateTime($value, $zone);
} catch (\Exception $e) {
throw new \InvalidArgumentException(\sprintf('Value "%s" for field "%s" is not a valid DateTime.', $value, $valueName));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

3 participants