如何验证给定日期不是 mule 3 中的未来日期
How to validate the Given date is not a Future date in mule 3
我的要求是验证给定日期不应是未来日期。
例如 today date is 01/01/2020
.
输入日期:
30/01/2020
输出:
Date should not be Future date.
1.Get 当前日期 #[server.dateTime]
.
2.Set 转换消息。
"datevalidation": (payload.DateOfBirth as :date {format:"yyyy-MM-dd"}) < (flowVars.currentdate as :date {format:"yyyy-MM-dd"}
3.Add 验证组件 isTure
.
<validation:is-true config-ref="Validation_Configuration" expression="#[payload.datevalidation]" doc:name="Validation" message="date should not be Future."/>
完整代码。
<mule xmlns:validation="http://www.mulesoft.org/schema/mule/validation" xmlns:dw="http://www.mulesoft.org/schema/mule/ee/dw" xmlns:http="http://www.mulesoft.org/schema/mule/http" xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:doc="http://www.mulesoft.org/schema/mule/documentation"
xmlns:spring="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-current.xsd
http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd
http://www.mulesoft.org/schema/mule/ee/dw http://www.mulesoft.org/schema/mule/ee/dw/current/dw.xsd
http://www.mulesoft.org/schema/mule/validation http://www.mulesoft.org/schema/mule/validation/current/mule-validation.xsd">
<http:listener-config name="HTTP_Listener_Configuration" host="0.0.0.0" port="8081" doc:name="HTTP Listener Configuration"/>
<validation:config name="Validation_Configuration" doc:name="Validation Configuration"/>
<flow name="helloFlow">
<http:listener config-ref="HTTP_Listener_Configuration" path="/hello" allowedMethods="GET" doc:name="HTTP"/>
<set-variable variableName="currentdate" value="#[server.dateTime]" doc:name="current date Variable"/>
<dw:transform-message doc:name="Transform Message">
<dw:set-payload><![CDATA[%dw 1.0
%output application/java
---
{
"datevalidation": (payload.DateOfBirth as :date {format:"yyyy-MM-dd"}) < (flowVars.currentdate as :date {format:"yyyy-MM-dd"})
}]]></dw:set-payload>
</dw:transform-message>
<validation:is-true config-ref="Validation_Configuration" expression="#[payload.datevalidation]" doc:name="Validation" message="date should not be Future."/>
<logger level="INFO" doc:name="Logger"/>
</flow>
</mule>
希望对您有所帮助。
另一个建议
%dw 2.0
output application/json
var inpDate = "08/06/2021" as Date {"format": "dd/MM/yyyy"}
var today= now() as Date {"format": "dd/MM/yyyy"}
---
if (daysBetween(inpDate,today) > 0) "PastDate" else "FutureDate"
您也可以使用相等运算符将它们作为日期进行比较。如果您的日期有时间,请确保您将这些边缘情况转换为通用时区。
对于骡子 3:
%dw 1.0
%input payload application/json
%output application/json
%function isFutureDate(dt) (dt as :date) > (now as :date)
%var dt = "30/01/2020" as :date { format: "dd/MM/yyyy" }
---
isFuture: isFutureDate(dt)
对于骡子 4:
%dw 2.0
output application/json
fun isFutureDate(dateToTest: Date | DateTime) =
(dateToTest as Date) > (now() as Date)
var date = |2021-06-10|
---
isFutureDate(date)
我的要求是验证给定日期不应是未来日期。
例如 today date is 01/01/2020
.
输入日期:
30/01/2020
输出:
Date should not be Future date.
1.Get 当前日期 #[server.dateTime]
.
2.Set 转换消息。
"datevalidation": (payload.DateOfBirth as :date {format:"yyyy-MM-dd"}) < (flowVars.currentdate as :date {format:"yyyy-MM-dd"}
3.Add 验证组件 isTure
.
<validation:is-true config-ref="Validation_Configuration" expression="#[payload.datevalidation]" doc:name="Validation" message="date should not be Future."/>
完整代码。
<mule xmlns:validation="http://www.mulesoft.org/schema/mule/validation" xmlns:dw="http://www.mulesoft.org/schema/mule/ee/dw" xmlns:http="http://www.mulesoft.org/schema/mule/http" xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:doc="http://www.mulesoft.org/schema/mule/documentation"
xmlns:spring="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-current.xsd
http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd
http://www.mulesoft.org/schema/mule/ee/dw http://www.mulesoft.org/schema/mule/ee/dw/current/dw.xsd
http://www.mulesoft.org/schema/mule/validation http://www.mulesoft.org/schema/mule/validation/current/mule-validation.xsd">
<http:listener-config name="HTTP_Listener_Configuration" host="0.0.0.0" port="8081" doc:name="HTTP Listener Configuration"/>
<validation:config name="Validation_Configuration" doc:name="Validation Configuration"/>
<flow name="helloFlow">
<http:listener config-ref="HTTP_Listener_Configuration" path="/hello" allowedMethods="GET" doc:name="HTTP"/>
<set-variable variableName="currentdate" value="#[server.dateTime]" doc:name="current date Variable"/>
<dw:transform-message doc:name="Transform Message">
<dw:set-payload><![CDATA[%dw 1.0
%output application/java
---
{
"datevalidation": (payload.DateOfBirth as :date {format:"yyyy-MM-dd"}) < (flowVars.currentdate as :date {format:"yyyy-MM-dd"})
}]]></dw:set-payload>
</dw:transform-message>
<validation:is-true config-ref="Validation_Configuration" expression="#[payload.datevalidation]" doc:name="Validation" message="date should not be Future."/>
<logger level="INFO" doc:name="Logger"/>
</flow>
</mule>
希望对您有所帮助。
另一个建议
%dw 2.0
output application/json
var inpDate = "08/06/2021" as Date {"format": "dd/MM/yyyy"}
var today= now() as Date {"format": "dd/MM/yyyy"}
---
if (daysBetween(inpDate,today) > 0) "PastDate" else "FutureDate"
您也可以使用相等运算符将它们作为日期进行比较。如果您的日期有时间,请确保您将这些边缘情况转换为通用时区。
对于骡子 3:
%dw 1.0
%input payload application/json
%output application/json
%function isFutureDate(dt) (dt as :date) > (now as :date)
%var dt = "30/01/2020" as :date { format: "dd/MM/yyyy" }
---
isFuture: isFutureDate(dt)
对于骡子 4:
%dw 2.0
output application/json
fun isFutureDate(dateToTest: Date | DateTime) =
(dateToTest as Date) > (now() as Date)
var date = |2021-06-10|
---
isFutureDate(date)