# Node-red-contrib-aggregator fires at wrong time

**URL:** <https://discourse.nodered.org/t/node-red-contrib-aggregator-fires-at-wrong-time/38650>\
**Category:** General\
**Created:** [6 January 2021 12:19 UTC](https://discourse.nodered.org/t/node-red-contrib-aggregator-fires-at-wrong-time/38650 "2021-01-06T12:19:10Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![christN](https://avatars.discourse-cdn.com/v4/letter/c/82dd89/32.png) [@christN](https://discourse.nodered.org/u/christN)\
**Post date:** [6 January 2021 12:19 UTC](https://discourse.nodered.org/t/node-red-contrib-aggregator-fires-at-wrong-time/38650/1 "2021-01-06T12:19:10Z")

</div>

I'm using node-red-contrib-aggregator (v1.5.0) to calculate the daily average ad a temperature value.  
Node-RED v1.2.1  
It is installed in an IOCage jail (FreeBSD 11.3-RELEASE-p14)

I expected that it would fire at 0:00 to show the average value of the last day.  
But it starts at 0:59:59 that is (almost) 1 hour to late.

I already verified the time zone if the IOCage jail which is correct:

```auto
root@NodeRed:~ # date
Wed Jan 6 13:09:31 CET 2021

```

I also added the timezone to settings.js as suggested on several places  
`process.env.TZ = 'Europe/Amsterdam';`  
just above module.exports = {

node-red-contrib-timerswitch does fire at the proper time so I'm kinda stuck now

Any help would be appreciated!

---

<div class="post-metadata">

**Author:** ![christN](https://avatars.discourse-cdn.com/v4/letter/c/82dd89/32.png) [@christN](https://discourse.nodered.org/u/christN)\
**Post date:** [6 January 2021 12:37 UTC](https://discourse.nodered.org/t/node-red-contrib-aggregator-fires-at-wrong-time/38650/2 "2021-01-06T12:37:36Z")

</div>

Just in case I just upgraded the IOCage to Freebsd 12.1-RELEASE  
And also updated Node-RED to 1.2.7 as for some reason I assumed there would be an update notice if a new version came out and I therefor missed the later releases

As a test I set the aggregater at 2 hours.  
If I understand it correctly it should fire every even hours (2:00, 4:00, 6:00, 8:00 etc)  
But, during this test it didn't fire at 14:00 but on 14:59:58 so again an hour to late.

In my opinion it looks like it is using utc time instead of CET, could this be the case?  
And if so, how can I resolve this?

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [6 January 2021 15:12 UTC](https://discourse.nodered.org/t/node-red-contrib-aggregator-fires-at-wrong-time/38650/3 "2021-01-06T15:12:01Z")

</div>

Are the timestamps shown above events in the debug pane showing the correct local time?  
What version of nodejs are you using (`node -v`)?

If you restart node-red without rebooting the server does it then fire at the right time?

**[Edit]** Have you changed the system time or zone since starting node-red?

---

<div class="post-metadata">

**Author:** ![christN](https://avatars.discourse-cdn.com/v4/letter/c/82dd89/32.png) [@christN](https://discourse.nodered.org/u/christN)\
**Post date:** [6 January 2021 16:20 UTC](https://discourse.nodered.org/t/node-red-contrib-aggregator-fires-at-wrong-time/38650/4 "2021-01-06T16:20:16Z")

</div>

The timestamps in the debug pane are correct.  
Also the timestamps shown in the flows (nodes that show a time(date) that is) are correct.

As for the version  
root@NodeRed:~ # pkg info | grep node  
node10-10.22.1 V8 JavaScript for client and server  
npm-node10-6.14.8 Node package manager  
root@NodeRed:~ # node -v  
v10.22.1

This isn't the latest, but the 10.x is still supported and the changelogs don't show any interesting fixes.  
None the less after the manual start test i can update it to the latetst LTS release available in the freebsd package manager (14.13.0) if that could be interesting?

Never restarted node-red manually (auto start with server) so I'm testing that now, will update this post as soon as I have an answer.

The time zone settings have never been changed, the iocage jail was created with the proper time zone settings.

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [6 January 2021 16:44 UTC](https://discourse.nodered.org/t/node-red-contrib-aggregator-fires-at-wrong-time/38650/5 "2021-01-06T16:44:03Z")

</div>

I would run a test here to see if I can replicate the problem, but, being in the UK I am now on UTC and haven't got a spare system I can setup with a different timezone.

---

<div class="post-metadata">

**Author:** ![christN](https://avatars.discourse-cdn.com/v4/letter/c/82dd89/32.png) [@christN](https://discourse.nodered.org/u/christN)\
**Post date:** [6 January 2021 17:00 UTC](https://discourse.nodered.org/t/node-red-contrib-aggregator-fires-at-wrong-time/38650/6 "2021-01-06T17:00:14Z")

</div>

Thanks for the assistance.

Though I think I might have found something that might be part of my issue.  
I'm not sure yet as I still have to test it but am out of time for today.

The code of node-red-contrib-aggregator uses new Date().getTime()  
This gives the time back as EPOCH which is as far as I know always UTC and the interpretor needs to convert it to something else if needed (for example to the correct time zone).  
I haven't found anything in the code for aggregator to correct for the time zone, but i could've missed it.

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [6 January 2021 17:21 UTC](https://discourse.nodered.org/t/node-red-contrib-aggregator-fires-at-wrong-time/38650/7 "2021-01-06T17:21:32Z")

</div>

Probably worth raising an issue against the node on its github page.

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [6 January 2021 17:25 UTC](https://discourse.nodered.org/t/node-red-contrib-aggregator-fires-at-wrong-time/38650/8 "2021-01-06T17:25:49Z")

</div>

Looking briefly at the code I also can't see anything attempting to adjust the intervals to local time.

---

<div class="post-metadata">

**Author:** ![christN](https://avatars.discourse-cdn.com/v4/letter/c/82dd89/32.png) [@christN](https://discourse.nodered.org/u/christN)\
**Post date:** [6 January 2021 18:52 UTC](https://discourse.nodered.org/t/node-red-contrib-aggregator-fires-at-wrong-time/38650/9 "2021-01-06T18:52:12Z")

</div>

Created an issue for it.

Hopefully it is something that is wrong with the node and that they can fix it.

---

<div class="post-metadata">

**Author:** ![christN](https://avatars.discourse-cdn.com/v4/letter/c/82dd89/32.png) [@christN](https://discourse.nodered.org/u/christN)\
**Post date:** [10 January 2021 09:00 UTC](https://discourse.nodered.org/t/node-red-contrib-aggregator-fires-at-wrong-time/38650/10 "2021-01-10T09:00:46Z")

</div>

So far still no update on the issue I created on github.

So for now I changed to code myself to correct the timezone.  
If they are going to follow up I will share it with them (or anybody else that wants it).

---

<div class="post-metadata">

**Author:** ![HaVi](https://avatars.discourse-cdn.com/v4/letter/h/b3f665/32.png) [@HaVi](https://discourse.nodered.org/u/HaVi)\
**Post date:** [29 January 2021 11:55 UTC](https://discourse.nodered.org/t/node-red-contrib-aggregator-fires-at-wrong-time/38650/11 "2021-01-29T11:55:32Z")

</div>

Would be great to read how you changed the code.

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [29 January 2021 12:12 UTC](https://discourse.nodered.org/t/node-red-contrib-aggregator-fires-at-wrong-time/38650/12 "2021-01-29T12:12:33Z")

</div>

Did you do it 'properly' by forking the git repository and modifying it on your fork? If so then others can install it direct from your fork by using  
`npm install <your git id>/node-red-contrib-...`

---

<div class="post-metadata">

**Author:** ![christN](https://avatars.discourse-cdn.com/v4/letter/c/82dd89/32.png) [@christN](https://discourse.nodered.org/u/christN)\
**Post date:** [29 January 2021 12:35 UTC](https://discourse.nodered.org/t/node-red-contrib-aggregator-fires-at-wrong-time/38650/13 "2021-01-29T12:35:56Z")

</div>

Yes, ofcourse I created a fork on github.  
You can find it on the repository pull requests where i published my changes.

Or you can find it in my repository, i just created a public fork so you can access it directly in there.  
AcEIoXx/node-red-contrib-aggregator

---

<div class="post-metadata">

**Author:** ![christN](https://avatars.discourse-cdn.com/v4/letter/c/82dd89/32.png) [@christN](https://discourse.nodered.org/u/christN)\
**Post date:** [29 January 2021 12:36 UTC](https://discourse.nodered.org/t/node-red-contrib-aggregator-fires-at-wrong-time/38650/14 "2021-01-29T12:36:34Z")

</div>

See my reply to Colin.

You should be able to get the changed version that way, or you can make the changes by yourself.

---

<div class="post-metadata">

**Author:** ![HaVi](https://avatars.discourse-cdn.com/v4/letter/h/b3f665/32.png) [@HaVi](https://discourse.nodered.org/u/HaVi)\
**Post date:** [29 January 2021 13:05 UTC](https://discourse.nodered.org/t/node-red-contrib-aggregator-fires-at-wrong-time/38650/15 "2021-01-29T13:05:23Z")

</div>

I suppose you mean [https://github.com/jaggr2/node-red-contrib-aggregator/pull/16](https://github.com/jaggr2/node-red-contrib-aggregator/pull/16)? Thanks!

---

<div class="post-metadata">

**Author:** ![christN](https://avatars.discourse-cdn.com/v4/letter/c/82dd89/32.png) [@christN](https://discourse.nodered.org/u/christN)\
**Post date:** [29 January 2021 13:18 UTC](https://discourse.nodered.org/t/node-red-contrib-aggregator-fires-at-wrong-time/38650/16 "2021-01-29T13:18:04Z")

</div>

He Hans,

Yes i do, but you can also just pull my fork. Whatever you prefer.

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [29 January 2021 13:44 UTC](https://discourse.nodered.org/t/node-red-contrib-aggregator-fires-at-wrong-time/38650/17 "2021-01-29T13:44:01Z")

</div>

Just to clarify, the modified version can be installed by going to your .node-red folder and running  
`npm install AcEIoXx/node-red-contrib-aggregator`  
then restart node-red.

If you ever want to revert to the standard one then  
`npm remove node-red-contrib-aggregator`  
`npm install node-red-contrib-aggregator`

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [29 January 2021 13:57 UTC](https://discourse.nodered.org/t/node-red-contrib-aggregator-fires-at-wrong-time/38650/18 "2021-01-29T13:57:55Z")

</div>

> [@christN](#):
>
> Yes, ofcourse I created a fork on github.

Sorry, I wasn't intending to imply any criticism, that is why I put 'proper' in quotes. Often people make such changes by editing the file in node\_modules. I had no way of knowing your experience level.

---

<div class="post-metadata">

**Author:** ![christN](https://avatars.discourse-cdn.com/v4/letter/c/82dd89/32.png) [@christN](https://discourse.nodered.org/u/christN)\
**Post date:** [29 January 2021 19:41 UTC](https://discourse.nodered.org/t/node-red-contrib-aggregator-fires-at-wrong-time/38650/19 "2021-01-29T19:41:27Z")

</div>

I took no offence, was in a hurry when I typed my reply and didn't meen to offend you.

everybody that wants to use my change..  
It works, that's it, the code isn't as nice as I would want it, but I wanted it working will making as litle changes to the original code as possible.  
The edit's could be made cleaner, but for me this works for now.

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [29 January 2021 20:35 UTC](https://discourse.nodered.org/t/node-red-contrib-aggregator-fires-at-wrong-time/38650/20 "2021-01-29T20:35:32Z")

</div>

> [@christN](#):
>
> didn't meen to offend you.

No offence taken. I was concerned that I had offended you 🙂

[Next page](https://discourse.nodered.org/t/node-red-contrib-aggregator-fires-at-wrong-time/38650.md?page=2)
