Functions-Talk

Problem with PSFT

I tried to use the new PSFT function I had the following problem when the User/visitor lets a PTV input field empty:

  • 'strftime("%Y%m%d", strtotime(PageVar($pagename, "$:date"))' delivers 19700101 (thats the result I want)
  • 'PSFT("%Y%m%d", strtotime(PageVar($pagename, "$:date"))' delivers the day today

Maybe its my own bad coding. Any idea what i can do? Siegfried Seibert March 18, 2022, at 11:35 MEZ

With strftime(), when the stamp is not numeric, old PHP versions cast it to integer (0), but PHP 8.1 raises a warning and does nothing (i.e. breaks). If there is no second argument, the value of time() is used. On PmWiki however, page variables and text variables that are null are identical to empty string "" before it gets to PSFT(), so PSFT() only casts to integers the numeric values, as in an empty string "" will be considered null or time(). This should work best with existing PmWiki functions and markup expressions.

In your case, you can use PSFT("%Y%m%d", intval(...)) to convert the stamp to an integer. For PmWiki, it would not be practical to make an empty string stamp behave as 1970-01-01. I'll document it. --Petko

I have to think about this one, there is still time to change it. --Petko

Thank you, PSFT("%Y%m%d", intval(...)) solved the problem. I just had to change one line of code in config.php, so for my installation this is completely OK. Siegfried Seibert March 18, 2022, at 12:47 MEZ


Documentation needs to be fixed: PSS($string) uses old markup with Markup_e and /e directives. XES September 22, 2017, at 08:09 AM

The examples are only with "Markup() with /e", that's the only case when this function should be used. --Petko September 22, 2017, at 08:47 AM

This is a talk page for improving PmWiki.Functions.