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

FIX Defensively copy mocked datetime #9968

Merged
merged 1 commit into from
Jun 7, 2021

Conversation

dmipeck
Copy link
Contributor

@dmipeck dmipeck commented Jun 5, 2021

Datetime::now() currently returns a reference to self::$mock_now if a mock time has been set. This means that if one calls Datetime::now()->Modify(...) the next time Datetime::now() is called it will return the modified datetime rather than the original. This PR has Datetime::now() return a defensive copy of self::$mock_now so that the mock time cannot be accidentally modified and can only be changed via Datetime::set_mock_now()

@kinglozzer
Copy link
Member

I’ve encountered this issue too, this should save having to do a bunch of clone-ing in user code

@dhensby dhensby merged commit c79638b into silverstripe:4 Jun 7, 2021
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 this pull request may close these issues.

3 participants