As of uComponents v6.0.0 all XSLT extensions are automatically registered with Umbraco. Newly created XSLT files (in the back-office) will already contain the appropriate namespaces. For existing XSLT files, you will still need to add the ucomponents.dates
namespace.
Enabling the XSLT extension for use in your XSLT templates.
Add the following XML snippet to your ~/config/xsltExtensions.config
file:
<XsltExtensions>
...
<ext assembly="uComponents.XsltExtensions" type="uComponents.XsltExtensions.Dates" alias="ucomponents.dates" />
...
</XsltExtensions>
Here are available methods in the Dates
library:
Adds the workdays, excluding weekends.
| Name | Type | Notes |
|——|——|——-|
| date | System.String
| |
| days | System.Int32
| |
| format | System.String
| (optional - defaults to dd MMMM yyyy
) |
<xsl:value-of select="ucomponents.dates:AddWorkdays(umbraco.library:CurrentDate(), 7, 'dd/MM/yyyy')" />
Get the current age, from the specified date of birth.
Returns: Returns the age based on the specified date of birth.
| Name | Type | Notes |
|——|——|——-|
| dateOfBirth | System.String
| |
<xsl:value-of select="ucomponents.dates:Age('1978-07-30')" />
Tests if a date is within the specified duration.
Returns: Returns true or false depending on if the date is within the specified duration.
| Name | Type | Notes |
|——|——|——-|
| date | System.String
| |
| duration | System.String
| The duration in XSD Duration format. |
<!-- if the content node was created within the last 7 days, then do ... -->
<xsl:if test="ucomponents.dates:DateWithinDuration($currentPage/@createDate, '7D')">
...
</xsl:if>
Tests if a date is within the last number of specified days.
Returns: Returns true or false depending on if the date is within the last number of days.
| Name | Type | Notes |
|——|——|——-|
| date | System.String
| |
| days | System.Int32
| |
<!-- if the content node was created within the last 7 days, then do ... -->
<xsl:if test="ucomponents.dates:DateWithinLastDays($currentPage/@createDate, 7)">
...
</xsl:if>
Gets the elapsed seconds since the input DateTime
.
Returns: Returns the elapsed seconds since the input DateTime
.
| Name | Type | Notes |
|——|——|——-|
| input | System.String
| |
<xsl:value-of select="ucomponents.dates:ElapsedSeconds($currentPage/@createDate)" />
Converts the value of the date time string to its equivalent string representation using the specified format.
Returns: The formatted date string
| Name | Type | Notes |
|——|——|——-|
| date | System.String
| |
| format | System.String
| (note - the use of S
returns the day-number suffix) |
<xsl:value-of select="ucomponents.dates:FormatDateTime($currentPage/@createDate, 'ddd ddS MMMM yyyy')" />
Gets the first day of month.
| Name | Type | Notes |
|——|——|——-|
| date | System.String
| |
| format | System.String
| (optional - defaults to dd MMMM yyyy
) |
<xsl:value-of select="ucomponents.dates:GetFirstDayOfMonth(umbraco.library:CurrentDate(), 'dd/MM/yyyy')" />
Gets the last day of month.
| Name | Type | Notes |
|——|——|——-|
| date | System.String
| |
| format | System.String
| (optional - defaults to dd MMMM yyyy
) |
<xsl:value-of select="ucomponents.dates:GetLastDayOfMonth(umbraco.library:CurrentDate(), 'dd/MM/yyyy')" />
Gets the pretty date.
Returns: Returns a pretty date.
| Name | Type | Notes |
|——|——|——-|
| date | System.String
| |
| format | System.String
| (optional - defaults to dd MMMM yyyy
) |
<xsl:value-of select="ucomponents.dates:GetPrettyDate($currentPage/@createDate, 'dd MMMM yyyy')" />
Determines whether [is leap year] [the specified date].
Returns: true if [is leap year] [the specified date]; otherwise, false.
| Name | Type | Notes |
|——|——|——-|
| date | System.String
| |
<xsl:if test="ucomponents.dates:IsLeapYear(umbraco.library:CurrentDate())">
<blink>Hurray! It's a leap year!</blink>
</xsl:if>
Determines whether the specified date is weekday.
Returns: true if the specified date is weekday; otherwise, false.
| Name | Type | Notes |
|——|——|——-|
| date | System.String
| |
<xsl:choose>
<xsl:when test="ucomponents.dates:IsWeekday(umbraco.library:CurrentDate())">
<span class="sad-panda">Boo! It's a weekday!</span>
</xsl:when>
<xsl:otherwise>
<blink>Hurray! It's the weekend!</blink>
</xsl:otherwise>
</xsl:choose>
Determines whether the specified date is weekend.
Internally this is the opposite of the IsWeekday method.
Returns: true if the specified date is weekend; otherwise, false.
| Name | Type | Notes |
|——|——|——-|
| date | System.String
| |
<xsl:choose>
<xsl:when test="ucomponents.dates:IsWeekend(umbraco.library:CurrentDate())">
<blink>Hurray! It's the weekend!</blink>
</xsl:when>
<xsl:otherwise>
<span class="sad-panda">Boo! It's a weekday!</span>
</xsl:otherwise>
</xsl:choose>
Lists all the dates between the start and end dates.
Internally this method uses umbraco.library.Split
to separate the dates into a list.
Returns: Returns a nodeset of all the dates between the start and end date.
| Name | Type | Notes |
|——|——|——-|
| startDate | System.String
| |
| endDate | System.String
| |
<ul>
<xsl:for-each select="ucomponents.dates:ListDates('2013-06-12', '2013-06-14')/value">
<li>
<xsl:value-of select="text()" />
</li>
</xsl:for-each>
</ul>
Parses the exact value of the date time string to its equivalent string representation using the specified format.
Returns: Returns a sortable date/time formatted to the specified pattern.
| Name | Type | Notes |
|——|——|——-|
| date | System.String
| |
| inputFormat | System.String
| |
| outputFormat | System.String
| (optional - defaults to "s"
“Sortable date/time pattern“) |
<xsl:value-of select="ucomponents.dates:ParseExact('12-31-2012', 'MM-dd-yyyy', 'dd-MM-yyyy')" />
Converts a date to Unix time.
Returns: Return the total number of seconds between Unix epoch and the specified date/time.
| Name | Type | Notes |
|——|——|——-|
| date | System.String
| |
<xsl:value-of select="ucomponents.dates:ToUnixTime($currentPage/@createDate)" />
Gets the number of workdays between two dates.
Returns: Returns the number of workdays between two dates.
| Name | Type | Notes |
|——|——|——-|
| startDate | System.String
| |
| endDate | System.String
| |
<!-- get the number of workdays (excludes weekends) from when the node was created -->
<xsl:value-of select="ucomponents.dates:WorkdaysDiff($currentPage/@createDate, umbraco.library:CurrentDate())" />