From: <fg...@us...> - 2010-01-20 14:39:37
|
Revision: 1689 http://openutils.svn.sourceforge.net/openutils/?rev=1689&view=rev Author: fgiust Date: 2010-01-20 14:39:29 +0000 (Wed, 20 Jan 2010) Log Message: ----------- cleaned up dateutils Modified Paths: -------------- trunk/magnolia-test-webapp/src/main/webapp/docroot/dateutils-test.jsp trunk/openutils-elfunctions/src/main/java/net/sourceforge/openutils/elfunctions/DateElUtils.java trunk/openutils-elfunctions/src/main/resources/META-INF/dateutils.tld trunk/openutils-elfunctions/src/test/resources/jsps/formatInterval.jsp Modified: trunk/magnolia-test-webapp/src/main/webapp/docroot/dateutils-test.jsp =================================================================== --- trunk/magnolia-test-webapp/src/main/webapp/docroot/dateutils-test.jsp 2010-01-20 14:11:07 UTC (rev 1688) +++ trunk/magnolia-test-webapp/src/main/webapp/docroot/dateutils-test.jsp 2010-01-20 14:39:29 UTC (rev 1689) @@ -12,7 +12,7 @@ .function { border: 1px solid #ccc; padding: 20px; - } + } .sampleresult { color: red; } @@ -61,9 +61,9 @@ <div class="function"> <h2>formatInterval</h2> <p>format a milliseconds interval as a string like 523h 22m 18s</p> - <div class="sampletext">java.lang.String formatInterval(java.lang.Long, java.lang.Boolean) + <div class="sampletext">java.lang.String formatInterval(java.lang.Long) </div> - <div class="sampleresult">formatInterval(63076234017000,true): ${du:formatInterval(63076234017000,true)}</div> + <div class="sampleresult">formatInterval(63076234017000,true): ${du:formatInterval(63076234017000)}</div> </div> <div class="function"> <h2>getMillisFromNow</h2> Modified: trunk/openutils-elfunctions/src/main/java/net/sourceforge/openutils/elfunctions/DateElUtils.java =================================================================== --- trunk/openutils-elfunctions/src/main/java/net/sourceforge/openutils/elfunctions/DateElUtils.java 2010-01-20 14:11:07 UTC (rev 1688) +++ trunk/openutils-elfunctions/src/main/java/net/sourceforge/openutils/elfunctions/DateElUtils.java 2010-01-20 14:39:29 UTC (rev 1689) @@ -30,6 +30,7 @@ /** + * Utility methods for date/time handling mapped to EL functions to allow usage in jsp pages. * @author fgiust * @version $Id$ */ @@ -42,12 +43,12 @@ private static Logger log = LoggerFactory.getLogger(DateElUtils.class); /** - * internal constant value to indicate no builtin format was found for the input pattern + * internal constant value to indicate no built-in format was found for the input pattern * @see {@link FastDateFormat} */ private static final int NO_FORMAT = -1337; - // constants to support builtin date and time formatting + // constants to support built-in date and time formatting private static final String FORMAT_SHORT = "short"; private static final String FORMAT_MEDIUM = "medium"; @@ -88,12 +89,12 @@ } /** - * internal utility method to format dates attempting builtin styles first, and then resorting to + * internal utility method to format dates attempting built-in styles first, and then resorting to * {@link FastDateFormat#getInstance(String)} * @param dateTime the date and time to format - * @param pattern the format pattern, or one (or two) of the builtin styles - * @param date true to format the date part with the builtin style - * @param time false to format the time part with the builtin style + * @param pattern the format pattern, or one (or two) of the built-in styles + * @param date true to format the date part with the built-in style + * @param time false to format the time part with the built-in style * @param locale formatter locale, default locale if null * @return the formatted date, or the empty string if dateTime was null or pattern was blank */ @@ -142,7 +143,7 @@ } /** - * formats a date using the given pattern or builtin style + * formats a date using the given pattern or built-in style * @param date the date to format * @param pattern a valid pattern, or one of "short", "medium", "long", "full" (case insensitive) * @return the formatted date @@ -153,7 +154,7 @@ } /** - * formats a time using the given pattern or builtin style + * formats a time using the given pattern or built-in style * @param time the time to format * @param pattern a valid pattern, or one of "short", "medium", "long", "full" (case insensitive) * @return the formatted time @@ -164,7 +165,7 @@ } /** - * Formats a date and/or time using the given pattern or builtin style - supports composite formats for date and + * Formats a date and/or time using the given pattern or built-in style - supports composite formats for date and * time with the syntax "date_format;time_format" (ex: "long;short") * @param dateTime the date and time * @param pattern date pattern @@ -176,7 +177,7 @@ } /** - * Formats a date and/or time using the given pattern or builtin style - supports composite formats for date and + * Formats a date and/or time using the given pattern or built-in style - supports composite formats for date and * time with the syntax "date_format;time_format" (ex: "long;short") with locale * @param dateTime the date and time * @param languageId lowercase two-letter ISO-639 code. @@ -191,11 +192,11 @@ /** * format a milliseconds interval as a string like 1y 2d 23h 22m 18s (year estimation approximates to 365 days) * @param millisInterval the interval in milliseconds - * @param isDuration isduration * @return the formatted string */ - public static String formatInterval(Long millisInterval, Boolean isDuration) + public static String formatInterval(Long millisInterval) { + if (millisInterval == null) { return StringUtils.EMPTY; @@ -207,79 +208,30 @@ long minutes = (secondsInterval % (60 * 60)) / 60; long seconds = secondsInterval % 60; StringBuilder out = new StringBuilder(); - if (isDuration) + + if (years > 0) { - if (years > 0) - { - out.append(years).append("y "); - } - if (days > 0) - { - out.append(days).append("d "); - } - if (hours > 0) - { - out.append(hours).append("h "); - } - if (minutes > 0) - { - out.append(minutes).append("m "); - } - out.append(seconds).append('s'); + out.append(years).append("y "); } - else + if (days > 0) { - if (years > 0) - { - if (years == 1) - { - out.append(years).append(" anno fa"); - } - else - { - out.append(years).append(" anni fa"); - } - } - else if (days > 0) - { - if (days == 1) - { - out.append(days).append(" giorno fa"); - } - else - { - out.append(days).append(" giorni fa"); - } - } - else if (hours > 0) - { - if (hours == 1) - { - out.append(hours).append(" ora fa"); - } - else - { - out.append(hours).append(" ore fa"); - } - } - else if (minutes > 0) - { - if (minutes == 1) - { - out.append(minutes).append(" minuto fa"); - } - else - { - out.append(minutes).append(" minuti fa"); - } - } - + out.append(days).append("d "); } + if (hours > 0) + { + out.append(hours).append("h "); + } + if (minutes > 0) + { + out.append(minutes).append("m "); + } + out.append(seconds).append('s'); + return out.toString(); } /** - * retrieve the milliseconds in difference between now and the input date + * Retrieve the milliseconds in difference between now and the input date * @param date the date * @return positive value for dates older than now */ @@ -318,7 +270,7 @@ /** * parse a date with a XSD pattern (YYYY-MM-DDThh:mm:ss) and return the parsed date as as a calendar object - * @param date the date string + * @param xsdDate the date string in the format "YYYY-MM-DDThh:mm:ss" * @return the parsed date as a Calendar */ public static Calendar parseXsdDate(String xsdDate) @@ -340,7 +292,6 @@ return cal; } - /** * Given a Calendar, returns a new calendar with same day and hh:mm:ss:mm set to 00:00:00:00 * @param calendar the calendar Modified: trunk/openutils-elfunctions/src/main/resources/META-INF/dateutils.tld =================================================================== --- trunk/openutils-elfunctions/src/main/resources/META-INF/dateutils.tld 2010-01-20 14:11:07 UTC (rev 1688) +++ trunk/openutils-elfunctions/src/main/resources/META-INF/dateutils.tld 2010-01-20 14:39:29 UTC (rev 1689) @@ -41,7 +41,7 @@ <name>formatInterval</name> <description>format a milliseconds interval as a string like 523h 22m 18s</description> <function-class>net.sourceforge.openutils.elfunctions.DateElUtils</function-class> - <function-signature>java.lang.String formatInterval(java.lang.Long, java.lang.Boolean)</function-signature> + <function-signature>java.lang.String formatInterval(java.lang.Long)</function-signature> </function> <function> <name>getMillisFromNow</name> Modified: trunk/openutils-elfunctions/src/test/resources/jsps/formatInterval.jsp =================================================================== --- trunk/openutils-elfunctions/src/test/resources/jsps/formatInterval.jsp 2010-01-20 14:11:07 UTC (rev 1688) +++ trunk/openutils-elfunctions/src/test/resources/jsps/formatInterval.jsp 2010-01-20 14:39:29 UTC (rev 1689) @@ -1,5 +1,5 @@ <jsp:root version="2.0" xmlns:jsp="http://java.sun.com/JSP/Page" xmlns:du="dateutils" > <jsp:directive.page import="java.util.Calendar" /> <jsp:scriptlet>Calendar datadefault = Calendar.getInstance(); datadefault.set(11,03,2,12,45,22);request.setAttribute("datadefault", datadefault);</jsp:scriptlet> - <jsp:text>${du:formatInterval(63076234017000,true)}</jsp:text> + <jsp:text>${du:formatInterval(63076234017000)}</jsp:text> </jsp:root> \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |