tags:

views:

34

answers:

2

I'm currently working on my company's in-house CMS and wish to add the ability for an admin to view the site on a specific date. This will allow admins to preview the site with archived or scheduled posts.

I'd like to avoid finding all mentions of date() or time() and offsetting them. Is there a way of making PHP think it's a specific date so that all calls to date() default to the new time?

Thank you

+1  A: 

This sounds like an encapsulation issue -- why not search for all mentions of date() or time() and replace them with $site->getDisplayedDate(), or something else appropriate to your code?

zildjohn01
I know I could do this, but I'd still be interested to know whether what I've asked is doable. I'm working with some legacy code and I'm afraid it's not the best-structured work I've come across :(
Rowan
I feel your pain, but I don't think there's any way to do this. Think about it this way... how would you feel if, in some unrelated code, you called `time()` and it gave you some date 3 weeks in the future?
zildjohn01
Very true. Thanks for the answer anyway, I'm happy to do it this way if there's no alternative! No OOP though, all globals :(
Rowan
+1  A: 

I can only think of changing it globally, which would change the date for everyone on the server at that point.

I would probably store a timestamp in the session or similar, so that it can be easily changed and updated at will, rather than changing core php ini values.

You might try this though, http://uk2.php.net/manual/en/function.date-default-timezone-set.php

DavidYell