statamic / cms

The core Laravel CMS Composer package
https://statamic.com
Other
3.71k stars 508 forks source link

Using `now | modify_date` more than once causes calculation errors #9100

Closed JayGeorge closed 9 months ago

JayGeorge commented 9 months ago

Bug description

Using now | modify_date more than once causes calculation errors.

For example:

{{ now|modify_date("next monday") }}
{{ now|modify_date("next monday") }}

Would result in:

December 4th, 2023
December 11th, 2023

This if you try to filter a collection like this: {{ collection:something sort="date:asc" as="entries" date:is_after='{now|modify_date("next monday")}' date:is_before='{now|modify_date("next monday + 7 days")}' }} you'd get unexpected results

How to reproduce

Try:

{{ now|modify_date("next monday") }}
{{ now|modify_date("next monday") }}

and see how you'll get:

December 4th, 2023
December 11th, 2023

Rather than what you'd expect:

December 4th, 2023
December 4th, 2023

Logs

No response

Environment

Laravel Version: 10.32.1
PHP Version: 8.2.7
Composer Version: 2.5.8
Environment: local
Debug Mode: ENABLED
URL: something.test
Maintenance Mode: OFF

Cache
Config: NOT CACHED
Events: NOT CACHED
Routes: CACHED
Views: CACHED

Drivers
Broadcasting: log
Cache: statamic
Database: mysql
Logs: stack / single
Mail: smtp
Queue: sync
Session: file

Locales
Installed
LaravelLang\Attributes\Plugin: 2.5.0
LaravelLang\HttpStatuses\Plugin: 3.6.1
LaravelLang\Lang\Plugin: 13.6.1
Locales Version: 1.9.0
Protected
Publisher Version: 15.0.2

Statamic
Addons: 4
Antlers: runtime
Stache Watcher: Enabled
Static Caching: Disabled
Version: 4.38.0 Solo

Statamic Addons
jaygeorge/statamic-vanilla-peak-tools: dev-main
studio1902/statamic-peak-browser-appearance: 3.3.2
studio1902/statamic-peak-commands: 3.0.0
studio1902/statamic-peak-seo: 7.3.1

Installation

Starter Kit using via CLI

Antlers Parser

runtime (new)

Additional details

No response

duncanmcclean commented 9 months ago

Ah, we probably need to make the now variable immutable.

JayGeorge commented 9 months ago

I'm in the process of making my first pull request shhhhh

duncanmcclean commented 9 months ago

🤐

duncanmcclean commented 9 months ago

We merged #9114 today which will allow you to prevent the date from being modified. Simply add the following to the boot method in your AppServiceProvider:

\Illuminate\Support\Facades\Date::use(\Carbon\CarbonImmutable::class);