Using date, views, calendar, cck modules to create various date related calendars and views .
How can I force a test date (i.e. change what 'now' is) to test the site for different dates e.g. to check that blocks that only show on certain dates work correctly?

Comments

dww’s picture

Status: Active » Fixed

That's outside the scope of Drupal. I believe you'd have to change the time on your system clock for the server running your site. Might not be possible, unless you've got a virtual host or something.

Tony Sharpe’s picture

Thanks for this. Changing the system clock is not something I want to do as it could cause all sorts of problems. I'd be quite happy to just hack in a line to date or calendar module as a one-off test - it's not something I'll need to do very often but I'd need to know the best place to do that.

dww’s picture

That's what I'm saying -- you can't really do that. DateAPI is doing all sorts of date manipulation, sometimes directly via the database and/or PHP, both of which are going to be relying on the system clock for "now"...

One thing you could try is changing the date_now() function in date_api.module. I won't promise that'll cover all cases, but it'll cover most cases. ;) So, instead of this:

function date_now($timezone = NULL) {
  return date_make_date('now', $timezone);
}

you'd want something like this:

function date_now($timezone = NULL) {
  $now = date_make_date('now', $timezone); 
  date_modify($now, '+4 days');  // or whatever you need.
  return $now;
}

or, just something like:

function date_now($timezone = NULL) {
  return date_make_date('2008-11-23 14:00', $timezone); 
}

Again, I'm not positive that *every* time CCK date and DateAPI touch the current time they use a date object from date_now(). I believe there are cases where they generate SQL for NOW(), and that's going to not work unless your DB thinks the time is different, too...

Good luck,
-Derek

Tony Sharpe’s picture

Thanks very much for this, I will give it a try. It's just what I needed.

karens’s picture

Title: Creating test date for date related content » Changing 'now' to test dates
Category: support » feature

It would be nice to find a way to do this, it's something that would be handy. I don't know off the top of my head if this will work or if there's another way to make this work, but I'll turn it into a feature request and if anyone finds a way to do it you can post it.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for two weeks with no activity.