Problems, need help? Have a tip or advice? Post it here.
3 posts Page 1 of 1
I've been trying to do something with dates in the form 'Second Saturday of the month' for a project, and in the course of it I seem to have found an issue (or perhaps an unexpected limitation) in cms:date.

In the thread at viewtopic.php?f=8&t=10559, KK indicates that the cms:date tag will deal with the same formats as the standard PHP strtotime. This presumably supersedes the documentation, which says that the date is expected in the 'Y-m-d H:i:s' format.

I therefore expected that if I did
Code: Select all
<cms:set my_date_long='First Saturday of August 2018' />
<cms:date '<cms:show my_date_long />'  format='Y-m-d H:i:s'/>

I'd get back the date of the first Saturday of August, formatted as I'd asked - that is, 2018-08-04 00:00:00.

But I've found that this only works if the date is specified in text directly - that is, I can't include a variable.

Here's a test file. I'd expect it to produce the same results whether the 'date' parameter for cms:date is literally 'First Saturday of August 2018', or a variable containing that text, or a variable containing 'First Saturday' plus the text 'of August 2018'. However, the cms:date only returns the correct response for the simple text option. I've also included a simpler type of date (whcih again doesn't work if it's in a variable), and for comparison, I've added a version using cms:php and calling PHP's strtotime function directly, and it works in all cases.

Code: Select all
<?php require_once( 'couch/cms.php' ); ?>

</p>
<cms:set my_date_short ='First Saturday' />
<cms:set my_date_long='First Saturday of August 2018' />
<cms:set my_date_simple='4 August 2018' />
<h2>
   Results using cms:date
</h2>
<p>
   Using string: <cms:date 'First Saturday of August 2018'  format='Y-m-d H:i:s'/>
</p>
<p>
   Using variable containing month: <cms:date '<cms:show my_date_long />'  format='Y-m-d H:i:s'/>
</p>

<p>
   Using variable plus text for month:<cms:date '<cms:show my_date_short /> of August 2018'  format='Y-m-d H:i:s'/>
</p>
<p>
   Using a simpler variable: <cms:date '<cms:show my_date_simple />'  format='Y-m-d H:i:s'/>
</p>


<h2>
   Results using cms:php and strtotime
</h2>

<p>
   Using string:     <cms:php> echo(date('Y-m-d H:i:s',strtotime( 'First Saturday of August 2018')));</cms:php>
</p>
<p>
   Using variable containing month: <cms:php> echo(date('Y-m-d H:i:s',strtotime( '<cms:show my_date_long />')));</cms:php>
</p>
<p>
   Using variable plus text for month:     <cms:php> echo(date('Y-m-d H:i:s',strtotime( '<cms:show my_date_short /> of August 2018')));</cms:php>
</p>
<p>
   Using a simpler variable: <cms:php> echo(date('Y-m-d H:i:s',strtotime( '<cms:show my_date_simple />')));</cms:php>
</p>

<?php COUCH::invoke(); ?>


Is it not expected behaviour for a tag to be able to take parameters made up using cms:show?
One needs to use "double-quotes" if the output of Couch tags is to be used as a parameter's value (please see http://docs.couchcms.com/concepts/setti ... eters.html for details).

For example as follows -
Code: Select all
<cms:date "<cms:show my_date_long />"  format='Y-m-d H:i:s'/>

Hope it helps.
That makes perfect sense - I missed that completely!

Thanks!
3 posts Page 1 of 1
cron