NIHVIVO-1591 Apply datetime functions and macros in lib-datetime.ftl to propStatement views

This commit is contained in:
rjy7 2011-01-10 03:10:08 +00:00
parent 752e50dce0
commit ad1a8c4e56

View file

@ -1,47 +1,40 @@
<#-- $This file is distributed under the terms of the license in /doc/license.txt$ --> <#-- $This file is distributed under the terms of the license in /doc/license.txt$ -->
<#-- Macros for datetime formatting --> <#-- Macros and functions for datetime formatting -->
<#-- Macro yearInterval <#-- Convenience macros to display year and year interval attributes in a classed span -->
<#macro yearSpan dateTime>
<#if dateTime?has_content>
<span class="listDateTime">${xsdDateTimeToYear(dateTime)}</span>
</#if>
</#macro>
Display a year interval in a property statement <#macro yearIntervalSpan startDateTime endDateTime endYearAsRange=true>
<#local yearInterval = yearInterval(startDateTime, endDateTime, endYearAsRange)>
Set endYearAsRange=false to display an end year without a start year without a preceding hyphen. The hyphen indicates that
a range is expected but the start year is not provided (e.g., core:personInPosition); no hyphen indicates that
a single date is typical (e.g., core:educationalTraining).
-->
<#macro yearInterval startDateTime endDateTime endYearAsRange=true>
<#local yearInterval>
<#if startDateTime?has_content>
<#local startYear = xsdDateTimeToYear(startDateTime)>
</#if>
<#if endDateTime?has_content>
<#local endYear = xsdDateTimeToYear(endDateTime)>
</#if>
<#if startYear?? && endYear??>
${startYear} - ${endYear}
<#elseif startYear??>
${startYear} -
<#elseif endYear ??>
<#if endYearAsRange>- </#if>${endYear}
</#if>
</#local>
<#if yearInterval?has_content> <#if yearInterval?has_content>
<span class="listDateTime">${yearInterval}</span> <span class="listDateTime">${yearInterval}</span>
</#if> </#if>
</#macro> </#macro>
<#macro dateTimeIntervalLong dateTimeStart precisionStart dateTimeEnd precisionEnd endAsRange=true>
<@dateTimeInterval dateTimeStart precisionStart dateTimeEnd precisionEnd "long" endAsRange />
</#macro>
<#macro dateTimeIntervalShort dateTimeStart precisionStart dateTimeEnd precisionEnd endAsRange=true> <#-- Assign a year precision and generate the interval -->
<@dateTimeInterval dateTimeStart precisionStart dateTimeEnd precisionEnd "short" endAsRange /> <#function yearInterval dateTimeStart dateTimeEnd endYearAsRange=true>
</#macro> <#local precision = "yearPrecision">
<#return dateTimeIntervalShort(dateTimeStart, precision, dateTimeEnd, precision, endYearAsRange)>
</#function>
<#macro dateTimeInterval dateTimeStart precisionStart dateTimeEnd precisionEnd view="short" endAsRange=true> <#-- Generate a datetime interval with dates displayed as "January 1, 2011" -->
<#function dateTimeIntervalLong dateTimeStart precisionStart dateTimeEnd precisionEnd endAsRange=true>
<#return dateTimeInterval(dateTimeStart, precisionStart, dateTimeEnd, precisionEnd, "long", endAsRange) >
</#function>
<#-- Generate a datetime interval with dates displayed as "1/1/2011" -->
<#function dateTimeIntervalShort dateTimeStart precisionStart dateTimeEnd precisionEnd endAsRange=true>
<#return dateTimeInterval(dateTimeStart, precisionStart, dateTimeEnd, precisionEnd, "short", endAsRange)>
</#function>
<#-- Generate a datetime interval -->
<#function dateTimeInterval dateTimeStart precisionStart dateTimeEnd precisionEnd view="short" endAsRange=true>
<#if dateTimeStart?has_content> <#if dateTimeStart?has_content>
<#local start = formatXsdDateTime(dateTimeStart, precisionStart, view)> <#local start = formatXsdDateTime(dateTimeStart, precisionStart, view)>
@ -61,10 +54,8 @@
</#if> </#if>
</#local> </#local>
<#if interval?has_content> <#return interval>
${interval} </#function>
</#if>
</#macro>
<#-- Functions for formatting and applying precision to a datetime <#-- Functions for formatting and applying precision to a datetime
@ -72,26 +63,37 @@
implementation; see NIHVIVO-1567. We want the Java code to apply the precision to the datetime string to pass only the implementation; see NIHVIVO-1567. We want the Java code to apply the precision to the datetime string to pass only the
meaningful data to the templates. The templates can format as they like, so these functions/macros would do display formatting meaningful data to the templates. The templates can format as they like, so these functions/macros would do display formatting
but not data extraction. but not data extraction.
On the other hand, this is so easy that it may not be worth re-implementing to gain a bit more MVC compliance.
--> -->
<#-- Generate a datetime with date formatted as "January 1, 2011" -->
<#function formatXsdDateTimeLong dateTime precision>
<#return formatXsdDateTime(dateTime, precision, "long")>
</#function>
<#-- Generate a datetime with date formatted as "1/1/2011" -->
<#function formatXsdDateTimeShort dateTime precision>
<#return formatXsdDateTime(dateTime, precision)>
</#function>
<#-- Generate a datetime as a year -->
<#function xsdDateTimeToYear dateTime>
<#local precision = "yearPrecision">
<#return formatXsdDateTime(dateTime, precision)>
</#function>
<#-- Convert the string dateTimeString to a datetime object -->
<#function toDateTime dateTimeString> <#function toDateTime dateTimeString>
<#-- First convert the datetime string to a string format that Freemarker <#-- First convert the datetime string to a string format that Freemarker
understands, then to a datetime object --> understands, then to a datetime object -->
<#return dateTimeString?replace("T", " ")?replace("Z", "")?datetime("yyyy-MM-dd HH:mm:ss")> <#return dateTimeString?replace("T", " ")?replace("Z", "")?datetime("yyyy-MM-dd HH:mm:ss")>
</#function> </#function>
<#function formatXsdDateTimeLong dateTime precision> <#-- Apply a precision and view to format a datetime -->
<#return formatXsdDateTime(dateTime, precision, "long")>
</#function>
<#function formatXsdDateTimeShort dateTime precision>
<#return formatXsdDateTime(dateTime, precision)>
</#function>
<#function formatXsdDateTime dateTime precision view="short"> <#function formatXsdDateTime dateTime precision view="short">
<#-- Convert to a string format that Freemarker understands, <#-- First convert the string dateTime to a datetime object -->
then to a datetime -->
<#local dt = toDateTime(dateTime)> <#local dt = toDateTime(dateTime)>
<#-- Use the precision to determine which portion to display, <#-- Use the precision to determine which portion to display,
@ -115,11 +117,4 @@
<#return dt?string(format)> <#return dt?string(format)>
</#function> </#function>
<#-- Function xsdDateTimeToYear -->
<#-- get rid of this -->
<#function xsdDateTimeToYear datetime>
<#local format = "yyyy">
<#return datetime?date(format)?string(format)>
</#function>