01418: Please add ordinals to ftime{} markup expressions

Summary: Please add ordinals to ftime{} markup expressions
Created: 2017-08-19 07:58
Status: Closed, added for 2.3.0
Category: Feature
From: XES
Assigned:
Priority: 1
Version:
OS:

Description: Request simple additional markup for ftime{} per suggestion on the php strftime() page.

This will allow adding ordinals to date output for English output per the date() 'S' parameter.

Suggested code from comment on PHP documentation page:


function my_strftime ($format, $timestamp)
{
    $format = str_replace('%O', date('S', $timestamp), $format);    
    return strftime($format, $timestamp);
}

XES August 19, 2017, at 07:59 AM

While this is very easy to add, the "%O" format means something different in the library function strftime. We could use lowercase "%o" but what if some day PHP assigns this format to something else? --Petko August 19, 2017, at 08:20 AM

And unfortunately, PHP does not localize these, unlike the month and day names (though not a reason to not enable it, at least for English). --Petko August 19, 2017, at 08:32 AM

I think you'd want to use something that would be very unlikely to assigned as a strftime format, e.g. "%^". --simon August 27, 2017, at 07:31 PM

Not a problem -- I was just showing what the comment on the strftime() page showed. Absolutely not picky about the convention used. Not all websites require i8n, such as local websites for local events. But it's nice to be able to say an event will be on Wednesday the 8th of November. XES September 05, 2017, at 10:52 AM -- I believe in translations, the markup would be ignored.

With PHP 8.1, the function strftime is deprecated, so it is very unlikely for new formats to be added. So I've added the "%o" format as an ordinal suffix with the new PSFT() function. See Functions#PSFT. Note that using the function before PHP 8.1, and without $EnableFTimeNew, will have the suffixes in English only. Enabling $EnableFTimeNew, with the 'intl' extension loaded will allow having the suffixes in other languages too. See below. --Petko January 01, 2022, at 07:09 PM

English

(:pagelist group=PmWiki fmt=#date count=10 order=random:)
(:if false:)
[[#date]]
* [[{=$Group}/{=$Name}]] . . . {(ftime fmt="%e'^%o^' %B, %Y" when=@{=$LastModifiedTime} )}
[[#dateend]]
(:ifend:)

French

(:pagelist group=PmWiki fmt=#date-intl count=10 order=random:)
(:if false:)
[[#date-intl]]
* [[{=$Group}/{=$Name}]] . . . {(ftime fmt="%e'^%o^' %B, %Y" when=@{=$LastModifiedTime} locale=fr_FR.utf8 )}
[[#date-intlend]]
(:ifend:)

Note that the pmwiki.org server doesn't have the PHP 'intl' extension loaded, so the ordinal suffixes are in English (but the French locale is installed for strftime so the month name is in French). On my own wiki the ordinal suffixes are correctly in French. See PmWiki.Functions#PSFT. --Petko January 01, 2022, at 07:09 PM

Looking at it again, in French dates, the "1st" may be written as "1er" ("premier"), but all other dates are just read as cardinal numbers (normal), as in "the two January". So I probably wouldn't use "%o" for dates in French. --Petko January 02, 2022, at 01:53 PM