Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature request: Debug date #3252

Open
jkriegshauser opened this issue Oct 26, 2023 · 7 comments
Open

Feature request: Debug date #3252

jkriegshauser opened this issue Oct 26, 2023 · 7 comments

Comments

@jkriegshauser
Copy link
Contributor

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.

@buxxi
Copy link
Contributor

buxxi commented Oct 26, 2023

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

@rejas
Copy link
Collaborator

rejas commented Oct 26, 2023

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 ;-)

@jkriegshauser
Copy link
Contributor Author

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
Copy link
Contributor Author

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
Copy link
Contributor Author

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
Copy link
Contributor Author

Also created MagicMirrorOrg/MagicMirror-Documentation#218 for the documentation fixup

@KristjanESPERANTO
Copy link
Contributor

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants