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

'Time Since' Rules calculates days incorrectly #117

Closed
gbaims opened this issue Nov 18, 2024 · 1 comment · Fixed by #119
Closed

'Time Since' Rules calculates days incorrectly #117

gbaims opened this issue Nov 18, 2024 · 1 comment · Fixed by #119

Comments

@gbaims
Copy link

gbaims commented Nov 18, 2024

Description

There is a bug in the "Time Since" rule logic. The code currently calculates the difference between the current date and the order date by only considering the difference in days (d). For example, if the order was made on 2024-10-15, the calculated difference on 2024-11-18 is 3 (18 - 15). However, the correct value should be 34, taking into account the full time interval, including months and years.

The issue arises because the d property of the TimeInterval object is used in the calculation. This property only provides the day difference and ignores other components of the date. Replacing d with the days property seems to resolve the issue, as days provides the total difference in days.


Step-by-step reproduction instructions

  1. Set a Woocommerce "Time Since Order" rule.
  2. First Order.
  3. Greater than
  4. 31
  5. The rule will never be true.

Expected behavior

The "Time Since" rule should calculate the correct time difference in days, considering the full time interval between the two dates. For example, from 2024-10-15 to 2024-11-18, the expected result is 34 days.


Actual behavior

The "Time Since" rule calculates the time difference as 3 days, ignoring the months and other components of the date interval.


Screenshots or screen recording (optional)

No screenshots available, but the bug can be reproduced with the steps provided.


System information

  • Block Visibility version: e.g., "3.7.0"
  • Block Visibility Pro version: "Not installed"
  • WordPress version: "6.7.0"
  • Gutenberg version: "Not installed"
  • Are all plugins except Block Visibility, Block Visibility Pro (if installed), and Gutenberg (if installed) deactivated? No
  • Are you using a default theme (e.g., Twenty Twenty-One)? No
@ndiego
Copy link
Owner

ndiego commented Dec 1, 2024

Thanks for reporting this bug @gbaims. I just fixed it and will include this patch in the next release later this week.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants