# In simpletime node 'mydoy' does not increment at 00:00

**URL:** https://discourse.nodered.org/t/in-simpletime-node-mydoy-does-not-increment-at-00-00/90777
**Category:** General
**Created:** [7 September 2024 19:28 UTC](https://discourse.nodered.org/t/in-simpletime-node-mydoy-does-not-increment-at-00-00/90777 "2024-09-07T19:28:00Z")
**Posts on this page:** 20
**Page:** 1

<div class="post-metadata">

### Author: ![GammaKappa](https://avatars.discourse-cdn.com/v4/letter/g/c5a1d2/32.png) [@GammaKappa](https://discourse.nodered.org/u/GammaKappa)
#### Post date: [7 September 2024 19:28 UTC](https://discourse.nodered.org/t/in-simpletime-node-mydoy-does-not-increment-at-00-00/90777/1 "2024-09-07T19:28:00Z")

</div>

I use the 'simpletime' node in many of my flows.  
This node can also output the day-of-year as msg.mydoy .

However, I noticed that mydoy does not increment at 00:00 but at 01:00

How can I correct this ?

---

<div class="post-metadata">

### Author: ![marcus-j-davies](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/marcus-j-davies/32/103435_2.png) [@marcus-j-davies](https://discourse.nodered.org/u/marcus-j-davies)
#### Post date: [7 September 2024 19:31 UTC](https://discourse.nodered.org/t/in-simpletime-node-mydoy-does-not-increment-at-00-00/90777/2 "2024-09-07T19:31:23Z")

</div>

Hi @GammaKappa

I don't use this Node, but it seems very possible, it based on UTC time?

If no date is provided, it will use a new Date object... and a new Date object is:

> JavaScript **`Date`** objects represent a single moment in time in a platform-independent format. `Date` objects encapsulate an integral number that represents milliseconds since the midnight at the beginning of January 1, 1970, UTC (the _epoch_ ).

> <https://github.com/Paul-Reed/node-red-contrib-simpletime/blob/c7da711e8d8d28661abe74e50d1bc5ca1f273ee5/simpletime.js#L39C21-L39C31>

@Paul-Reed may be able to confirm this

---

<div class="post-metadata">

### Author: ![Paul-Reed](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/paul-reed/32/66906_2.png) [@Paul-Reed](https://discourse.nodered.org/u/Paul-Reed)
#### Post date: [7 September 2024 19:57 UTC](https://discourse.nodered.org/t/in-simpletime-node-mydoy-does-not-increment-at-00-00/90777/3 "2024-09-07T19:57:38Z")

</div>

> [@GammaKappa](#):
>
> However, I noticed that mydoy does not increment at 00:00 but at 01:00

If you output `mytime` from the simpletime node, is the time correct for you?

I would suspect that the most likely cause is the time or timezone is different on the node-red server where node-red is running, to where your browser is running.  
Are you running docker?

---

<div class="post-metadata">

### Author: ![GammaKappa](https://avatars.discourse-cdn.com/v4/letter/g/c5a1d2/32.png) [@GammaKappa](https://discourse.nodered.org/u/GammaKappa)
#### Post date: [8 September 2024 06:02 UTC](https://discourse.nodered.org/t/in-simpletime-node-mydoy-does-not-increment-at-00-00/90777/4 "2024-09-08T06:02:40Z")

</div>

I am running node-red on a Raspberry Pi (no docker).

Time Zone on the Pi is set to Europe-Brussels.  
The 'mytimes' output shows the correct time.

---

<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: [8 September 2024 07:49 UTC](https://discourse.nodered.org/t/in-simpletime-node-mydoy-does-not-increment-at-00-00/90777/5 "2024-09-08T07:49:21Z")

</div>

It is probably best to submit an issue on the node's github page.

> **[Issues · Paul-Reed/node-red-contrib-simpletime](https://github.com/Paul-Reed/node-red-contrib-simpletime/issues)**
>
> A lightweight node-red node to provide and format date and time. - Issues · Paul-Reed/node-red-contrib-simpletime

---

<div class="post-metadata">

### Author: ![cymplecy](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/cymplecy/32/2773_2.png) [@cymplecy](https://discourse.nodered.org/u/cymplecy)
#### Post date: [8 September 2024 08:31 UTC](https://discourse.nodered.org/t/in-simpletime-node-mydoy-does-not-increment-at-00-00/90777/6 "2024-09-08T08:31:25Z")

</div>

I just did a little test my altering my system time and the msg.myday seems to be in sync with other properties when crossing a midnight boundary.  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/f/6/f6ae33a5ea475db733c5f043bd9a35fe15ed20db.png)

I'm in London/Europe UTC+1 timezone

Can you show us a debug output that demonstrates us the problem your having?

---

<div class="post-metadata">

### Author: ![GammaKappa](https://avatars.discourse-cdn.com/v4/letter/g/c5a1d2/32.png) [@GammaKappa](https://discourse.nodered.org/u/GammaKappa)
#### Post date: [8 September 2024 10:19 UTC](https://discourse.nodered.org/t/in-simpletime-node-mydoy-does-not-increment-at-00-00/90777/7 "2024-09-08T10:19:42Z")

</div>

Here's an excerpt from a log file :

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/d/1/d10eb22dda5d5b62989f2e6a5683c39c3eff2c71.png)

@cymplecy : my problem is with 'mydoy' rather then 'myday'

---

<div class="post-metadata">

### Author: ![cymplecy](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/cymplecy/32/2773_2.png) [@cymplecy](https://discourse.nodered.org/u/cymplecy)
#### Post date: [8 September 2024 10:34 UTC](https://discourse.nodered.org/t/in-simpletime-node-mydoy-does-not-increment-at-00-00/90777/9 "2024-09-08T10:34:43Z")

</div>

Sorry for not reading your original post properly ☹

I am getting the same issue as you

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/7/7/775add30f45fe7819c6001ead8036653b8b26385.png)

[edit] I'm thinking this issue probably comes from this bit of JS code in the node source

```auto
ny = Math.ceil((d - new Date(d.getFullYear(),0,1)) / 86400000)

```

A bit of googling suggests it should be more like this

```auto
ny = Math.floor((d - new Date(d.getFullYear(), 0, 0)) / 86400000)

```

but I'll do some testing to see if works before submitting it as a fix  
[edit2]  
Initial testing seems to indicate that both pieces of code return same result so having to go deeper down the rabbit hole 🙂

---

<div class="post-metadata">

### Author: ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)
#### Post date: [8 September 2024 11:46 UTC](https://discourse.nodered.org/t/in-simpletime-node-mydoy-does-not-increment-at-00-00/90777/10 "2024-09-08T11:46:42Z")

</div>

I use this:

```auto
function getDayOfYear(dt){
    return (Date.UTC(dt.getFullYear(), dt.getMonth(), dt.getDate()) - Date.UTC(dt.getFullYear(), 0, 0)) / 86400000
}

```

Demo  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/c/9/c9bc8c7d930d5280f8cdffe58b629f8ac07568ff.png)

---

<div class="post-metadata">

### Author: ![cymplecy](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/cymplecy/32/2773_2.png) [@cymplecy](https://discourse.nodered.org/u/cymplecy)
#### Post date: [8 September 2024 11:55 UTC](https://discourse.nodered.org/t/in-simpletime-node-mydoy-does-not-increment-at-00-00/90777/11 "2024-09-08T11:55:03Z")

</div>

That looks like just another way of the google provided solution but avoiding have to use Math.floor 🙂  
I think all the code snippets are producing the same number but something is going amiss somewhere

My thoughts at this point is that it's some sort of timezone issue but as you know - I'm no JS expert 🙂

_Aside - I had written a DOY function in another language (Snap!) and was using that to cross-check but I've found out that is giving the wrong answer as well! (Separate un-related issue)_

---

<div class="post-metadata">

### Author: ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)
#### Post date: [8 September 2024 11:58 UTC](https://discourse.nodered.org/t/in-simpletime-node-mydoy-does-not-increment-at-00-00/90777/12 "2024-09-08T11:58:05Z")

</div>

> [@cymplecy](#):
>
> That looks like just another way of the google provided solution

As would pretty much any working solution - I dont understand your point?

There is a good reason for avoiding floor - the solution needs to remove traces of DST and TZ then do the calculation.

> [@cymplecy](#):
>
> My thoughts at this point is that it's some sort of timezone issue

what i said ☝ which is why this uses UTC and not floor

---

<div class="post-metadata">

### Author: ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)
#### Post date: [8 September 2024 11:59 UTC](https://discourse.nodered.org/t/in-simpletime-node-mydoy-does-not-increment-at-00-00/90777/13 "2024-09-08T11:59:08Z")

</div>

An alternative way would be to subtract or add the timezone offset (which in essence is what the above does without calling `getTimezoneOffset`)

---

<div class="post-metadata">

### Author: ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)
#### Post date: [8 September 2024 12:01 UTC](https://discourse.nodered.org/t/in-simpletime-node-mydoy-does-not-increment-at-00-00/90777/14 "2024-09-08T12:01:49Z")

</div>

Lastly, if `moment` is available, then

```auto
moment(dt).dayOfYear()

```

---

<div class="post-metadata">

### Author: ![cymplecy](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/cymplecy/32/2773_2.png) [@cymplecy](https://discourse.nodered.org/u/cymplecy)
#### Post date: [8 September 2024 12:04 UTC](https://discourse.nodered.org/t/in-simpletime-node-mydoy-does-not-increment-at-00-00/90777/15 "2024-09-08T12:04:04Z")

</div>

My point was that your solution was logicaly the same as the google one) and therefore the algorithm itself is probably not at fault - no offence intended 🙂

---

<div class="post-metadata">

### Author: ![cymplecy](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/cymplecy/32/2773_2.png) [@cymplecy](https://discourse.nodered.org/u/cymplecy)
#### Post date: [8 September 2024 12:04 UTC](https://discourse.nodered.org/t/in-simpletime-node-mydoy-does-not-increment-at-00-00/90777/16 "2024-09-08T12:04:50Z")

</div>

simpletime node is the lean machine used to avoid moment 🙂

---

<div class="post-metadata">

### Author: ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)
#### Post date: [8 September 2024 12:04 UTC](https://discourse.nodered.org/t/in-simpletime-node-mydoy-does-not-increment-at-00-00/90777/17 "2024-09-08T12:04:50Z")

</div>

Lastly, I would add, a set of unit tests in the node should check the solution (mine too) to ensure leap years, start of year, end of year etc all make sense (and multiple timezones too)

---

<div class="post-metadata">

### Author: ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)
#### Post date: [8 September 2024 12:07 UTC](https://discourse.nodered.org/t/in-simpletime-node-mydoy-does-not-increment-at-00-00/90777/18 "2024-09-08T12:07:36Z")

</div>

> [@cymplecy](#):
>
> simpletime node is the lean machine used to avoid moment

I _think_ that is somewhat superfluous since Node-RED installs `moment` by default 🤷

The node could make use of moment without actually adding it in the package (or at least make it a peer dependency) - but probably best to avoid it.

---

<div class="post-metadata">

### Author: ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)
#### Post date: [8 September 2024 12:26 UTC](https://discourse.nodered.org/t/in-simpletime-node-mydoy-does-not-increment-at-00-00/90777/19 "2024-09-08T12:26:55Z")

</div>

I thought moment was deprecated-so relying on it being in the core while good for now, may not be a totally valid assumption.

---

<div class="post-metadata">

### Author: ![cymplecy](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/cymplecy/32/2773_2.png) [@cymplecy](https://discourse.nodered.org/u/cymplecy)
#### Post date: [8 September 2024 13:11 UTC](https://discourse.nodered.org/t/in-simpletime-node-mydoy-does-not-increment-at-00-00/90777/20 "2024-09-08T13:11:17Z")

</div>

> [@Steve-Mcl](#):
>
> `Date.UTC(dt.getFullYear(), dt.getMonth(), dt.getDate()) - Date.UTC(dt.getFullYear(), 0, 0)) / 86400000`

Does seem to give the correct answer for all just before midnight/just after midnight including end of year scenarios

Thank you 🙂

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/0/5/0540b66cc3472f608e3ddca577dfccebee1c3e1f.png)

I'll make a PR to @Paul-Reed (done)

I'm giving up trying to understand why the other ones don't work and just stop while I'm behind

_Aside - and I've fixed my issue in Snap! which uses an entirely different method_  
_(Basically specify how many days in each month adjusted for leap years and add in the DD value of YYMMDD)_

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/a/7/a73365ab4360776f3cf80b7de670a97f5ce38318.png)  
_(Snap! is 1-based indexing hence the need for the +1 and -1 here and there)_

---

<div class="post-metadata">

### Author: ![Paul-Reed](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/paul-reed/32/66906_2.png) [@Paul-Reed](https://discourse.nodered.org/u/Paul-Reed)
#### Post date: [8 September 2024 15:02 UTC](https://discourse.nodered.org/t/in-simpletime-node-mydoy-does-not-increment-at-00-00/90777/21 "2024-09-08T15:02:38Z")

</div>

Thanks @cymplecy  
I'm out all day, but back this evening and will catch up then.

[Next page](https://discourse.nodered.org/t/in-simpletime-node-mydoy-does-not-increment-at-00-00/90777.md?page=2)
