Skip to main content
Inspiring
March 8, 2022
Answered

CreateDate() failing for Mon Feb 29 17:00:00 AEDT 2016

  • March 8, 2022
  • 2 replies
  • 270 views

CreateDate() works for other Feb dates in the system except this leap day.

 

Local.TempDate = ExecutedSearch["datefield_dt"][Local.i]; /* Mon Feb 29 17:00:00 AEDT 2016 */
Local.TempDate = CreateDate(Right(ExecutedSearch["datefield_dt"][Local.i], 4), Month(Local.TempDate), Day(Local.TempDate));

 

Has anyone come across this before?  I cannot imagine a mature language has a leap year bug.  Is there a workaround?

 

Thank you

Brent

 

    This topic has been closed for replies.
    Correct answer BKBK

    The problem has a very likely cause. ColdFusion does not recognize the value of Local.TempDate as a valid date.

     

    However a neat solution is possible. May we assume that the searched date is always going to be of the following form? 

     

     

    Mon Feb 29 17:00:00 AEDT 2016

     

     

    If so, then I will suggest a solution that has reuse potential.

     

    DateFromSearch.cfc

     

    component {
    	public any function init (string inputDate) output=false {
    		/* Argument of the form: Mon Feb 29 17:00:00 AEDT 2016 */
    		/* In the functions below, treat date string as list with delimiter " " */
    		variables.dateAsString=arguments.inputDate;
    		
    		return this;
    	}
    	
    	public numeric function getDay() output=false {	
    		var d=listGetAt(variables.dateAsString,3," ");
    		
    		return d;
    	}
    	
    	public numeric function getMonth() output=false {
    		var monthAsString=lcase(listGetAt(variables.dateAsString,2," "));
    		var mnth=0; // initialize
    		
    		switch(monthAsString) { 
    			 case "jan": 
    				 mnth=1; 
    				 break; 
    			 case "feb": 
    			 	 mnth=2; 
    				 break; 
    			 case "mar": 
    			 	 mnth=3; 
    				 break; 
    			 case "apr": 
    				 mnth=4; 
    				 break; 
    			 case "may": 
    			 	 mnth=5; 
    				 break; 
    			 case "jun": 
    			 	 mnth=6; 
    				 break; 
    			 case "jul": 
    				 mnth=7; 
    				 break; 
    			 case "aug": 
    			 	 mnth=8; 
    				 break; 
    			 case "sep": 
    			 	 mnth=9; 
    				 break; 
    			 case "oct": 
    				 mnth=10; 
    				 break; 
    			 case "nov": 
    			 	 mnth=11; 
    				 break; 
    			 case "dec": 
    			 	 mnth=12; 
    				 break; 
    		} 
    		
    		return mnth;
    	}
    	
    	public numeric function getYear() output=false {
    		var yr=listLast(variables.dateAsString," ");
    		
    		return yr;	
    	}
    }

     

     

    testpage.cfm (in same directory as the CFC)

     

    <cfscript>
        Local.TempDate = ExecutedSearch["datefield_dt"][Local.i]; /* Mon Feb 29 17:00:00 AEDT 2016 */
        dateObj = new DateFromSearch(Local.TempDate) ;
         Local.TempDate = createdate(dateObj.getYear(),dateObj.getMonth(),dateObj.getDay());
    </cfscript>

     

     

    2 replies

    BKBK
    Community Expert
    BKBKCommunity ExpertCorrect answer
    Community Expert
    March 9, 2022

    The problem has a very likely cause. ColdFusion does not recognize the value of Local.TempDate as a valid date.

     

    However a neat solution is possible. May we assume that the searched date is always going to be of the following form? 

     

     

    Mon Feb 29 17:00:00 AEDT 2016

     

     

    If so, then I will suggest a solution that has reuse potential.

     

    DateFromSearch.cfc

     

    component {
    	public any function init (string inputDate) output=false {
    		/* Argument of the form: Mon Feb 29 17:00:00 AEDT 2016 */
    		/* In the functions below, treat date string as list with delimiter " " */
    		variables.dateAsString=arguments.inputDate;
    		
    		return this;
    	}
    	
    	public numeric function getDay() output=false {	
    		var d=listGetAt(variables.dateAsString,3," ");
    		
    		return d;
    	}
    	
    	public numeric function getMonth() output=false {
    		var monthAsString=lcase(listGetAt(variables.dateAsString,2," "));
    		var mnth=0; // initialize
    		
    		switch(monthAsString) { 
    			 case "jan": 
    				 mnth=1; 
    				 break; 
    			 case "feb": 
    			 	 mnth=2; 
    				 break; 
    			 case "mar": 
    			 	 mnth=3; 
    				 break; 
    			 case "apr": 
    				 mnth=4; 
    				 break; 
    			 case "may": 
    			 	 mnth=5; 
    				 break; 
    			 case "jun": 
    			 	 mnth=6; 
    				 break; 
    			 case "jul": 
    				 mnth=7; 
    				 break; 
    			 case "aug": 
    			 	 mnth=8; 
    				 break; 
    			 case "sep": 
    			 	 mnth=9; 
    				 break; 
    			 case "oct": 
    				 mnth=10; 
    				 break; 
    			 case "nov": 
    			 	 mnth=11; 
    				 break; 
    			 case "dec": 
    			 	 mnth=12; 
    				 break; 
    		} 
    		
    		return mnth;
    	}
    	
    	public numeric function getYear() output=false {
    		var yr=listLast(variables.dateAsString," ");
    		
    		return yr;	
    	}
    }

     

     

    testpage.cfm (in same directory as the CFC)

     

    <cfscript>
        Local.TempDate = ExecutedSearch["datefield_dt"][Local.i]; /* Mon Feb 29 17:00:00 AEDT 2016 */
        dateObj = new DateFromSearch(Local.TempDate) ;
         Local.TempDate = createdate(dateObj.getYear(),dateObj.getMonth(),dateObj.getDay());
    </cfscript>

     

     

    Inspiring
    March 9, 2022

    Thanks, BKBK.  CF natively works for every date in the same format except Feb 29, 2016.  I added test data which fail on Feb 29, 2012 and Feb 29, 2020.  I used your getDay and getMonth functions with success.  Thank you.

    BKBK
    Community Expert
    Community Expert
    March 9, 2022

    You are right, @brents78709329 . There is something not quite right about that. Why should 

     

    Sun Feb 28 17:00:00 AEDT 2016

     

    work but

     

    Mon Feb 29 17:00:00 AEDT 2016

     

    lead to an error?

    I have submitted a bug report on validation of February 29.

    Inspiring
    March 8, 2022

    Message: Specify a valid date in createDateTime function.

    Detail: Date value passed to date function createDateTime is unspecified or invalid. 


    at coldfusion.util.DateUtils.createDateTime(DateUtils.java:1507) at coldfusion.runtime.CFDateTimeParser.toDateTime(CFDateTimeParser.java:592) at coldfusion.runtime.CFDateTimeParser.parseTime(CFDateTimeParser.java:392) at coldfusion.runtime.CFDateTimeParser._parseDateTime(CFDateTimeParser.java:165) at coldfusion.runtime.CFDateTimeParser.parseDateTime(CFDateTimeParser.java:88) at coldfusion.runtime.Cast._Date(Cast.java:1505) at coldfusion.runtime.Cast._Date(Cast.java:1419) at coldfusion.runtime.Cast._Date(Cast.java:1549) at cfsearch2dfunctions2dsolr2ecfml1345621940$funcEXECUTESEARCH.runFunction(C:\home\urbanaffairs-stage.com.au\wwwroot\_\includes\search-functions-solr.cfml:234) at coldfusion.runtime.UDFMethod.invoke(UDFMethod.java:623) at coldfusion.runtime.UDFMethod$ArgumentCollectionFilter.invoke(UDFMethod.java:516) at coldfusion.filter.FunctionAccessFilter.invoke(FunctionAccessFilter.java:95) at coldfusion.runtime.UDFMethod.runFilterChain(UDFMethod.java:463) at coldfusion.runtime.UDFMethod.runFilterChain(UDFMethod.java:438) at coldfusion.runtime.UDFMethod.invoke(UDFMethod.java:310) at coldfusion.runtime.CfJspPage._invokeUDF(CfJspPage.java:5011) at coldfusion.runtime.CfJspPage._invokeUDF(CfJspPage.java:4991) at cfsearch2ecfml246464043._factor25(C:\home\urbanaffairs-stage.com.au\wwwroot\search\search.cfml:125) at cfsearch2ecfml246464043._factor28(C:\home\urbanaffairs-stage.com.au\wwwroot\search\search.cfml:113) at cfsearch2ecfml246464043._factor29(C:\home\urbanaffairs-stage.com.au\wwwroot\search\search.cfml:29) at cfsearch2ecfml246464043.runPage(C:\home\urbanaffairs-stage.com.au\wwwroot\search\search.cfml:1) at coldfusion.runtime.CfJspPage.invoke(CfJspPage.java:257) at coldfusion.tagext.lang.IncludeTag.handlePageInvoke(IncludeTag.java:749) at coldfusion.tagext.lang.IncludeTag.doStartTag(IncludeTag.java:578) at coldfusion.runtime.CfJspPage._emptyTcfTag(CfJspPage.java:5201) at cfApplication2ecfc528976928$funcONREQUEST._factor4(C:\home\urbanaffairs-stage.com.au\wwwroot\Application.cfc:173) at cfApplication2ecfc528976928$funcONREQUEST.runFunction(C:\home\urbanaffairs-stage.com.au\wwwroot\Application.cfc:78) at coldfusion.runtime.UDFMethod.invoke(UDFMethod.java:623) at coldfusion.runtime.UDFMethod$ReturnTypeFilter.invoke(UDFMethod.java:553) at coldfusion.runtime.UDFMethod$ArgumentCollectionFilter.invoke(UDFMethod.java:516) at coldfusion.filter.FunctionAccessFilter.invoke(FunctionAccessFilter.java:95) at coldfusion.runtime.UDFMethod.runFilterChain(UDFMethod.java:463) at coldfusion.runtime.UDFMethod.runFilterChain(UDFMethod.java:438) at coldfusion.runtime.UDFMethod.invoke(UDFMethod.java:310) at coldfusion.runtime.TemplateProxy.invoke(TemplateProxy.java:975) at coldfusion.runtime.TemplateProxy.invoke(TemplateProxy.java:696) at coldfusion.runtime.TemplateProxy.invoke(TemplateProxy.java:503) at coldfusion.runtime.AppEventInvoker.invoke(AppEventInvoker.java:115) at coldfusion.runtime.AppEventInvoker.onRequest(AppEventInvoker.java:308) at coldfusion.filter.ApplicationFilter.invoke(ApplicationFilter.java:569) at coldfusion.filter.RequestMonitorFilter.invoke(RequestMonitorFilter.java:43) at coldfusion.filter.MonitoringFilter.invoke(MonitoringFilter.java:40) at coldfusion.filter.PathFilter.invoke(PathFilter.java:162) at coldfusion.filter.IpFilter.invoke(IpFilter.java:45) at coldfusion.filter.ExceptionFilter.invoke(ExceptionFilter.java:97) at coldfusion.filter.ClientScopePersistenceFilter.invoke(ClientScopePersistenceFilter.java:28) at coldfusion.filter.BrowserFilter.invoke(BrowserFilter.java:38) at coldfusion.filter.NoCacheFilter.invoke(NoCacheFilter.java:60) at coldfusion.filter.GlobalsFilter.invoke(GlobalsFilter.java:38) at coldfusion.filter.DatasourceFilter.invoke(DatasourceFilter.java:22) at coldfusion.filter.CachingFilter.invoke(CachingFilter.java:62) at coldfusion.CfmServlet.service(CfmServlet.java:231) at coldfusion.bootstrap.BootstrapServlet.service(BootstrapServlet.java:311) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:228) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:163) at coldfusion.monitor.event.MonitoringServletFilter.doFilter(MonitoringServletFilter.java:46) at coldfusion.bootstrap.BootstrapFilter.doFilter(BootstrapFilter.java:47) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:190) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:163) at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:190) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:163) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:202) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:97) at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:542) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:143) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:92) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:78) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:373) at org.apache.coyote.ajp.AjpProcessor.service(AjpProcessor.java:462) at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:65) at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:893) at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1723) at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49) at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128) at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628) at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) at java.base/java.lang.Thread.run(Thread.java:834)