Archives of Support Questions (Read Only)

This is an archived board for historical reference. Information and links may no longer be available or relevant
Announcements
This board is archived and read-only for historical reference. To ask a new question, please post a new topic on the appropriate active board.

Nifi problem with daylight saving

avatar
New Member

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
New Member

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
New Member

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
New Member

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.