PUBLIC - Liferay Portal Community Edition
  1. PUBLIC - Liferay Portal Community Edition
  2. LPS-13580

org.apache.velocity.tools.generic.DateTool.toDate(...) used in templates doesn't work as expected

    Details

    • Similar Issues:
      Show 5 results 

      Description

      Hi, I have used following Velocity template in Liferay 5.1.2 and it prints expected results (returns Date) bud if I try the same in 6.0.5 many of them (with BAD) returns null.
      I'm really not sure what's going on...

        1. Velocity template BEGIN
          $dateTool.toDate("EEE, dd MMM yyyy hh:mm:ss Z" , "Fri, 24 Sep 2010 10:53:00 +0200") BAD<br/>
          $dateTool.toDate("dd MMM yyyy hh:mm:ss Z" , "24 Sep 2010 10:53:00 +0200") BAD<br/>
          $dateTool.toDate("MMM yyyy hh:mm:ss Z" , "Sep 2010 10:53:00 +0200") BAD<br/>
          $dateTool.toDate("yyyy hh:mm:ss Z" , " 2010 10:53:00 +0200") OK<br/>
          $dateTool.toDate("hh:mm:ss Z" , "10:53:00 +0200") OK<br/>
          $dateTool.toDate("dd MM yyyy hh:mm:ss Z" , "05 11 2010 10:53:00 +0200") OK<br/>
          $dateTool.toDate("EEE dd MM yyyy hh:mm:ss Z" , "Fri 05 11 2010 10:53:00 +0200") BAD<br/>
          $dateTool.toDate("EEE, dd MMM yyyy hh:mm:ss" , "Fri, 24 Sep 2010 10:53:00") BAD<br/>
        2. Velocity template END

        Activity

        Hide
        Kristoffer Onias added a comment -

        I'm currently in relay with one of our velocity experts. Can you confirm if this is an issue with velocity? Does velocity support those variables in that locale?
        Thanks!

        Show
        Kristoffer Onias added a comment - I'm currently in relay with one of our velocity experts. Can you confirm if this is an issue with velocity? Does velocity support those variables in that locale? Thanks!
        Hide
        Raymond Auge added a comment -

        The bug appears to be in DateTool which is part of the velocity-tools.jar library.

        When using Liferay's own date parsing utils everything works fine:

        Template:
        #################################################
        #set ($portalBeanLocator = $portal.getClass().forName('com.liferay.portal.kernel.bean.PortalBeanLocatorUtil'))
        #set ($dateFormatFactory = $portalBeanLocator.locate('com.liferay.portal.kernel.util.DateFormatFactoryUtil'))

        #set ($indexFormat = $dateFormatFactory.getSimpleDateFormat('EEE, dd MMM yyyy hh:mm:ss Z'))
        #set ($date = $indexFormat.parse('Fri, 24 Sep 2010 10:53:00 +0200'))
        $indexFormat.format($date)<br/>

        #set ($indexFormat = $dateFormatFactory.getSimpleDateFormat('dd MMM yyyy hh:mm:ss Z'))
        #set ($date = $indexFormat.parse('24 Sep 2010 10:53:00 +0200'))
        $indexFormat.format($date)<br/>

        #set ($indexFormat = $dateFormatFactory.getSimpleDateFormat('MMM yyyy hh:mm:ss Z'))
        #set ($date = $indexFormat.parse('Sep 2010 10:53:00 +0200'))
        $indexFormat.format($date)<br/>

        #set ($indexFormat = $dateFormatFactory.getSimpleDateFormat('yyyy hh:mm:ss Z'))
        #set ($date = $indexFormat.parse('2010 10:53:00 +0200'))
        $indexFormat.format($date)<br/>

        #set ($indexFormat = $dateFormatFactory.getSimpleDateFormat('hh:mm:ss Z'))
        #set ($date = $indexFormat.parse('10:53:00 +0200'))
        $indexFormat.format($date)<br/>

        #set ($indexFormat = $dateFormatFactory.getSimpleDateFormat('dd MM yyyy hh:mm:ss Z'))
        #set ($date = $indexFormat.parse('05 11 2010 10:53:00 +0200'))
        $indexFormat.format($date)<br/>

        #set ($indexFormat = $dateFormatFactory.getSimpleDateFormat('EEE dd MM yyyy hh:mm:ss Z'))
        #set ($date = $indexFormat.parse('Fri 05 11 2010 10:53:00 +0200'))
        $indexFormat.format($date)<br/>

        #set ($indexFormat = $dateFormatFactory.getSimpleDateFormat('EEE, dd MMM yyyy hh:mm:ss'))
        #set ($date = $indexFormat.parse('Fri, 24 Sep 2010 10:53:00'))
        $indexFormat.format($date)<br/>
        #################################################

        Result:
        #################################################
        Fri, 24 Sep 2010 04:53:00 -0400
        24 Sep 2010 04:53:00 -0400
        Sep 2010 04:53:00 -0400
        2010 03:53:00 -0500
        03:53:00 -0500
        05 11 2010 04:53:00 -0400
        Fri 05 11 2010 04:53:00 -0400
        Fri, 24 Sep 2010 10:53:00
        #################################################

        Show
        Raymond Auge added a comment - The bug appears to be in DateTool which is part of the velocity-tools.jar library. When using Liferay's own date parsing utils everything works fine: Template: ################################################# #set ($portalBeanLocator = $portal.getClass().forName('com.liferay.portal.kernel.bean.PortalBeanLocatorUtil')) #set ($dateFormatFactory = $portalBeanLocator.locate('com.liferay.portal.kernel.util.DateFormatFactoryUtil')) #set ($indexFormat = $dateFormatFactory.getSimpleDateFormat('EEE, dd MMM yyyy hh:mm:ss Z')) #set ($date = $indexFormat.parse('Fri, 24 Sep 2010 10:53:00 +0200')) $indexFormat.format($date)<br/> #set ($indexFormat = $dateFormatFactory.getSimpleDateFormat('dd MMM yyyy hh:mm:ss Z')) #set ($date = $indexFormat.parse('24 Sep 2010 10:53:00 +0200')) $indexFormat.format($date)<br/> #set ($indexFormat = $dateFormatFactory.getSimpleDateFormat('MMM yyyy hh:mm:ss Z')) #set ($date = $indexFormat.parse('Sep 2010 10:53:00 +0200')) $indexFormat.format($date)<br/> #set ($indexFormat = $dateFormatFactory.getSimpleDateFormat('yyyy hh:mm:ss Z')) #set ($date = $indexFormat.parse('2010 10:53:00 +0200')) $indexFormat.format($date)<br/> #set ($indexFormat = $dateFormatFactory.getSimpleDateFormat('hh:mm:ss Z')) #set ($date = $indexFormat.parse('10:53:00 +0200')) $indexFormat.format($date)<br/> #set ($indexFormat = $dateFormatFactory.getSimpleDateFormat('dd MM yyyy hh:mm:ss Z')) #set ($date = $indexFormat.parse('05 11 2010 10:53:00 +0200')) $indexFormat.format($date)<br/> #set ($indexFormat = $dateFormatFactory.getSimpleDateFormat('EEE dd MM yyyy hh:mm:ss Z')) #set ($date = $indexFormat.parse('Fri 05 11 2010 10:53:00 +0200')) $indexFormat.format($date)<br/> #set ($indexFormat = $dateFormatFactory.getSimpleDateFormat('EEE, dd MMM yyyy hh:mm:ss')) #set ($date = $indexFormat.parse('Fri, 24 Sep 2010 10:53:00')) $indexFormat.format($date)<br/> ################################################# Result: ################################################# Fri, 24 Sep 2010 04:53:00 -0400 24 Sep 2010 04:53:00 -0400 Sep 2010 04:53:00 -0400 2010 03:53:00 -0500 03:53:00 -0500 05 11 2010 04:53:00 -0400 Fri 05 11 2010 04:53:00 -0400 Fri, 24 Sep 2010 10:53:00 #################################################
        Hide
        Cynthia Wilburn (Inactive) added a comment -

        Updating affected version from 6.0.5 to 6.0.6. Key issues that were closed in 6.0.6 are in the 6.0.6 release notes.

        Show
        Cynthia Wilburn (Inactive) added a comment - Updating affected version from 6.0.5 to 6.0.6. Key issues that were closed in 6.0.6 are in the 6.0.6 release notes.
        Hide
        Kristoffer Onias added a comment -

        Hello Milan,
        This issue has been inactive for quite some time. If you still experience any issues please open another ticket.

        Thanks!

        Show
        Kristoffer Onias added a comment - Hello Milan, This issue has been inactive for quite some time. If you still experience any issues please open another ticket. Thanks!
        Hide
        Milan Jaroš added a comment -

        Hello,
        OK. I hope it is resolved by usage of Liferay's own date utils.

        Kind regards,
        Milan

        Show
        Milan Jaroš added a comment - Hello, OK. I hope it is resolved by usage of Liferay's own date utils. Kind regards, Milan

          People

          • Votes:
            2 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:
              Days since last comment:
              3 years, 21 weeks, 2 days ago

              Development

                Structure Helper Panel