Search

When trying to format dates with the Date Time utility, I found that there was a missing format for day. So, I've added an additional format for days in digits with no leading zero and no suffix:

 x - day in digits with no leading zero e.g. 1, 9, 12, 25

The date-controller template needs the following added:

 <xsl:when test="$tletter = 'x'">
   <xsl:call-template name="format-day">
     <xsl:with-param name="date" select="$date"/>
     <xsl:with-param name="format" select="$letter"/>
   </xsl:call-template>
 </xsl:when>

And the format-day template needs to look like this:

 <xsl:template name="format-day">
   <xsl:param name="date"/>
   <xsl:param name="day" select="format-number(substring($date,9,2),'00')"/>
   <xsl:param name="format" select="'x'"/>
   <xsl:param name="suffix">
     <xsl:choose>
       <xsl:when test="(substring($day,2) = 1) and not(substring($day,1,1) = 1)">st</xsl:when>
       <xsl:when test="(substring($day,2) = 2) and not(substring($day,1,1) = 1)">nd</xsl:when>
       <xsl:when test="(substring($day,2) = 3) and not(substring($day,1,1) = 1)">Rd</xsl:when>
       <xsl:otherwise>th</xsl:otherwise>
     </xsl:choose>
   </xsl:param>

   <xsl:choose>
     <xsl:when test="$format = 'd'">
       <xsl:value-of select="$day"/>
     </xsl:when>
     <xsl:when test="$format = 'x'">
       <xsl:value-of select="format-number($day,'0')"/>
     </xsl:when>
     <xsl:when test="$format = 'D'">
       <xsl:value-of select="format-number($day,'0')"/>
       <sup><xsl:value-of select="$suffix"/></sup>
     </xsl:when>
   </xsl:choose>
 </xsl:template>

I noticed this too. Allen, this should probably be included in your date utility. Awesome date utility, by the way!

It is quite awesome indeed.

Thanks Stephen, I've put this on the bug tracker as a feature addition. I'll add it to the next revision.

I also noticed a small typo:

 W - month as a full word e.g. Monday, Tuesday

Surely it must be:

 W - day as a full word e.g. Monday, Tuesday

I have also noticed that January was spelt wrong.

Create an account or sign in to comment.

Symphony • Open Source XSLT CMS

Server Requirements

  • PHP 5.3-5.6 or 7.0-7.3
  • PHP's LibXML module, with the XSLT extension enabled (--with-xsl)
  • MySQL 5.5 or above
  • An Apache or Litespeed webserver
  • Apache's mod_rewrite module or equivalent

Compatible Hosts

Sign in

Login details