-
- 368 Posts
That’s it all right... but no day suffix format string :’(
This may be a stupid question, but is it possible for this to be implemented in MODx without also being added to PHP’s strftime? If so, I’m going to get busy with the bugtracker....
Jason
-
- 24,544 Posts
Quote from: kenquad at Oct 29, 2010, 03:50 AM
That’s it all right... but no day suffix format string :’(
This may be a stupid question, but is it possible for this to be implemented in MODx without also being added to PHP’s strftime? If so, I’m going to get busy with the bugtracker....
It’s theoretically possible, but you can also write your own custom output modifier (i.e. snippet). Something like this:
<?php
/* DateSuffix snippet */
$suffix = '';
switch (substr($input, -1, 1)) {
case: '1':
$suffix = 'st';
break;
case: '2':
$suffix = 'nd';
break;
case '3':
$suffix = 'rd';
break;
default:
$suffix = 'th';
}
/* handle anomalies */
switch (substr($input, -2, 2)) {
case '11:
case '12':
case '13':
$suffix = 'th';
break;
}
return $input . $suffix;
Just tack on
ateSuffix after date: (assuming that the number you want to suffix is at the end).
-
- 368 Posts
It looks to me like your snippet would require a different condition for every day of the month to differentiate between, say, the 22nd and the 12th, both of which end with the digit ’2’. Is that right?
Jason
-
- 24,544 Posts
Quote from: kenquad at Oct 29, 2010, 03:44 PM
It looks to me like your snippet would require a different condition for every day of the month to differentiate between, say, the 22nd and the 12th, both of which end with the digit ’2’. Is that right?
Not quite, all the ’th’ ones can be left out since that’s the default and you can lump a bunch of them together:
Look above, I’ve rewritten it.
-
- 368 Posts
Looks good to me. Now I’ll see if I can get it implemented. Thanks!
Jason
-
- 24,544 Posts
It’s sort of a bug, but not in MODx. The %e modifier is not implemented in Windows.
http://www.php.net/manual/en/function.strftime.php
-
- 81 Posts
Thanks for that BobRay.
At least I know I’m not going crazy.
I’m guessing that it might then work when I upload the test site from my windows localhost to the linux server then.
Thanks for your tutorials and info pages - they are very helpful for non-programmer types like me.