Support Questions
Find answers, ask questions, and share your expertise
Announcements
Alert: Welcome to the Unified Cloudera Community. Former HCC members be sure to read and learn how to activate your account here.

Nifi problem with daylight saving

Solved Go to solution

Nifi problem with daylight saving

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

Accepted Solutions
Highlighted

Re: Nifi problem with daylight saving

Explorer

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
Highlighted

Re: Nifi problem with daylight saving

Explorer

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

Highlighted

Re: Nifi problem with daylight saving

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.

Don't have an account?
Coming from Hortonworks? Activate your account here