ioBroker / ioBroker.javascript

Script engine for JavaScript and Blockly
MIT License
322 stars 120 forks source link

[Bug]: getAstroDate( pattern, date ) unwanted side effect on date #1506

Closed git-kick closed 3 months ago

git-kick commented 4 months ago

I'm sure that

Script type

JavaScript

The problem

I think that getAstroDate has an unwanted side-effect on the date argument in some situations: after calling getAstroDate(pattern,date) with a date variable, date's time of day is set to noon. To reproduce:

const now = new Date()
log(`now1 = ${now}`, 'debug')
var night = new Date(getAstroDate("night",now))
log(`now2 = ${now}`, 'debug')

iobroker.current.log (in debug mode!)

15:30:05.828 | info | javascript.0 (213570) Start javascript script.js.main.proofAstro
-- | -- | --
15:30:05.830 | debug | javascript.0 (213570) script.js.main.proofAstro: now1 = Mon Feb 26 2024 15:30:05 GMT+0100 (Mitteleuropäische Normalzeit)
15:30:05.830 | debug | javascript.0 (213570) script.js.main.proofAstro: now2 = Mon Feb 26 2024 12:00:00 GMT+0100 (Mitteleuropäische Normalzeit)
15:30:05.830 | info | javascript.0  (213570) script.js.main.proofAstro: registered 0 subscriptions, 0  schedules, 0 messages, 0 logs and 0 file subscriptions

See now2 showing 12:00 in contrast to now1 showing 15:30 correctly.

Version of nodejs

18.17.1

Version of ioBroker js-controller

5.0.19

Version of adapter

7.8.0

klein0r commented 4 months ago

Nice catch

https://github.com/ioBroker/ioBroker.javascript/blob/e51a239f31974893afbbba70a6545105d0d58286/lib/sandbox.js#L1872