ioBroker.javascript
ioBroker.javascript copied to clipboard
[Bug]: getAstroDate( pattern, date ) unwanted side effect on date
I'm sure that
- [X] This issue is still present in the current beta version of this adapter
- [X] There is no other (open) issue with the same topic (use the search!)
- [X] This issue is not described in the adapter documentation / FAQ (read the docs!)
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
Nice catch
https://github.com/ioBroker/ioBroker.javascript/blob/e51a239f31974893afbbba70a6545105d0d58286/lib/sandbox.js#L1872