I was given code that uses the dateTimeFormat function. The original developer used a mask of "MM-HH-YY-dd-NN". This code works on his machine. And it works on our test server. But it does not work on my local machine. I can only make it work when I change the mask to "MM-HH-yy-dd-NN";
Note the difference here is the upper case "YY" and the lower case "yy"
In looking at the documentation at https://wikidocs.adobe.com/wiki/display/coldfusionen/DateTimeFormat it looks like lower case yy is the officially supported way of doing things.
Does anyone know why YY would be supported in some situations and not others? I suspect it may be some localization code somewhere, but I'm not finding any differences in my CF admin and the one on the test server. Is there something I can do on my machine to make the YY work?
My machine is a Windows 7 VM running on Mac while the server is a Windows server 2008.
My JVM is 1.6.0_29 while the server is running 1.7.0
Are these differences sufficient to explain the issue?
Here is some simple code for test:
<cfscript>
testTime=now();
lowermask= "MM-HH-yy-dd-NN";
uppermask= "MM-HH-YY-dd-NN";
result = {
lower=dateTimeFormat(testTime, lowermask)
,upper=dateTimeFormat(testTime, uppermask)
};
writedump(result);
</cfscript>
It looks like the problem is in the underlying Java version. The error I get is:
java.lang.IllegalArgumentException: Illegal pattern character 'Y'
at java.text.SimpleDateFormat.compile(SimpleDateFormat.java:768)
at java.text.SimpleDateFormat.initialize(SimpleDateFormat.java:575)
at java.text.SimpleDateFormat.<init>(SimpleDateFormat.java:500)
at coldfusion.util.DateUtils.getCFDateTimeFormat(DateUtils.java:673)
at coldfusion.util.DateUtils.formatDateTime(DateUtils.java:942)
at coldfusion.runtime.CFPage.LSDateTimeFormat(CFPage.java:1750)
at coldfusion.runtime.CFPage.LSDateTimeFormat(CFPage.java:1742)
at coldfusion.runtime.CFPage.DateTimeFormat(CFPage.java:1722)
at cftemp2ecfm333879290.runPage(C:\inetpub\wwwroot\temp.cfm:7)
at coldfusion.runtime.CfJspPage.invoke(CfJspPage.java:244)
at coldfusion.tagext.lang.IncludeTag.doStartTag(IncludeTag.java:444)
at coldfusion.filter.CfincludeFilter.invoke(CfincludeFilter.java:65)
at coldfusion.filter.IpFilter.invoke(IpFilter.java:64)
at coldfusion.filter.ApplicationFilter.invoke(ApplicationFilter.java:449)
at coldfusion.filter.MonitoringFilter.invoke(MonitoringFilter.java:40)
at coldfusion.filter.PathFilter.invoke(PathFilter.java:112)
at coldfusion.filter.ExceptionFilter.invoke(ExceptionFilter.java:94)
at coldfusion.filter.BrowserDebugFilter.invoke(BrowserDebugFilter.java:79)
at coldfusion.filter.ClientScopePersistenceFilter.invoke(ClientScopePersistenceFilter.java:28)
at coldfusion.filter.BrowserFilter.invoke(BrowserFilter.java:38)
at coldfusion.filter.NoCacheFilter.invoke(NoCacheFilter.java:58)
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:219)
at coldfusion.bootstrap.BootstrapServlet.service(BootstrapServlet.java:89)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at coldfusion.monitor.event.MonitoringServletFilter.doFilter(MonitoringServletFilter.java:42)
at coldfusion.bootstrap.BootstrapFilter.doFilter(BootstrapFilter.java:46)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:224)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:169)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:168)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:928)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:414)
at org.apache.coyote.ajp.AjpProcessor.process(AjpProcessor.java:204)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:539)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:298)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
at java.lang.Thread.run(Thread.java:662)
Java has changed. ColdFusion doesn't care. It passes the mask argument straight through.
Java 6 docs say it supports only y
Java 7 docs say it supports both y
and Y
A few highlights from the Java 7 docs
Capital
Y
is a "week year"A week year is in sync with a
WEEK_OF_YEAR
cycle. All weeks between the first and last weeks (inclusive) have the same week year value. Therefore, the first and last days of a week year may have different calendar year values.If week year
'Y'
is specified and the calendar doesn't support any week years, the calendar year ('y'
) is used instead.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With