Skip to content

FIX timesheet date comparison#36480

Open
atm-jonathan wants to merge 3 commits into
Dolibarr:developfrom
atm-jonathan:FIX_TIMESHEET_DATE_COMPARISON
Open

FIX timesheet date comparison#36480
atm-jonathan wants to merge 3 commits into
Dolibarr:developfrom
atm-jonathan:FIX_TIMESHEET_DATE_COMPARISON

Conversation

@atm-jonathan

Copy link
Copy Markdown
Contributor

FIX Fix timesheet restriction date comparison

Problem:
When the constant PROJECT_TIMESHEET_PREVENT_AFTER_MONTHS is set, the check to prevent insertion, modification, or deletion of old timesheets was failing.
The code was comparing $this->timespent_date (a string, e.g., '2023-01-01') directly with $restrictBefore (an integer timestamp). This type mismatch caused the condition to evaluate incorrectly (often returning false), allowing changes even when they should have been restricted.

Solution:
Added strtotime() to convert $this->timespent_date into a Unix timestamp before comparing it with the $restrictBefore timestamp.

Affected methods in projet/class/task.class.php:

  • addTimeSpent
  • updateTimeSpent
  • delTimeSpent

@atm-jonathan atm-jonathan changed the title timesheet date comparison FIX timesheet date comparison Nov 29, 2025
Comment thread htdocs/projet/class/task.class.php Outdated
$restrictBefore = dol_time_plus_duree(dol_now(), - getDolGlobalInt('PROJECT_TIMESHEET_PREVENT_AFTER_MONTHS'), 'm');

if ($this->timespent_date < $restrictBefore) {
if (strtotime($this->timespent_date) < $restrictBefore) {

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.

Using strtotime must be avoid. Timezone are not managed correctly. Would be better to convert the restrictbefore into a timestamp (using dol_mktime for example) to make the comparison.

@eldy eldy added the PR to fix - See feedback in comments PR needs to be fixed to be integrated (some comments should describes the fix to do) label Nov 29, 2025
@pixodeo

pixodeo commented Jun 20, 2026

Copy link
Copy Markdown
Contributor

PR #38921 opened against 18.0. The three comparison sites in task.class.php now coerce $this->timespent_date with is_numeric/(int)strtotime before comparing against the dol_time_plus_duree timestamp, so the PROJECT_TIMESHEET_PREVENT_AFTER_MONTHS guard catches both the date-string and the int-timestamp callers.

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

Labels

PR to fix - See feedback in comments PR needs to be fixed to be integrated (some comments should describes the fix to do)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants