[pmwiki-users] Event-calendar with pagelist and ftime? (repost)

sti at pooq.com sti at pooq.com
Tue Nov 13 04:45:02 CST 2007


Audun Myhra Bergwitz wrote:
>> (:pagelist if="date {(ftime %GW%V {*$Name})} {=$Name}" :)
>>
>> returns all of the pages where the name is in the same week as that 
>> of the current page."
> 
> I'm not sure if I get how this code work? Is this correct:
> 
> {(ftime %GW%V {*$Name})} seem to define a range of values, ie every date 
> value within the same week as {*$Name)? It then
> compares this to the name of pages beeing searched and if {=$Name} is
> within the range if=date returns TRUE?

Not quite. {*$Name} is the name part of the currently displayed page.
{(ftime...)} is described here:

  http://www.pmwiki.org/wiki/PmWiki/ConditionalMarkup

Thus the expression {(ftime %GW%V {*$Name})} takes the name of the currently
described page, and tries to interpret that as a date (if it fails, it uses
the current date instead). It outputs the result as a year and week number
like "2007W46".

The date test inside the 'if="date...' string is the same test as in the
standard conditional markup. Its documented here:

  http://www.pmwiki.org/wiki/PmWiki/ConditionalMarkup

I think that Hans was hoping that '2007W46' was a valid date string for the
test, but as far as I can see from reading through the documentation (and the
PmWiki code) it isn't. (It would be convenient if it was though). I'm afraid
that means that what Hans posted won't work.

Instead, I think you need a much more complicated test, like this:

(:pagelist if="date {(ftime %F '{*$Name} Sunday-1week')}..{(ftime %F '{*$Name}
Saturday')} {=$Name}" :)

This checks each page found by pagelist to see if its name can be interpreted
as a date that falls between last Sunday, and next Saturday (ie, this week).

> Why does one need %GW%V? Isn't %GW enough?

%GW would just produce a date like "2007W" which wouldn't have been enough, if
date could handle week numbers.

> Would this work for a pagelist where $Time(page text variable) is within 
> the current week:
> (: pagelist if="date {(ftime %GW%V when=today)} {=$Time}" :) ?

This would have been close, if date could handle %GW%V dates, but you forgot a
colon in the PTV. It should be {=$:Time}.

Instead, I think you need:

(:pagelist if="date {(ftime %F Sunday-1week)}..{(ftime %F Saturday)} {=$:Time}" :)

> What format should $Time have for the above to work? Would the order of
> this pagelist be chronological based on $Time? Or do I need to create a
> custom order= for it to do that?

You need a time string that can be interpreted as a standard date format. The
documentation for this can be found here:

  http://www.gnu.org/software/tar/manual/html_node/tar_113.html

Generally, its best to go with an ISO date of the form YYYY-MM-DD or
YYYY/MM/DD. If you find this too restrictive, a trick you can often use in a
page is to define the time in a hidden PTV and use it further down with ftime
to put it into a better format:

(:Time:2007/12/19:)

We'll be having our annual Christmas party on {(ftime "%A, %B %d, %Y")
{$:Time}}, so mark your calendars.

> Also:
>  From http://www.pmwiki.org/wiki/PmWiki/PageTextVariables
> 
>> Note ConditionalMarkup does not work with page text variables or 
>> include other pages.
>>
>> Page text variables don't honor (:if:). This is the same way that 
>> doing (:include OtherPage#section:) doesn't look to see if 
>> [[#section]] is inside of an (:if:)...(:ifend:) construct of some 
>> sort.
> 
> Does this mean that the above pagelist won't work or does it only mean
> that page text variables within conditional markup wont work?

Actually, it means that this won't work:

(:if authid:)
Allowed:True
(:else:)
NotAllowed:True
(:if:)

The above defines BOTH Allowed and NotAllowed. You can't use (:if:) to prevent
the definition of a PTV. Anything in a page that looks like a PTV is one, even
if it doesn't show. This can be useful, as some folks find it convenient to do
this:

(:if false:)
Hidden section
Date: 2007-10-15
Time: 7:45pm
Where: Ashtonbury Cathedral
What: A thurible.
(:ifend:)

and then use the PTV's so defined later on in the page.

I hope this helps!




More information about the pmwiki-users mailing list