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 week of the year calculation

Nifi week of the year calculation

New Contributor

Hi all,

I nifi I have an attribute with filename from which I extracted date with substring (only yyyyMMdd portion).

After that I want to calculate year week number for date 2018/08/19 (formated from string portion 20180819024112) which is week number 33.

If I use format without specified timezone ('GMT'), I get week number 34, but with specified timezone I get correct week number 33. What is the difference? Why do I get wrong week number without timezone. GMT is only +2 hours from 19th of August Midnight.

Thanks,

Tom

87449-4.png

87445-1.png


3.png2.png
3 REPLIES 3

Re: Nifi week of the year calculation

New Contributor

Could it be that in GMT weeks start on Monday whereas weeks in your implicit timezone start on Sunday? Which timezone is your system set to?

Another thing to check could be what date you get when you use:

(...):format('yyyy-MM-dd HH:mm:ss', 'GMT')

Is it what you're expecting?

Re: Nifi week of the year calculation

New Contributor

Timezone on my system is UTC+1 and first day of the week is Monday (also specified on my system).

With (...):format('yyyy-MM-dd HH:mm:ss', 'GMT') I get 2018-08-18 22:00:00, but without 'GMT' I get 2018-08-19 00:00:00.

Re: Nifi week of the year calculation

Hello @Tomislav Novosel!
I tried to make the same test as you, but unfortunately, I got 34, even after removing the GMT.
Here's my template.
testing-tmz.xml

Also here's the step that I took:

su - nifi
mkdir -p /home/nifi/play_ts/cd /home/nifi/play_ts/touch 20180819024112


BTW, my timezone it's UTC. And my formula it's a little bit different from yours cause I'm skipping the getDelimitedFields.

${filename:substring(0,8):toDate("yyyyMMdd"):format("w","GMT")}

Hope this helps.