Created
December 14, 2020 18:55
-
-
Save trycf/d2d54f4a1cb032d802f1f6584f5baf6e 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]+[^\##]+)')); | |
objPattern = CreateObject("java","java.util.regex.Pattern").Compile(JavaCast( "string", 'l?s?(dateformat|datetimeformat)(.*?)[''"](.*?)[DY]{1,10}(.*?)[''"]')); | |
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