We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 37059
    • 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
      • 3749
      • 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 laughateSuffix after date: (assuming that the number you want to suffix is at the end).
        Did I help you? Buy me a beer
        Get my Book: MODX:The Official Guide
        MODX info for everyone: http://bobsguides.com/modx.html
        My MODX Extras
        Bob's Guides is now hosted at A2 MODX Hosting
        • 37059
        • 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
          • 3749
          • 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.

            Did I help you? Buy me a beer
            Get my Book: MODX:The Official Guide
            MODX info for everyone: http://bobsguides.com/modx.html
            My MODX Extras
            Bob's Guides is now hosted at A2 MODX Hosting
            • 37059
            • 368 Posts
            Looks good to me. Now I’ll see if I can get it implemented. Thanks!
              Jason
              • 25287
              • 81 Posts
              Thanks for the info in this topic, especially the list of parameters by BobRay.

              I’ve run into one glitch - including the %e parameter results in a blank output. The %e is meant to remove the leading zero on the %d parameter. It’s not major, but puzzling.

              eg.
              [[*publishedon:strtotime:date=`%e %B %Y`]]
              produces no output but
              [[*publishedon:strtotime:date=`%d %B %Y`]]
              does.

              Could it be some error in my configuration or is this a bug?
                • 3749
                • 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
                  Did I help you? Buy me a beer
                  Get my Book: MODX:The Official Guide
                  MODX info for everyone: http://bobsguides.com/modx.html
                  My MODX Extras
                  Bob's Guides is now hosted at A2 MODX Hosting
                  • 25287
                  • 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.
                    • 24629
                    • 370 Posts
                    Hi,

                    is it also possible to use
                    setlocale(LC_ALL, 'nl_NL')
                    within a filter?


                    [[+publishedon:strtotime:date=`%d %b %Y`]]

                    that would be handy for multilingual sites.

                    Ralph
                      • 37059
                      • 368 Posts
                      Quote from: BobRay at Oct 29, 2010, 04:16 AM

                      Just tack on laughateSuffix after date: (assuming that the number you want to suffix is at the end).

                      I’m back grin

                      Just 4 months later, I finally got around to trying to use this - and immediately ran into a problem: I have no idea how to attach this:
                      [[+publishedon:strtotime:date=`%B %d, %Y`]]

                      to this:
                      :DateSuffix


                      Particularly when the number needing the suffix isn’t at the end. huh Sorry to have to ask for hand-holding all the way, but I am really new to the whole snippet modifiers thing. Thanks!
                        Jason