Support Questions

Find answers, ask questions, and share your expertise
Announcements
Celebrating as our community reaches 100,000 members! Thank you!

Nifi problem with daylight saving

avatar

I need next day as attribute.

As I know, date manipulation by adding ms (e.g. ${now():toNumber():plus(86400000) ).

With this solution I have a problem with the daylight saving:

If date = "2016-10-29 12:00:00"

${date:toDate("yyyy-MM-dd HH:mm:ss"):toNumber():plus(86400000):format("yyyy-MM-dd HH:mm:ss")}

This code results: "2016-10-30 11:00:00"

I have built a pyhton solution, but I'm not realy happy with it:

import java.io
from org.apache.commons.io import IOUtils
from java.nio.charset import StandardCharsets
from org.apache.nifi.processor.io import StreamCallback
from datetime import datetime
from datetime import timedelta

flowFile = session.get()
if (flowFile != None):
  inDate = flowFile.getAttribute('inputDate')
  outputDateName = flowFile.getAttribute('output date attribute name')
  unit = flowFile.getAttribute('python timedelta unit')
  quantity = int(flowFile.getAttribute('quantity'))
  pythonDateFormat = flowFile.getAttribute('python date format')
  
  kwargs = {unit: quantity }
  outputDt = (datetime.strptime(inDate, pythonDateFormat) + timedelta(**kwargs)).strftime(pythonDateFormat)
  
  flowFile = session.putAttribute(flowFile, outputDateName, outputDt)
  session.transfer(flowFile, REL_SUCCESS)


Exist another solution with the given Nifi Processors?

I'm using HDF 1.2.0.0.

1 ACCEPTED SOLUTION

avatar
Contributor

According to the Nifi documentation, the timezone is embedded in the date information. https://nifi.apache.org/docs/nifi-docs/html/expression-language-guide.html#types

What if you included the timezone in your input and parsed with 'Z' in the format?

View solution in original post

2 REPLIES 2

avatar
Contributor

According to the Nifi documentation, the timezone is embedded in the date information. https://nifi.apache.org/docs/nifi-docs/html/expression-language-guide.html#types

What if you included the timezone in your input and parsed with 'Z' in the format?

avatar

I received the same date (perhaps I did something wrong 🙂 ).

I solved the problem with the following UpdateAttribute:

${date:toDate("yyyy-MM-dd"):toNumber():plus(86400000):format("yyyy-MM-dd"):append(${date:toDate("yyyy-MM-dd HH:mm:ss"):toNumber():format(" HH:mm:ss")})}

It works, but I'm still not very happy with this solution.