Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

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

mrdale
Member
From: Walla Walla
Registered: 2004-11-19
Posts: 2,215
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: 5,068
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: 5,068
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 Emeritus
From: Helsinki, Finland
Registered: 2006-07-14
Posts: 4,533
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)

Offline

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

mrdale
Member
From: Walla Walla
Registered: 2004-11-19
Posts: 2,215
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 Emeritus
From: Helsinki, Finland
Registered: 2006-07-14
Posts: 4,533
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

Offline

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

mrdale
Member
From: Walla Walla
Registered: 2004-11-19
Posts: 2,215
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 Emeritus
From: Helsinki, Finland
Registered: 2006-07-14
Posts: 4,533
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)

Offline

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

ruud
Developer emeritus
From: a galaxy far far away
Registered: 2006-06-04
Posts: 5,068
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: 10,562
Website GitHub

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. Bleeding-edge code available on GitHub.

Txp Builders – finely-crafted code, design and Txp

Offline

#11 2008-11-07 18:26:37

mrdale
Member
From: Walla Walla
Registered: 2004-11-19
Posts: 2,215
Website

Re: Date Based URLvar problem with time offset

So Ruud…

Preference or No? I’m for your hack. Let’s get it in the core. I’m sick of applying hacks to every site I have that uses a calendar.

…otherwise, let’s remove DST and Timezone altogether, as they’re functionally pointless.

taps feet.

Offline

#12 2008-11-07 21:05:10

saccade
Plugin Author
From: Neubeuern, Germany
Registered: 2004-11-05
Posts: 517

Re: Date Based URLvar problem with time offset

Maybe I’m wrong here (I just chime in because there seems to be a change in the time-handling), but DST behaviour in Textpattern is a problem in general, because DST-setting now does change all dates (or timestamps, back and forth), even when they were created in a different DST-period.

In my opinion DST-setting should be left out in calculating timestamps (just take the current valid time or the manually inserted time) and only be taken into account when calculating the current active time. Timestamps shan’t change ever (except willingly and manually) and they always should reflect in numbers what time has been actual (for past times) or what is estimated as the actual time in future.

E.g.: If I write now (non DST) an article which should be published (and should show the time 10 o’clock!) next June, 1st, 10 o’clock (DST presumably active – but this could also be changed by law), I don’t want to know or think about it’s time-algorithm. Whether DST or not I mean 10 o’clock. At the moment I need to set it to “9.00” because otherwise txp will change it to “11” when DST-setting changes.
The other way round an article which is now shown as “published 10:00” in next summer will be shown as “published 11:00” – that is extremely irritating, not to mention the hassle if you have a calendar like mdp_calendar.

Edit: I have written those reflections in german, should I post them or try a translation?

Last edited by saccade (2008-11-07 21:07:40)

Offline

Board footer

Powered by FluxBB