parseDateTime() can't parse a valid string when using a pattern

Description

<cfset timeStamp = "2018-01-04-23.40.56"> <cfset newTimeStamp = parseDateTime(timeStamp, "yyyy-MM-dd-HH.nn.ss")> <cfoutput>#newTimeStamp#</cfoutput>

I know this is a bit of an unconventional format - but this is what I have to work with and this is why I am providing the pattern describing my expected format.

I also tried it with single quotes around the dash between the date and time parts:
"yyyy-MM-dd'-'HH.nn.ss"

as well as using "mm" for minutes:
""yyyy-MM-dd'-'HH.mm.ss"

In all cases I get

"can't cast value [2018-01-04-23.40.56] to a Date Object"

error

Using "nn" for minutes works in ACF and produces correct output:

{ts '2018-01-04 23:40:56'}

(according to http://cflive.net)

Stacktrace:

lucee.runtime.exp.ExpressionException: can't cast value [2018-01-04-23.40.56] to a Date Object
at lucee.runtime.op.date.DateCaster.toDateAdvanced(DateCaster.java:486)
at lucee.runtime.functions.string.ParseDateTime._call(ParseDateTime.java:45)
at lucee.runtime.functions.string.ParseDateTime.call(ParseDateTime.java:39)
at _34f00148_ba4f_4c58_a76deba685b01720_cfm1890$cf.call(/code/34F00148-BA4F-4C58-A76DEBA685B01720.cfm:11)
at lucee.runtime.PageContextImpl._doInclude(PageContextImpl.java:893)
at lucee.runtime.PageContextImpl._doInclude(PageContextImpl.java:838)
at lucee.runtime.listener.ClassicAppListener._onRequest(ClassicAppListener.java:63)
at lucee.runtime.listener.MixedAppListener.onRequest(MixedAppListener.java:44)
at lucee.runtime.PageContextImpl.execute(PageContextImpl.java:2394)
at lucee.runtime.PageContextImpl._execute(PageContextImpl.java:2385)
at lucee.runtime.PageContextImpl.executeCFML(PageContextImpl.java:2353)
at lucee.runtime.engine.CFMLEngineImpl.serviceCFML(CFMLEngineImpl.java:917)
at lucee.loader.engine.CFMLEngineWrapper.serviceCFML(CFMLEngineWrapper.java:102)
at lucee.loader.servlet.CFMLServlet.service(CFMLServlet.java:62)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:292)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:240)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:212)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:141)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:528)
at org.apache.coyote.ajp.AbstractAjpProcessor.process(AbstractAjpProcessor.java:872)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:672)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1520)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1476)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Thread.java:745)

Environment

I tested this on http://cflive.net which runs Lucee 5.1.3.18 as well as on our Windows Server 2012 R2 which runs Lucee 5.2.2.71

Attachments

1
  • 12 Jan 2018, 03:13 pm

Activity

Show:

Marianna Shvartsapel 26 January 2018 at 23:32

Yes, thank you. Good to know!

That's what I ended up using when I couldn't get ParseDateTime() to work.

Michael Offner 26 January 2018 at 07:27

also consider to use "lsParseDateTime" instead for new functionality.
The regular date function care the legacy of being compatible to US specific dates, the newer "ls" date functions are a lot cleaner approach.

Marianna Shvartsapel 25 January 2018 at 15:51

Thank you so much Michael!

Pothys - MitrahSoft 22 January 2018 at 11:19
Edited

Hi ,

I've adapt above possibility in test case .

Pull request: https://github.com/lucee/Lucee/pull/374

Fixed

Details

Assignee

Reporter

Priority

Fix versions

New Issue warning screen

Before you create a new Issue, please post to the mailing list first https://dev.lucee.org

Once the issue has been verified, one of the Lucee team will ask you to file an issue

Sprint

Affects versions

Created 11 January 2018 at 22:26
Updated 1 February 2018 at 16:37
Resolved 25 January 2018 at 14:05

Flag notifications