Page MenuHomePhabricator

Convert calls to time() into PhabricatorTime::getNow() and eventually blacklist time()
Open, WishlistPublic

Description

The time() function works fine, but returns the actual current time. This makes it more difficult to test things like event triggers, both manually and with unit tests. Many time() calls should use PhabricatorTime::getNow() instead, which can return an alternate "current time" which comes from the CLI or a unit test.

Moving code to use PhabricatorTime::getNow() will generally produce more consistent, predictable results for commands like bin/trigger fire --now '2012-08-15 13:14:15'.

One issue with doing this is that getNow() never advances when faked -- the current time is frozen at the second which was faked. This is desirable/necessary for many test situations, but can make loops which rely on time() run forever. We'll need to introduce alternate primitives to deal with these cases.

The benefit of this infrastructure improvement is very small overall, but triggers and Calendar will likely benefit from easier development and testing in the long run as we make progress against it.

Related Objects

Event Timeline

epriestley raised the priority of this task from to Wishlist.
epriestley updated the task description. (Show Details)
epriestley added a project: Infrastructure.
epriestley added a subscriber: epriestley.

We should also probably move it to libphutil and rename it to PhutilTime, although the whole class can't move. This would let us use it in rCORE.

In particular, we can't do bin/remote backup db001 --instance giraffe --now '2012-08-15 13:14:15' to test backups at arbitrary times, and backups fired through bin/trigger fire --now ... lose their adjusted frame of reference once they make a call outside of rSERVICES.