Files
reflex-wms-connector/ReflexUtils.ftl

72 lines
3.4 KiB
Java

<#-- -------------------------------------------------------------------------------------------- -->
<#-- Concat HARDIS WMS timestamp with HARDIS WMS time zone and format this date in ISO UTC format -->
<#-- -------------------------------------------------------------------------------------------- -->
<#function RfxDateTimetoUTC rfxdatetime offset >
<#return ((rfxdatetime + offset)?datetime.iso?iso_utc)>
</#function>
<#function DateTimeUTCtoRfxLocale dateutc locale >
<#return dateutc?datetime.iso?iso_nz(locale)>
</#function>
<#-- -------------------------------------------------------------------------------------------- -->
<#-- Add second to dateTime ex: AddSecondsToDatetime("2025-11-17T09:15:00Z"?datetime.iso, 61) -->
<#-- -------------------------------------------------------------------------------------------- -->
<#function AddSecondsToDatetime date seconds>
<#assign timeInMilliseconds = (1000 * seconds) >
<#assign aDate = date?long + timeInMilliseconds>
<#return aDate?number_to_datetime>
</#function>
<#-- -------------------------------------------------------------------------------------------- -->
<#-- Duration between two datetimes in second -->
<#-- -------------------------------------------------------------------------------------------- -->
<#function DurationBetweenTwoDatetimeInSeconds startDate endDate>
<#return (endDate?long - startDate?long) / 1000 >
</#function>
<#-- --------------------------------------------------------------------------------------- -->
<#-- Split email HARDIS WMS into json array string -->
<#-- Example : splitemail "john.doe@hardis-group.com,; name@hardis-group.com" -->
<#-- return "["john.doe@hardis-group.com","name@hardis-group.com"]" -->
<#-- --------------------------------------------------------------------------------------- -->
<#function splitEmailsIntoArray emails >
<#local str = "[">
<#list emails?split(";|,| |à|/","r")?filter(l -> l != "") as email>
<#if email?matches("^[\\w-\\.]+@([\\w-]+\\.)+[\\w-]{2,4}$")>
<#if str != "[">
<#local str += ",">
</#if>
<#local str += "\"">
<#local str += email>
<#local str += "\"">
</#if>
</#list>
<#local str += "]">
<#return (str)>
</#function>
<#-- --------------------------------------------------------------------------------------- -->
<#-- validate and convert HARDIS WMS date field into UTC timestamp -->
<#-- Example : RfxDatetoTimestampUTC("2025-11-00", "yyyy-MM-dd) -->
<#-- return "2025-11-00T00:00:00Z" -->
<#-- --------------------------------------------------------------------------------------- -->
<#-- Default timestamp to use in case of invalid date -->
<#assign DEFAULT_TIMESTAMP = "1970-01-01T00:00:00Z">
<#function RfxDatetoTimestampUTC rfxdate rfx_date_format >
<#local fallback = DEFAULT_TIMESTAMP>
<#if !rfxdate?matches("[0-9]*-[0-9]*-[0-9]*")>
<#return fallback>
</#if>
<#attempt>
<#if rfxdate?? && rfxdate == rfxdate?date(rfx_date_format)?string(rfx_date_format) >
<#return rfxdate?datetime(rfx_date_format)?iso_utc>,
<#else>
<#return fallback>
</#if>
<#recover>
<#return fallback>
</#attempt>
</#function>