2 Jan 1999 08:00 require_once FS_ABS_PATH.'/php/db-sql.php'; $this->assertDatesEquals("1 Jan 2001 08:00", fs_days_ago_to_unix_time(1, false, strtotime("2 Jan 2001 08:00"))); $this->assertDatesEquals("1 Jan 2001 00:00", fs_days_ago_to_unix_time(1, false, strtotime("2 Jan 2001 00:00"))); $this->assertDatesEquals("1 Jan 2001 00:00", fs_days_ago_to_unix_time(1, true, strtotime("1 Jan 2001 00:00"))); $this->assertDatesEquals("1 Jan 2001 00:00", fs_days_ago_to_unix_time(1, true, strtotime("1 Jan 2001 00:01"))); $this->assertDatesEquals("1 Jan 2001 00:00", fs_days_ago_to_unix_time(1, true, strtotime("1 Jan 2001 23:59"))); $this->assertDatesEquals("1 Feb 2008 00:00", fs_days_ago_to_unix_time(5, true, strtotime("5 Feb 2008 23:59"))); // with time zones // same timezone $this->assertDatesEquals("1 Jan 2001 00:00", fs_days_ago_to_unix_time(1, true, strtotime("1 Jan 2001 00:00"), "+0:0","+0:0")); $this->assertDatesEquals("1 Jan 2001 00:00", fs_days_ago_to_unix_time(1, true, strtotime("1 Jan 2001 00:00"), "+1:0","+1:0")); // Different time zone. // We want to return a time that is midnight for the user, but the time is at the server time zone. // This is the explnation for the first test: // Server time is 1 Jan 2001 03:00, // User is at +2 hours offset, so user time is 1 Jan 2001 05:00, // This means that for the user, midnight is 5 hours ago. // so we return 31 Dec 2000 22:00, which is 5 hours ago in server time. $this->assertDatesEquals("31 Dec 2000 22:00", fs_days_ago_to_unix_time(1, true, strtotime("1 Jan 2001 03:00"), "+2:0","+0:0")); $this->assertDatesEquals("1 Jan 2001 14:00", fs_days_ago_to_unix_time(1, true, strtotime("2 Jan 2001 08:00"), "+10:0","+0:0")); $this->assertDatesEquals("2 Jan 2001 05:00", fs_days_ago_to_unix_time(1, true, strtotime("2 Jan 2001 21:00"), "-5:0","+0:0")); $this->assertDatesEquals("31 Dec 2000 21:00", fs_days_ago_to_unix_time(1, true, strtotime("1 Jan 2001 03:00"), "+2:0","-1:0")); } function assertDatesEquals($expected_date_str, $actual_date_unixtime) { $this->assertEquals($expected_date_str, date('j M Y H:i', $actual_date_unixtime)); } } ?>