Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deprecated global function "now" because it's equivalent to Varien_Date::now() #1991

Merged
merged 1 commit into from
Apr 20, 2022
Merged

Deprecated global function "now" because it's equivalent to Varien_Date::now() #1991

merged 1 commit into from
Apr 20, 2022

Conversation

Sdfendor
Copy link
Contributor

@Sdfendor Sdfendor commented Jan 28, 2022

Description (*)

There are currently two now methods that are doing the exact same thing, returning the formatted version of the current timestamp either with or without the time part (Besides those there is a third one within Zend that does a similar thing but is not part of this PR).

global now (app/code/core/Mage/Core/functions.php):

/**
 * Simple sql format date
 *
 * @param bool $dayOnly
 * @return string
 */
function now($dayOnly = false)
{
    return date($dayOnly ? 'Y-m-d' : 'Y-m-d H:i:s');
}

Varien_Date (lib/Varien/Date.php):

/**
 * Retrieve current date in internal format
 *
 * @param boolean $withoutTime day only flag
 * @return string
 */
public static function now($withoutTime = false)
{
    $format = $withoutTime ? self::DATE_PHP_FORMAT : self::DATETIME_PHP_FORMAT;
    return date($format);
}

the used constants:

const DATETIME_PHP_FORMAT       = 'Y-m-d H:i:s';
const DATE_PHP_FORMAT           = 'Y-m-d';

It's clear to see that both functions are equivalent. I propose:

  1. To deprecate global function now
  2. To reference the replacement Varien_Date::now()
  3. To use the replacement call instead of the redundant code

In subsequent PRs the following changes can be implemented:

  1. For v19 occurrences of deprecated global function shall be replaced one-to-one
  2. For v20 deprecated global function shall be removed

Contribution checklist (*)

  • Pull request has a meaningful description of its purpose
  • All commits are accompanied by meaningful commit messages
  • All automated tests passed successfully (all builds are green)

@github-actions github-actions bot added the Component: Core Relates to Mage_Core label Jan 28, 2022
@fballiano fballiano merged commit e3d66a5 into OpenMage:1.9.4.x Apr 20, 2022
@github-actions
Copy link
Contributor

Unit Test Results

0 files   - 1  0 suites   - 1   0s ⏱️ ±0s
0 tests ±0  0 ✔️ ±0  0 💤 ±0  0 ❌ ±0 
0 runs   - 7  0 ✔️  - 5  0 💤  - 2  0 ❌ ±0 

Results for commit e3d66a5. ± Comparison against base commit 438639f.

@Sdfendor Sdfendor deleted the deprecate_redundant_global_function branch August 4, 2022 10:11
@Sdfendor Sdfendor restored the deprecate_redundant_global_function branch August 4, 2022 10:11
@Sdfendor Sdfendor deleted the deprecate_redundant_global_function branch August 4, 2022 10:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Component: Core Relates to Mage_Core
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants