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

Time functions #8

Merged
merged 4 commits into from
May 16, 2024
Merged

Time functions #8

merged 4 commits into from
May 16, 2024

Conversation

zoe-codez
Copy link
Member

@zoe-codez zoe-codez commented May 16, 2024

Changes

  1. renamed automation.utils to automation.time
  2. updated solar.onEvent to work off scheduler.sliding
  • context is no longer required
  • new optional param: offset
  1. added automation.time methods, which consume strings and return bool
  • isBetween
  • isBefore
  • isAfter

Offset

  • (number) ms
  • (tuple) [quantity, unit]
  • (string) ISO 8601 partial duration string: (#H)(#M)(#S)
  • (object) mapping of units to quantities
  • (Duration) dayjs.duration object
  • (function) a function that returns any of the above

Offset examples

automation.solar.onEvent({
  eventName: "dusk",
  exec() {
    logger.info("hour before dusk");
  },
  offset: "-1h",
});

automation.solar.onEvent({
  eventName: "dusk",
  exec() {
    logger.info("some random time within an hour after dusk");
  },
  offset: () => Math.random() * 60 * 60 * 1000,
});

Checklist

  • Read the contribution guide and accept the
    code of conduct
  • Readme and docs (updated or not needed)
  • Tests (added, updated or not needed)

@zoe-codez zoe-codez marked this pull request as draft May 16, 2024 00:18
@zoe-codez zoe-codez marked this pull request as ready for review May 16, 2024 03:21
@zoe-codez zoe-codez merged commit f934140 into main May 16, 2024
1 check passed
@zoe-codez zoe-codez deleted the time_functions branch May 16, 2024 03:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants