This function compares two values with simple types (String/Number/Boolean/Date/Time/Date-time).
It returns 0 if the two values are equal. It returns a value lower than 0 if the first value is strictly lower than the second. It returns a value higher than 0 if the first value is higher than the second.
When the two values are String type, the comparison mode is lexicographic. The "opts" parameter can be used to define a comparison using a collation enabling two character strings to be compared according to a given language.
Parameters
String/Number/Boolean/Date/Time/Date-time |
compVal1 |
Simple-type value to compare |
Mandatory |
String/Number/Boolean/Date/Time/Date-time |
compVal2 |
Simple-type value to compare |
Mandatory |
Hash |
opts |
Definition of comparison options. This object can have the following attributes:
|
Optional |
For example
<#assign stringVal1 = "foo" /> <#assign stringVal2 = "bar" /> <#assign opts = {"stringComp": "localeBased", "collator": {"locale": "en-GB", "strength": "primary"} } /> <#assign compare = hardisCore.compare (stringVal1, stringVal2, opts) /> <#if compare == 0> ${stringVal1} equals ${stringVal2} <#elseif compare > 0> ${stringVal1} is greater than ${stringVal2} <#else> ${stringVal1} is less than ${stringVal2} </#if>
Another example
<#assign compare = hardisCore.compare ("2015-05-23"?date.xs, "2017-10-04"?date.xs) />