Skip to content

feat: add optional sleep time feature to webhooktimer#2

Merged
XHyperDEVX merged 1 commit intomainfrom
cto/implement-sleep-window-webhooktimer
Mar 28, 2026
Merged

feat: add optional sleep time feature to webhooktimer#2
XHyperDEVX merged 1 commit intomainfrom
cto/implement-sleep-window-webhooktimer

Conversation

@cto-new
Copy link
Copy Markdown

@cto-new cto-new bot commented Mar 28, 2026

Summary

Added optional sleep time feature to webhooktimer - a time period during which webhooks won't be triggered even if timer expires.

Changes Made

Backend (Go)

  1. internal/models/timer.go: Added two new fields to TimerEntry struct:

    • SleepTimeStart - Start time in HH:MM format (24-hour)
    • SleepTimeEnd - End time in HH:MM format (24-hour)
  2. internal/models/db.go: Updated SQLite schema to include:

    • sleep_time_start TEXT column
    • sleep_time_end TEXT column
  3. internal/timer/manager.go:

    • Added isSleepTime() helper that checks if current time falls within sleep window
    • Added parseTime() helper to parse HH:MM strings
    • Modified runTimer() to skip webhook execution during sleep time
    • Handles sleep times that span midnight (e.g., 23:00-06:00)
    • Uses Europe/Berlin timezone for time calculations
  4. internal/handlers/handlers.go:

    • Updated CreateTimer, UpdateTimer, and ToggleTimer handlers to include sleep time fields in SQL queries

Frontend (HTML/JavaScript)

  1. web/templates/index.html:
    • Added "Enable Sleep Time" checkbox with toggle switch styling
    • Added sleep time input fields (Start/End in HH:MM format) with time picker
    • Updated editTimer() to populate sleep time fields when editing
    • Updated form submission to include sleep time data
    • Updated new-timer-btn handler to reset sleep time fields

Usage

  1. Create or edit a timer
  2. Check "Enable Sleep Time"
  3. Set the start and end times (e.g., 23:00 to 06:00 for overnight sleep)
  4. During the configured time window, webhooks will not be triggered even if the timer expires
  5. The timer continues to run and will execute webhooks once the sleep window ends

Powered by CTO.new

Add optional sleep time feature - a time period during which webhooks
won't be triggered even if timer expires.

Changes:
- Add SleepTimeStart and SleepTimeEnd fields to TimerEntry model (HH:MM format)
- Update SQLite database schema with new columns
- Add isSleepTime() helper to check if current time falls within sleep window
- Handle sleep times that span midnight (e.g., 23:00-06:00)
- Use Europe/Berlin timezone for time calculations
- Update all SQL queries (Create, Update, Toggle, StartAll)
- Add UI in timer modal with checkbox toggle and time inputs
- Update JavaScript to handle sleep time in form submission and editing
@XHyperDEVX XHyperDEVX merged commit c50d0d0 into main Mar 28, 2026
1 check passed
@XHyperDEVX XHyperDEVX deleted the cto/implement-sleep-window-webhooktimer branch March 28, 2026 16:50
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.

1 participant