[ 
https://issues.apache.org/jira/browse/NIFI-15658?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Richard Scott updated NIFI-15658:
---------------------------------
    Summary: Add duration arithmetic Expression Language functions for Date and 
Instant values  (was: Add plusDuration,minusDuration / 
plusInstantDuration,minusInstantDuration functions to NiFi Expression Language 
for date/instant arithmetic)

> Add duration arithmetic Expression Language functions for Date and Instant 
> values
> ---------------------------------------------------------------------------------
>
>                 Key: NIFI-15658
>                 URL: https://issues.apache.org/jira/browse/NIFI-15658
>             Project: Apache NiFi
>          Issue Type: Improvement
>          Components: Core Framework, Extensions
>    Affects Versions: 2.8.0
>            Reporter: Richard Scott
>            Assignee: Richard Scott
>            Priority: Minor
>          Time Spent: 20m
>  Remaining Estimate: 0h
>
> NiFi Expression Language currently provides {{toDate()}} for parsing values 
> into a {{{}Date{}}}, and {{toInstant()}} for parsing values into an 
> {{{}Instant{}}}, but it does not provide a simple built-in way to add or 
> subtract a duration from either parsed value.
> As a result, users who want to shift a parsed date or instant often need to 
> convert the value to a numeric representation, perform arithmetic in 
> milliseconds, and then convert or format the result again. This makes common 
> time-based operations harder to read, harder to maintain, and less intuitive 
> than they should be.
> For example, users should be able to write:
> ${myDate:toDate("dd-MM-yyyy"):plusDuration("1 week"):format("dd-MM-yyyy")}
> ${myTimestamp:toInstant("dd-MM-yyyy HH:mm:ss", "UTC"):plusInstantDuration("1 
> week"):formatInstant("dd-MM-yyyy HH:mm:ss", "UTC")}
>  
> instead of relying on number-based arithmetic after parsing.
> h3. Proposed new functions
> For {{Date}} values:
>  * {{plusDuration(String duration)}}
>  * {{minusDuration(String duration)}}
> For {{Instant}} values:
>  * {{plusInstantDuration(String duration)}}
>  * {{minusInstantDuration(String duration)}}
> h3. Supported units
> The {{duration}} argument should support:
>  * years
>  * months
>  * weeks
>  * days
>  * hours
>  * minutes
>  * seconds
> h3. Validation requirements
> The {{duration}} argument should be validated strictly.
> Examples of valid inputs:
>  * {{"1 day"}}
>  * {{"2 weeks"}}
>  * {{"3 months"}}
> Examples of invalid inputs:
>  * {{"B weeks"}}
>  * {{"1 dog"}}
>  * {{"ten days"}}
> Invalid duration strings should cause the expression to be considered invalid 
> rather than being interpreted leniently.
> h3. Expected behavior
> {{plusDuration()}} and {{minusDuration()}} should:
>  * operate on {{Date}} values
>  * return {{Date}} values
>  * support natural chaining with existing date-related Expression Language 
> functions such as {{format()}}
> {{plusInstantDuration()}} and {{minusInstantDuration()}} should:
>  * operate on {{Instant}} values
>  * return {{Instant}} values
>  * support natural chaining with existing instant-related Expression Language 
> functions such as {{formatInstant()}}
> For {{Instant}} values, arithmetic should be evaluated in UTC so results are 
> deterministic across environments.
> h3. Benefit
> This enhancement would make date and time arithmetic in Expression Language 
> far easier to read and write, especially when working with values already 
> parsed using {{toDate()}} or {{{}toInstant(){}}}. It would also reduce the 
> need for awkward millisecond-based calculations for common operations such as 
> adding days, weeks, months, or years.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to