Skip to content

Commit

Permalink
PHP 8.1 - deprecated strftime()
Browse files Browse the repository at this point in the history
I will use @strftime as suggested in smarty
- smarty-php/smarty#678
- smarty-php/smarty#780

A good solution using date() probably requires lot of testing.
  • Loading branch information
u0113 committed Aug 24, 2022
1 parent f322433 commit 10994ba
Show file tree
Hide file tree
Showing 15 changed files with 39 additions and 39 deletions.
12 changes: 6 additions & 6 deletions lib/api/xmlrpc/v1/test/TestlinkXMLRPCServerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -565,7 +565,7 @@ function testCreateBuildWithInsufficientRights()
{
$data = array();
$data["devKey"] = TestlinkXMLRPCServerTestData::noRightsDevKey;
$data["buildname"] = "Another test build from " . strftime("%c");
$data["buildname"] = "Another test build from " . @strftime("%c");
$data["testplanid"] = TestlinkXMLRPCServerTestData::testTPID;

if(!$this->client->query('tl.createBuild', $data)) {
Expand All @@ -584,7 +584,7 @@ function testCreateBuildWithoutNotes()
{
$data = array();
$data["devKey"] = TestlinkXMLRPCServerTestData::testDevKey;
$data["buildname"] = "Another test build from " . strftime("%c");
$data["buildname"] = "Another test build from " . @strftime("%c");
$data["testplanid"] = TestlinkXMLRPCServerTestData::testTPID;

if(!$this->client->query('tl.createBuild', $data)) {
Expand All @@ -600,9 +600,9 @@ function testCreateBuildWithNotes()
{
$data = array();
$data["devKey"] = TestlinkXMLRPCServerTestData::testDevKey;
$data["buildname"] = "Another notes test build from " . strftime("%c");
$data["buildname"] = "Another notes test build from " . @strftime("%c");
$data["testplanid"] = TestlinkXMLRPCServerTestData::testTPID;
$data["buildnotes"] = "Some notes from the build created at " . strftime("%c");
$data["buildnotes"] = "Some notes from the build created at " . @strftime("%c");

if(!$this->client->query('tl.createBuild', $data)) {
echo "\n" . $this->getName() . " >> something went really wrong - " . $this->client->getErrorCode() .
Expand All @@ -616,9 +616,9 @@ function testCreateBuildWithInvalidTPID()
{
$data = array();
$data["devKey"] = TestlinkXMLRPCServerTestData::testDevKey;
$data["buildname"] = "Another test build from " . strftime("%c");
$data["buildname"] = "Another test build from " . @strftime("%c");
$data["testplanid"] = -1;
$data["buildnotes"] = "Some notes from the build created at " . strftime("%c");
$data["buildnotes"] = "Some notes from the build created at " . @strftime("%c");

if(!$this->client->query('tl.createBuild', $data)) {
echo "\n" . $this->getName() . " >> something went really wrong - " . $this->client->getErrorCode() .
Expand Down
2 changes: 1 addition & 1 deletion lib/codetrackerintegration/stashrestInterface.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ public function getCommitsForHTMLSelect($projectKey,$repoName,$branchName)

foreach($commitList->values as $elem)
{
$ret[$elem->id] = $elem->displayId . ' (' . strftime($localesDateFormat,
$ret[$elem->id] = $elem->displayId . ' (' . @strftime($localesDateFormat,
($elem->authorTimestamp / 1000)) . '): ' . $elem->message;
}
}
Expand Down
4 changes: 2 additions & 2 deletions lib/functions/lang_api.php
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,7 @@ function localize_dateOrTimeStamp($params,$smarty,$what,$value)
$value = strtotime($value);
}

$retVal = strftime($format, $value);
$retVal = @strftime($format, $value);
if(isset($params['var'])) {
$smarty->assign($params['var'],$retVal);
}
Expand All @@ -410,7 +410,7 @@ function localizeTimeStamp($value,$format)
$value = strtotime($value);
}

return strftime($format, $value);
return @strftime($format, $value);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion lib/functions/print.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -735,7 +735,7 @@ function renderFirstPage($doc_info)


$output .= '<div class="summary">' . '<p id="printedby">' . lang_get('printed_by_TestLink_on')." ".
strftime($date_format_cfg, time()) . "</p></div>\n";
@strftime($date_format_cfg, time()) . "</p></div>\n";

// Print legal notes
if ($docCfg->company_copyright != '')
Expand Down
4 changes: 2 additions & 2 deletions lib/functions/testcase.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -551,7 +551,7 @@ function create_tcase_only($parent_id,$name,$order=self::DEFAULT_ORDER,$id=self:
$doIt = true;
while($doIt) {
if( $doIt = !is_null($itemSet) ) {
$prefix = strftime($algo_cfg->text,time());
$prefix = @strftime($algo_cfg->text,time());
$target = $prefix . " " . $name ;
$final_len = strlen($target);
if( $final_len > $name_max_len)
Expand Down Expand Up @@ -8206,7 +8206,7 @@ function trim_and_limit($s, $len = 100)
*/
function generateTimeStampName($name)
{
return strftime("%Y%m%d-%H:%M:%S", time()) . ' ' . $name;
return @strftime("%Y%m%d-%H:%M:%S", time()) . ' ' . $name;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion lib/issuetrackerintegration/gforgesoapInterface.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ private function helperParseDate($date2parse)
{
$ret = date_parse($date2parse);
$ret = ((gmmktime(0, 0, 0, $ret['month'], $ret['day'], $ret['year'])));
$ret = $this->l18n['duedate'] . gmstrftime("%d %b %Y",($ret));
$ret = $this->l18n['duedate'] . @gmstrftime("%d %b %Y",($ret));
}
return $ret ;
}
Expand Down
2 changes: 1 addition & 1 deletion lib/issuetrackerintegration/jiraCommons.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ private function helperParseDate($date2parse)
{
$ret = date_parse($date2parse);
$ret = ((gmmktime(0, 0, 0, $ret['month'], $ret['day'], $ret['year'])));
$ret = $this->l18n['duedate'] . gmstrftime("%d %b %Y",($ret));
$ret = $this->l18n['duedate'] . @gmstrftime("%d %b %Y",($ret));
}
return $ret ;
}
Expand Down
2 changes: 1 addition & 1 deletion lib/requirements/reqOverview.php
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@
$verbose_type = $req_mgr->cfield_mgr->custom_field_types[$cf['type']];
$value = preg_replace('!\s+!', ' ', htmlspecialchars($cf['value'], ENT_QUOTES, $cfg->charset));
if( ($verbose_type == 'date' || $verbose_type == 'datetime') && is_numeric($value) && $value != 0 ) {
$value = strftime( $cfg->$verbose_type . " ({$labels['week_short']} %W)" , $value); #fix typo: missing 's' in labels
$value = @strftime( $cfg->$verbose_type . " ({$labels['week_short']} %W)" , $value); #fix typo: missing 's' in labels
}
$result[] = $value;
}
Expand Down
4 changes: 2 additions & 2 deletions lib/results/resultsMoreBuildsGUI.php
Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,9 @@ function initializeGui(&$dbHandler,$args)
$reports_cfg = config_get('reportsCfg');
$ldf = config_get('locales_date_format');
$date_format = $ldf[((isset($_SESSION['locale'])) ? $_SESSION['locale'] : 'en_GB')];
$gui->selected_start_date = strftime($date_format, time() - ($reports_cfg->start_date_offset));
$gui->selected_start_date = @strftime($date_format, time() - ($reports_cfg->start_date_offset));
$gui->selected_start_time = $reports_cfg->start_time;
$gui->selected_end_date = strftime($date_format, time());
$gui->selected_end_date = @strftime($date_format, time());
$gui->selected_end_time = null;

return $gui;
Expand Down
4 changes: 2 additions & 2 deletions lib/results/tcCreatedPerUserOnTestProject.php
Original file line number Diff line number Diff line change
Expand Up @@ -303,10 +303,10 @@ function initializeGuiForInput(&$dbHandler,$argsObj,&$guiObj) {
$now = time();

if(is_null($argsObj->selected_start_date)) {
$guiObj->selected_start_date = strftime($dateFormat, $now - ($cfg->start_date_offset));
$guiObj->selected_start_date = @strftime($dateFormat, $now - ($cfg->start_date_offset));
$guiObj->selected_start_time = $cfg->start_time;

$guiObj->selected_end_date = strftime($dateFormat, $now);
$guiObj->selected_end_date = @strftime($dateFormat, $now);
$guiObj->selected_end_time = null;
} else {
$guiObj->selected_start_date = $argsObj->selected_start_date[0];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,7 @@ public static function DATEVALUE($dateValue = 1) {
if ($testVal2 !== False) {
$testVal3 = strtok('- ');
if ($testVal3 === False) {
$testVal3 = strftime('%Y');
$testVal3 = @strftime('%Y');
}
} else {
return PHPExcel_Calculation_Functions::VALUE();
Expand All @@ -401,9 +401,9 @@ public static function DATEVALUE($dateValue = 1) {

if (($PHPDateArray !== False) && ($PHPDateArray['error_count'] == 0)) {
// Execute function
if ($PHPDateArray['year'] == '') { $PHPDateArray['year'] = strftime('%Y'); }
if ($PHPDateArray['month'] == '') { $PHPDateArray['month'] = strftime('%m'); }
if ($PHPDateArray['day'] == '') { $PHPDateArray['day'] = strftime('%d'); }
if ($PHPDateArray['year'] == '') { $PHPDateArray['year'] = @strftime('%Y'); }
if ($PHPDateArray['month'] == '') { $PHPDateArray['month'] = @strftime('%m'); }
if ($PHPDateArray['day'] == '') { $PHPDateArray['day'] = @strftime('%d'); }
$excelDateValue = floor(PHPExcel_Shared_Date::FormattedPHPToExcel($PHPDateArray['year'],$PHPDateArray['month'],$PHPDateArray['day'],$PHPDateArray['hour'],$PHPDateArray['minute'],$PHPDateArray['second']));

switch (PHPExcel_Calculation_Functions::getReturnDateType()) {
Expand Down
8 changes: 4 additions & 4 deletions third_party/codeplex/PHPExcel/Calculation/DateTime.php
Original file line number Diff line number Diff line change
Expand Up @@ -534,7 +534,7 @@ public static function DATEVALUE($dateValue = 1)
if ($testVal2 !== false) {
$testVal3 = strtok('- ');
if ($testVal3 === false) {
$testVal3 = strftime('%Y');
$testVal3 = @strftime('%Y');
}
} else {
return PHPExcel_Calculation_Functions::VALUE();
Expand All @@ -554,16 +554,16 @@ public static function DATEVALUE($dateValue = 1)
if (($PHPDateArray !== false) && ($PHPDateArray['error_count'] == 0)) {
// Execute function
if ($PHPDateArray['year'] == '') {
$PHPDateArray['year'] = strftime('%Y');
$PHPDateArray['year'] = @strftime('%Y');
}
if ($PHPDateArray['year'] < 1900) {
return PHPExcel_Calculation_Functions::VALUE();
}
if ($PHPDateArray['month'] == '') {
$PHPDateArray['month'] = strftime('%m');
$PHPDateArray['month'] = @strftime('%m');
}
if ($PHPDateArray['day'] == '') {
$PHPDateArray['day'] = strftime('%d');
$PHPDateArray['day'] = @strftime('%d');
}
$excelDateValue = floor(
PHPExcel_Shared_Date::FormattedPHPToExcel(
Expand Down
6 changes: 3 additions & 3 deletions third_party/phpxmlrpc/lib/xmlrpc.inc
Original file line number Diff line number Diff line change
Expand Up @@ -3123,19 +3123,19 @@ xmlrpc_encode_entitites($this->errstr, $GLOBALS['xmlrpc_internalencoding'], $cha
{
if(!$utc)
{
$t=strftime("%Y%m%dT%H:%M:%S", $timet);
$t=@strftime("%Y%m%dT%H:%M:%S", $timet);
}
else
{
if(function_exists('gmstrftime'))
{
// gmstrftime doesn't exist in some versions
// of PHP
$t=gmstrftime("%Y%m%dT%H:%M:%S", $timet);
$t=@gmstrftime("%Y%m%dT%H:%M:%S", $timet);
}
else
{
$t=strftime("%Y%m%dT%H:%M:%S", $timet-date('Z'));
$t=@strftime("%Y%m%dT%H:%M:%S", $timet-date('Z'));
}
}
return $t;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ function smarty_function_html_select_date($params, Smarty_Internal_Template $tem
break;
}
}
// Note: date() is faster than strftime()
// Note: date() is faster than @strftime()
// Note: explode(date()) is faster than date() date() date()
if (isset($params[ 'time' ]) && is_array($params[ 'time' ])) {
if (isset($params[ 'time' ][ $prefix . 'Year' ])) {
Expand Down Expand Up @@ -309,8 +309,8 @@ function smarty_function_html_select_date($params, Smarty_Internal_Template $tem
for ($i = 1; $i <= 12; $i++) {
$_val = sprintf('%02d', $i);
$_text = isset($month_names) ? smarty_function_escape_special_chars($month_names[ $i ]) :
($month_format === '%m' ? $_val : strftime($month_format, $_month_timestamps[ $i ]));
$_value = $month_value_format === '%m' ? $_val : strftime($month_value_format, $_month_timestamps[ $i ]);
($month_format === '%m' ? $_val : @strftime($month_format, $_month_timestamps[ $i ]));
$_value = $month_value_format === '%m' ? $_val : @strftime($month_value_format, $_month_timestamps[ $i ]);
$_html_months .= '<option value="' . $_value . '"' . ($_val == $_month ? ' selected="selected"' : '') .
'>' . $_text . '</option>' . $option_separator;
}
Expand Down
12 changes: 6 additions & 6 deletions vendor/smarty/smarty/libs/plugins/modifier.date_format.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,19 @@
* Smarty date_format modifier plugin
* Type: modifier
* Name: date_format
* Purpose: format datestamps via strftime
* Purpose: format datestamps via @strftime
* Input:
* - string: input date string
* - format: strftime format for output
* - format: @strftime format for output
* - default_date: default date if $string is empty
*
* @link https://www.smarty.net/manual/en/language.modifier.date.format.php date_format (Smarty online manual)
* @author Monte Ohrt <monte at ohrt dot com>
*
* @param string $string input date string
* @param string $format strftime format for output
* @param string $format @strftime format for output
* @param string $default_date default date if $string is empty
* @param string $formatter either 'strftime' or 'auto'
* @param string $formatter either '@strftime' or 'auto'
*
* @return string |void
* @uses smarty_make_timestamp()
Expand All @@ -48,7 +48,7 @@ function smarty_modifier_date_format($string, $format = null, $default_date = ''
} else {
return;
}
if ($formatter === 'strftime' || ($formatter === 'auto' && strpos($format, '%') !== false)) {
if ($formatter === '@strftime' || ($formatter === 'auto' && strpos($format, '%') !== false)) {
if (Smarty::$_IS_WINDOWS) {
$_win_from = array(
'%D',
Expand Down Expand Up @@ -78,7 +78,7 @@ function smarty_modifier_date_format($string, $format = null, $default_date = ''
}
$format = str_replace($_win_from, $_win_to, $format);
}
return strftime($format, $timestamp);
return @strftime($format, $timestamp);
} else {
return date($format, $timestamp);
}
Expand Down

0 comments on commit 10994ba

Please sign in to comment.