FIX timesheet date comparison#36480
Open
atm-jonathan wants to merge 3 commits into
Open
Conversation
eldy
reviewed
Nov 29, 2025
| $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) { |
Member
There was a problem hiding this comment.
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.
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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
FIX Fix timesheet restriction date comparison
Problem:
When the constant
PROJECT_TIMESHEET_PREVENT_AFTER_MONTHSis 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_dateinto a Unix timestamp before comparing it with the$restrictBeforetimestamp.Affected methods in
projet/class/task.class.php:addTimeSpentupdateTimeSpentdelTimeSpent