[ 
https://issues.apache.org/jira/browse/NIFI-15658?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18066780#comment-18066780
 ] 

ASF subversion and git services commented on NIFI-15658:
--------------------------------------------------------

Commit 4aab4244d66ece9723a1a269c6eba9ed5cdb1776 in nifi's branch 
refs/heads/main from Richard Scott
[ https://gitbox.apache.org/repos/asf?p=nifi.git;h=4aab4244d66 ]

NIFI-15658 Add duration arithmetic functions for Date and Instant values

This closes #10956.

Signed-off-by: Pierre Villard <[email protected]>


> 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: 2h
>  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