Created 10-14-2019 08:37 AM
@bha
This can be done via a single long complex NiFi Expression Language (EL) statement or via a couple smaller EL statements within the "Advanced" Ui of the UpdateAttribute processor.
Before you can use NiFI EL to solve this query, you will need to get your date in to a FlowFile attribute. Since i have no idea where the date 10/12/2019 originates from, I can't help much here. If it is on the content, perhaps extractText processor can be used.
Lets assume we have a FlowFile with the following FlowFile attribute on it:
FlowFile attribute name: | FlowFile Attribute value: |
mydate | 10/12/2019 |
We can pass this FlowFile through an UpdateAttribute processor where we create a new attribute with the date of the subsequent Sunday. (My EL assumes that if input date is already Sunday, it will calculate the next Sunday instead of just reporting that today is Sunday)
Solution1 (one long NiFi EL statement):
The full EL is below (all one line):
${mydate:toDate('MM/dd/yyyy'):format('u'):lt('7'):ifElse("${literal('7'):minus(${mydate:toDate('MM/dd/yyyy'):format('u')}):multiply('86400000'):plus(${mydate:toDate('MM/dd/yyyy'):toNumber()}):format('EEE,MM/dd/yyyy')}","${literal('604800000'):plus(${mydate:toDate('MM/dd/yyyy'):toNumber()}):format('EEE,MM/dd/yyyy')}")}
NOTE: Be careful with copy paste as it may screw up the single and double quote marks in the above EL making the EL statement invalid.
What above does is calculate day of week (1 - 7)...
IF - Then if that number is less then 7:
--- it subtracts it from 7 to determine how many day until next Sunday remain.
--- Then multiples that number by number of millseconds in a day
--- Then adds that number to the millisecond value of your input date.
--- Then converts that new millisecond value back in to a date again (format here is Sun,10/13/2019)
ELSE - When number is not less then 7
--- It adds 7 days in milliseconds to number to the millisecond value of your input date.
--- Then converts that new millisecond value back in to a date again (format here is Sun,10/13/2019)
So essential you have tow EL statements handled by an ifElse function. One covers days 1 -6 and the other covers day 7.
Solution 2 (Using "Advanced" UI of UpdateAttribute to break apart above long EL):
The Advanced Ui allows you to construct rules. Only the rules where the "conditions" resolve to "true" will apply the actions. So we simply create two rules. One for days 1-6 and the other for when day of week is 7.
Day less than 7:
Day equal 7:
Using the "Advanced"UI makes handling complex EL statements easier.
Hope this helps,
Matt