Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions core/attributedef.class.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -8985,12 +8985,15 @@ public function GetSubItemAsPlainText($sItemCode, $value)
switch ($sThresholdCode) {
case 'deadline':
if ($value) {
if (is_int($value)) {
if (is_numeric($value)) {
if (!is_int($value)) {
$value = intval($value);
}
$sDate = date(AttributeDateTime::GetInternalFormat(), $value);
$sRet = AttributeDeadline::FormatDeadline($sDate);
Comment on lines 8987 to 8993
Copy link

Copilot AI Jan 28, 2026

Choose a reason for hiding this comment

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

GetSubItemAsPlainText() is now tolerant of numeric-string timestamps for deadline, but GetSubItemAsHTML() still calls date(..., $value) without casting/validation, which can still throw a TypeError on PHP 8 when $value is a string (common when the subitem value comes from SQL). Consider applying the same numeric-string handling in the HTML branch to keep behavior consistent and prevent runtime errors.

Copilot uses AI. Check for mistakes.
} else {
$sRet = $value;
}
} else {
$sRet = $value;
}
Comment on lines +8988 to +8996
Copy link

Copilot AI Jan 28, 2026

Choose a reason for hiding this comment

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

The added block uses spaces for indentation whereas this file consistently uses tabs in surrounding code. Please re-indent these lines to match the existing convention to keep diffs clean and avoid style drift.

Copilot uses AI. Check for mistakes.
} else {
$sRet = '';
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -347,4 +347,20 @@ public function GivenAttribute(string $sHostClass, string $sAttCode, string $sAt
return $oAttribute;
}

public function testDisplayStopwatch()
{
$aUserRequestCustomParams = [
Comment on lines +350 to +352
Copy link

Copilot AI Jan 28, 2026

Choose a reason for hiding this comment

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

This new test method is indented with spaces, while the rest of the file uses tabs (eg. existing methods above). Please align indentation to the file's convention to avoid noisy diffs and style inconsistencies.

Copilot uses AI. Check for mistakes.
'title' => "Test DisplayStopwatch",
];
$oUserRequest = $this->CreateUserRequest(456, $aUserRequestCustomParams);
$oAttDef = MetaModel::GetAttributeDef(get_class($oUserRequest), 'ttr_escalation_deadline');
$iStartDate = time() - 200;

$oStopwatch = $oUserRequest->Get('ttr');
$oStopwatch->DefineThreshold(100, $iStartDate);
Comment on lines +357 to +360
Copy link

Copilot AI Jan 28, 2026

Choose a reason for hiding this comment

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

Variable name $iStartDate is misleading here: it's used as the threshold deadline timestamp passed to DefineThreshold(), not a start date. Renaming (eg. $iDeadlineTs) would make the test intent clearer.

Suggested change
$iStartDate = time() - 200;
$oStopwatch = $oUserRequest->Get('ttr');
$oStopwatch->DefineThreshold(100, $iStartDate);
$iDeadlineTs = time() - 200;
$oStopwatch = $oUserRequest->Get('ttr');
$oStopwatch->DefineThreshold(100, $iDeadlineTs);

Copilot uses AI. Check for mistakes.
$oUserRequest->Set('ttr', $oStopwatch);
$value = $oUserRequest->Get('ttr_escalation_deadline');
$sRet = $oAttDef->GetAsPlainText($value, $oUserRequest);
self::assertEquals('Missed by 3 min', $sRet);
Comment on lines +362 to +364
Copy link

Copilot AI Jan 28, 2026

Choose a reason for hiding this comment

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

This test doesn't currently exercise the new behavior in GetSubItemAsPlainText() (handling numeric timestamps provided as strings), because Get('ttr_escalation_deadline') returns an int from the in-memory ormStopWatch. To cover the regression, coerce $value to a string (or otherwise simulate the SQL/string code path) before calling GetAsPlainText() and keep the assertion on the formatted output.

Copilot uses AI. Check for mistakes.
}
}