Created
December 8, 2020 19:48
-
-
Save trycf/487102da03bd95ba2bb9a093046243d7 to your computer and use it in GitHub Desktop.
TryCF Gist
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<cfscript> | |
function matchBadDate(str){ | |
objPattern = CreateObject("java","java.util.regex.Pattern").Compile(JavaCast( "string", '((?<=l?s?(dateformat|datetimeformat)).+[DY]+[^\##]+)')); | |
objMatcher = objPattern.Matcher(JavaCast( "string", str )); | |
return objMatcher.Find(); | |
} | |
</cfscript> | |
<cfoutput> | |
<cfset dayOptions = [ | |
['d', false], | |
['dd', false], | |
['ddd', false], | |
['dddd', false], | |
['D', true], | |
['DD', true], | |
['DDD', true], | |
['DDDD', true] | |
]> | |
<cfset monthOptions = [ | |
'm', | |
'mm', | |
'mmm', | |
'mmmm' | |
]> | |
<cfset yearOptions = [ | |
['yy', false], | |
['yyyy', false], | |
['YY', true], | |
['YYYY', true] | |
]> | |
<cfset otherOptions = [ | |
'k', | |
'w', | |
'gg', | |
'z' | |
]> | |
<cfset separatorOptions = [ | |
'-', | |
'/', | |
' ', | |
', ', | |
',' | |
]> | |
<cfset dateval = [ | |
'val', | |
'now()', | |
"'2018-12-15'", | |
'"2018-12-15"' | |
]> | |
<cfset dd = now()> | |
<cfset passed = 0> | |
<cfset failed = 0> | |
<cfset values = "dateformat, datetimeformat"> | |
<cfloop list="#values#" index="i"> | |
<cfloop array="#dayOptions#" index="do"> | |
<cfloop array="#monthOptions#" index="mo"> | |
<cfloop array="#yearOptions#" index="yr"> | |
<cfloop array="#otherOptions#" index="oo"> | |
<cfloop array="#separatorOptions#" index="sep"> | |
<cfloop array="#dateval#" index="dv"> | |
<cfset test1 = "###i#(#dv#,'#do[1]##sep##mo##sep##yr[1]##sep##oo#')##"> | |
<cfset test2 = '###i#(#dv#,"#do[1]##sep##mo##sep##yr[1]##sep##oo#")##'> | |
<cfset expected = false> | |
<cfif do[2] or yr[2]> | |
<cfset expected = true> | |
</cfif> | |
<cfif matchBadDate(test1) neq expected>expected: #expected# received #matchBadDate(test1)# - #test1# <br> | |
<cfset failed ++> | |
<cfelse> | |
<cfset passed ++> | |
</cfif> | |
<cfif matchBadDate(test2) neq expected>expected: #expected# received #matchBadDate(test2)# - #test2# <br> <br> | |
<cfset failed ++> | |
<cfelse> | |
<cfset passed ++> | |
</cfif> | |
</cfloop> | |
</cfloop> | |
</cfloop> | |
</cfloop> | |
</cfloop> | |
</cfloop> | |
</cfloop> | |
<strong>Passed:</strong> #passed# <br/> | |
<strong>Failed:</strong> #failed# <br/> | |
</cfoutput> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment