Textpattern Forum

You are not logged in. Register | Login | Help

#1 2008-10-25 14:26:37

mrdale
Moderator
From: Walla Walla
Registered: 2004-11-19
Posts: 2,066
Website

Date Based URLvar problem with time offset

I came across this problem a long time ago, and Mary made a patch.

BUG: When using date based URLvars like “?date=2008-10-06” an article posted on that day may or may not show depending on the time of day posted.

Details: My time offset is -8 GMT, and I have DST switched on.

  • If I post at 17:00 the article doesn’t show
  • If I post at 16:59 the article shows

So it’s pretty clear that this is a time offset issue.

The problem is fixed by the following patch, which was supplied by mary against 4.0.6

Index: textpattern/publish.php
===================================================================
--- textpattern/publish.php	(revision 2987)
+++ textpattern/publish.php	(working copy)
@@ -621,7 +621,26 @@
 		$section   = (!$section)   ? '' : " and Section IN ('".join("','", doSlash(do_list($section)))."')";
 		$excerpted = ($excerpted=='y')  ? " and Excerpt !=''" : '';
 		$author    = (!$author)    ? '' : " and AuthorID IN ('".join("','", doSlash(do_list($author)))."')";
-		$month     = (!$month)     ? '' : " and Posted like '".doSlash($month)."%'";
+
+
+		// Hack to fix Textpattern's wack date bug
+		if ($month)
+		{
+			list($y, $m, $d) = explode('-', $month);
+
+			// Calculate bounds on a certain server-day, using the website offset
+			// With an article, we add the offset, so we subtract to undo that
+			$l = mktime(0, 0, 0, $m, $d, $y) - tz_offset();
+			$h = mktime(0, 0, 0, $m, $d+1, $y) - tz_offset();
+
+			$month = " and Posted >= from_unixtime($l) and Posted < from_unixtime($h) ";
+		}
+		
+		else
+		{
+			$month = '';
+		}
+
 		$id        = (!$id)        ? '' : " and ID = '".intval($id)."'";
 		switch ($time) {
 			case 'any':

Offline

#2 2008-10-26 14:01:16

ruud
Developer emeritus
From: a galaxy far far away
Registered: 2006-06-04
Posts: 4,545
Website

Re: Date Based URLvar problem with time offset

Alternative:

Index: textpattern/publish.php
===================================================================
--- textpattern/publish.php	(revision 2987)
+++ textpattern/publish.php	(working copy)
@@ -621,7 +621,26 @@
 		$section   = (!$section)   ? '' : " and Section IN ('".join("','", doSlash(do_list($section)))."')";
 		$excerpted = ($excerpted=='y')  ? " and Excerpt !=''" : '';
 		$author    = (!$author)    ? '' : " and AuthorID IN ('".join("','", doSlash(do_list($author)))."')";
-		$month     = (!$month)     ? '' : " and Posted like '".doSlash($month)."%'";
+		$month     = (!$month)     ? '' : " and from_unixtime(unix_timestamp(Posted) + ".tz_offset()."))  like '".doSlash($month)."%'";

The advantage is that it still allows you to abuse (!) the “month” attribute for selecting a year: month="2008", but I suspect it’s considerably slower than Mary’s solution (haven’t tested either one) for large sets of articles.

Offline

#3 2008-10-26 18:05:10

ruud
Developer emeritus
From: a galaxy far far away
Registered: 2006-06-04
Posts: 4,545
Website

Re: Date Based URLvar problem with time offset

Hmm… something to consider. This is how it currently works (if I understand correctly):

/year/month/day/title => the date in that URL is the date the same as the one stored in the database for a specific article, which due to timezone issues doesn’t always equal the date in the timezone set by the user. So you’ll see that <txp:posted /> can show 2008-10-26, while in the permlinkurl, it can looks like 2008-10-27 due to the timezone setting.

/year/month/day => same thing

What you propose is switching the second case (/year/month/day) to use the timezone-compensated dates instead of the dates stored in the database. This would make /year/month/day/title url schemes inconsistent with /year/month/day.

Offline

#4 2008-10-26 19:03:35

Gocom
Developer
Registered: 2006-07-14
Posts: 4,476
Website

Re: Date Based URLvar problem with time offset

Remember that this would change the content of our existing date/month based article listings. Not always bad thing but anyway.

Last edited by Gocom (2008-10-26 19:04:09)


Rah-plugins | What? I’m a little confused… again :-) <txp:is_god />

Offline

#5 2008-10-27 15:50:00

mrdale
Moderator
From: Walla Walla
Registered: 2004-11-19
Posts: 2,066
Website

Re: Date Based URLvar problem with time offset

Just my 2c… A timezone compensation system is pretty pointless without across-the-board application in the CMS.

I think you should make everything date-based timezone compensated OR remove the timezone setting.

or am I wrong here?

Last edited by mrdale (2008-10-27 16:19:42)

Offline

#6 2008-10-27 16:31:37

Gocom
Developer
Registered: 2006-07-14
Posts: 4,476
Website

Re: Date Based URLvar problem with time offset

mrdale wrote:

or am I wrong here?

Remember that in some countries we have daylight saving time that causes some problems. In example URL’s content will change twice during a year.

So I’m against of that patch, or then we need a setting to disable that. I don’t want my article content change automatically.

remove the timezone setting

Then it’s impossible to determinate publish time or configure time right when server moves location (remember our not so beloved dst) :D


Rah-plugins | What? I’m a little confused… again :-) <txp:is_god />

Offline

#7 2008-10-27 17:30:46

mrdale
Moderator
From: Walla Walla
Registered: 2004-11-19
Posts: 2,066
Website

Re: Date Based URLvar problem with time offset

OK, So we just have to deal with date based urls failing to display content?

Offline

#8 2008-10-27 17:48:40

Gocom
Developer
Registered: 2006-07-14
Posts: 4,476
Website

Re: Date Based URLvar problem with time offset

mrdale wrote:

OK, So we just have to deal with date based urls failing to display content?

It shows it, but with different date.

Current txp sites will be effected with the change so, it possibly requires option to turn it off; that patch i mean.

Last edited by Gocom (2008-10-27 17:50:52)


Rah-plugins | What? I’m a little confused… again :-) <txp:is_god />

Offline

#9 2008-11-03 21:46:29

ruud
Developer emeritus
From: a galaxy far far away
Registered: 2006-06-04
Posts: 4,545
Website

Re: Date Based URLvar problem with time offset

Hmm… makes you wonder why we have a DST preference.

Offline

#10 2008-11-03 22:11:34

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 5,980
Website

Re: Date Based URLvar problem with time offset

ruud wrote:

Hmm… makes you wonder why we have a DST preference.

Makes one wonder why we have DST in the world at all. Add half an hour and leave it be. Save us all a headache :-D

Last edited by Bloke (2008-11-03 22:12:26)


The smd plugin menagerie — for when you need one more gribble of power from Textpattern.

Txp Builders – finely-crafted code, design and Txp

Offline

Board footer

Powered by FluxBB