0 users online. Create an account or sign in to join them.Users

Author:
mprofitl
Version:
1.0
Release Date:
16 Jul 2013
Category:
Date & Time

Description

A translated copy of brendo's friendly time ago (which is again an improved copy of Nick Dunn's utility). German language has a different structure of time expressions and this utility reflects these.

XSLT

View Raw
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:date="http://exslt.org/dates-and-times" xmlns:math="http://exslt.org/math" extension-element-prefixes="date math">

<xsl:template name="time-ago">
	<xsl:param name="date-and-time"/>
	
	<xsl:variable name="now" select="concat($today, 'T', $current-time, ':00', $timezone)" />
	<xsl:variable name="minutes" select="date:seconds(date:difference($date-and-time, $now)) div 60" />
	<xsl:variable name="delta-minutes" select="math:abs($minutes)" />
	
	<xsl:variable name="delta-in-words">
		<xsl:choose>
			<xsl:when test="$delta-minutes &lt; 1">
				<xsl:text>weniger als einer Minute</xsl:text>
			</xsl:when>
			<xsl:when test="$delta-minutes &lt; 2">
				<xsl:text>einer Minute</xsl:text>
			</xsl:when>
			<xsl:when test="$delta-minutes &lt; 45">
				<xsl:value-of select="floor($delta-minutes)"/>
				<xsl:text> Minuten</xsl:text>
			</xsl:when>
			<xsl:when test="$delta-minutes &lt; 90">
				<xsl:text>etwa einer Stunde</xsl:text>
			</xsl:when>
			<xsl:when test="$delta-minutes &lt; 1440">
				<xsl:value-of select="floor($delta-minutes div 60)"/>
				<xsl:text> Stunden</xsl:text>
			</xsl:when>
			<xsl:when test="$delta-minutes &lt; 2880">
				<xsl:text>einem Tag</xsl:text>
			</xsl:when>
			<xsl:when test="$delta-minutes &lt; 43200">
				<xsl:value-of select="round($delta-minutes div 1440)"/>
				<xsl:text> Tagen</xsl:text>
			</xsl:when>
			<xsl:when test="$delta-minutes &lt; 86400">
				<xsl:text>etwa einem Monat</xsl:text>
			</xsl:when>
			<xsl:when test="$delta-minutes &lt; 525600">
				<xsl:value-of select="floor($delta-minutes div 43200)"/>
				<xsl:text> Monaten</xsl:text>
			</xsl:when>
			<xsl:when test="$delta-minutes &lt; 1051200">
				<xsl:value-of select="floor($delta-minutes div 10080)"/>
				<xsl:text>etwa einem Jahr</xsl:text>
			</xsl:when>
			<xsl:otherwise>
				<xsl:value-of select="floor($delta-minutes div 525600)"/>
				<xsl:text> Jahren</xsl:text>
			</xsl:otherwise>
		</xsl:choose>
	</xsl:variable>

	<xsl:choose>
		<xsl:when test='$minutes &lt; 0'>
			<xsl:choose>
				<xsl:when test='$delta-in-words = "one day"'>
					<xsl:text>morgen</xsl:text>
				</xsl:when>
				<xsl:when test='$delta-in-words = "about one month"'>
					<xsl:text>letzten Monat</xsl:text>
				</xsl:when>
				<xsl:when test='$delta-in-words = "about one year"'>
					<xsl:text>letztes Jahr</xsl:text>
				</xsl:when>
				<xsl:otherwise>
					<xsl:text>vor </xsl:text>
					<xsl:value-of select='$delta-in-words' />
				</xsl:otherwise>
			</xsl:choose>			
		</xsl:when>
		<xsl:otherwise>
			<xsl:choose>
				<xsl:when test='$delta-in-words = "one day"'>
					<xsl:text>gestern</xsl:text>
				</xsl:when>
				<xsl:when test='$delta-in-words = "about one month"'>
					<xsl:text>nächsten Monat</xsl:text>
				</xsl:when>
				<xsl:when test='$delta-in-words = "about one year"'>
					<xsl:text>nächstes Jahr</xsl:text>
				</xsl:when>
				<xsl:otherwise>
					<xsl:text>vor </xsl:text>
					<xsl:value-of select='$delta-in-words' />
				</xsl:otherwise>
			</xsl:choose>
		</xsl:otherwise>
	</xsl:choose>
</xsl:template>

</xsl:stylesheet>

Discuss this XSLT Utility

Symphony • Open Source XSLT CMS

Server Requirements

  • PHP 5.3-5.6 or 7.0-7.1
  • 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