MagicMirror icon indicating copy to clipboard operation
MagicMirror copied to clipboard

Feature request: Debug date

Open jkriegshauser opened this issue 1 year ago • 7 comments

I looked at documentation and through the code and didn't see any way to easily do this.

As a developer, it would be beneficial to have MagicMirror use a simulated debug date. This could be specified in config.json for example, and then become useful for tests.

This would essentially replace all calls to moment() with moment(config.debugDate) since moment(undefined) falls back to returning the current date/time. Anything else that doesn't use moment() would also need fixup.

jkriegshauser avatar Oct 26 '23 17:10 jkriegshauser

Just add Date.now = () => new Date('2001-02-03T04:05:06'); in your config.js outside of the config-object

buxxi avatar Oct 26 '23 19:10 buxxi

Just add Date.now = () => new Date('2001-02-03T04:05:06'); in your config.js outside of the config-object

This might be a helpful addition to the module-development section of the documentation if someone wants to create a PR for that ;-)

rejas avatar Oct 26 '23 19:10 rejas

Setting Date.now to a lambda that responds with a specific date is an interesting idea, but it basically means that time stops. Sometimes we just want time to start at a specific time when MM is started 🤔

jkriegshauser avatar Oct 26 '23 22:10 jkriegshauser

Just add Date.now = () => new Date('2001-02-03T04:05:06'); in your config.js outside of the config-object

@buxxi this didn't quite work. The date/time typically in the top-middle shows the hard-coded date/time, but many modules still show actual time. Any other ideas?

jkriegshauser avatar Dec 31 '23 19:12 jkriegshauser

I went through and changed everywhere doing new Date() to Date.now() and that seemed to work. However, several external modules use new Date() and we should probably offer guidance on using Date.now() instead

jkriegshauser avatar Dec 31 '23 20:12 jkriegshauser

Also created https://github.com/MichMich/MagicMirror-Documentation/pull/218 for the documentation fixup

jkriegshauser avatar Dec 31 '23 21:12 jkriegshauser

However, several external modules use new Date() and we should probably offer guidance on using Date.now() instead

To see which modules are using new Date() I just added a check for this in my 3rd Party Module project - here is the result. There are a few developers who have adapted their modules in the past according to this list. So this may help to decrease the use of new Date() in the future.

KristjanESPERANTO avatar Dec 31 '23 23:12 KristjanESPERANTO