Prettier timestamp in Colloquy
Colloquy only show me hour and minute for messages, but I want second! Why those Colloquy guys ignore second? One day in my life has 86400 parts, minutes is not precision enough for me. Furthermore, second is an SI base unit, isn't it?
After a while of research, I found they use XSLT as a render engine. I use "Fiat" style, and the XSL file could be found at /Applications/Colloquy.app/Contents/Resources/Styles/Fiat.colloquyStyle/Contents/Resources/main.xsl. The code for the timestamp conversion may look like:
<xsl:template name="short-time">
<xsl:param name="date" /> <!-- YYYY-MM-DD HH:MM:SS +/-HHMM -->
<xsl:variable name='hour' select='substring($date, 12, 2)' />
<xsl:variable name='minute' select='substring($date, 15, 2)' />
<xsl:choose>
<xsl:when test="contains($timeFormat,'H')">
<!-- 24hr format -->
<xsl:value-of select="concat($hour,':',$minute)" />
</xsl:when>
<xsl:otherwise>
<!-- am/pm format -->
<xsl:choose>
<xsl:when test="number($hour) > 12">
<xsl:value-of select="number($hour) - 12" />
</xsl:when>
<xsl:when test="number($hour) = 0">
<xsl:text>12</xsl:text>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$hour" />
</xsl:otherwise>
</xsl:choose>
<xsl:text>:</xsl:text>
<xsl:value-of select="$minute" />
<xsl:choose>
<xsl:when test="number($hour) >= 12">
<xsl:text>PM</xsl:text>
</xsl:when>
<xsl:otherwise>
<xsl:text>AM</xsl:text>
</xsl:otherwise>
</xsl:choose>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
After have read the code above, I have to say, the Western date format sucks! It is lucky that we have ISO 8601, but I cannot understand why they still insist on that *stupid* style of date, make it as a standard in UNIX and force us to follow. So I removed all useless code above, and my code is now like the following:
<xsl:template name="short-time">
<xsl:param name="date" /> <!-- YYYY-MM-DD HH:MM:SS +/-HHMM -->
<xsl:value-of select="substring($date, 12, 8)" />
</xsl:template>

1 Comments:
An spelling mistake :
'but I cannot understand why they still insisit on that *stupid* style of date'
'insisit' should be 'insist', right?
Post a Comment
<< Home