[pmwiki-users] repost: problem with PTV and if= date in pagelists

Peter Bowers pbowers at pobox.com
Fri Jan 30 13:41:16 CST 2009

On Fri, Jan 30, 2009 at 12:14 PM, none < <bergwitz at gmail.com> wrote:

> Audun Myhra Bergwitz wrote:
> (:pagelist if='date ..{=$:Timestamp}' $:Timestamp=-:)
> Tried this again today, and it works.
> The reason it didn't work was that I had PTVs which didn't follow the
> correct pattern. I was using the Norwegian word Tid (Time) as the PTV
> and some pages had things like "Tid: Monday the 1st of August" (though
> in Norwegian so totally unrecognizable for the pmwiki code). When I
> tested it by using Timestamp:  as the PTV (which only appear on my test
> pages) and all PTVs followed recongizable pattern the code work as
> expected.
> Due to the unrecognizable format of some PTVs the pagelist code seem to
> ignore the whole If-thing. I don't know it this is a bug in the code, or
> if it is the intended behaviour.
> Anyway it makes my idea of making an event calendar based on
> PTV-Timestamps somewhat vulnerable, as just one wrongly formatted PTV
> will cause all pagelists based on the PTV-timestamp to list everything.
> Though, I think I can work around that.

I think I've figured out some things that will at least move us forward in
understanding as well as (I think) giving a working solution...

The date condition calls DRange() in pmwiki.  This function starts up with a
regex to parse the arguments.  The regex does NOT allow spaces (\S*) in the
first 2 arguments (i.e., before and after the ..) but DOES allow spaces
(\S.*) in the last argument.  So if you put your PTV (relatively
uncontrolled data) as the FIRST argument and it has something like "February
2, 2009" then DRange() interprets that as "February" as your first argument
and "2, 2009" as your last argument.  Obviously this gets things really
messed up and you get somewhat random results.  (Although I'm still not
getting anything that brings in all pages -- that's a puzzler.)

In order to get around this problem (note that only English dates will be
recognized by strtodate()) you need to put your PTV as the last argument.
Then you also need to check to make sure the PTV is not invalid and that the
PTV is not blank.  Here's something that should result in a working

(:pagelist name=Test.? if="expr date {(ftime %Y%m%d)}.. {=$:ts} && ! date
INVALID {=$:ts}" $:ts=-:)

It may also be helpful to periodically run something that would check for
those invalid dates since presumably those pages with a PTV set to an
unrecognized date are intended to be displayed and so you would want to
correct them:

(:pagelist name=Test.? if="date INVALID {=$:ts}" $:ts=-:)

Hope that solves it for you...

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.pmichaud.com/pipermail/pmwiki-users/attachments/20090130/4c3121c9/attachment.html 

More information about the pmwiki-users mailing list