From 1e01db0889bd1c845adb8151a93446be13ee0d43 Mon Sep 17 00:00:00 2001 From: Kelly Thomas Reardon Date: Sun, 31 May 2026 19:52:09 -0500 Subject: [PATCH] more time zone corrections and removing the loop in the notifier script as it now runs via a cron schedule --- Start-DoneTickNotifier.ps1 | 106 +++++++++++++------------------------ docker-compose.yaml | 3 +- 2 files changed, 37 insertions(+), 72 deletions(-) diff --git a/Start-DoneTickNotifier.ps1 b/Start-DoneTickNotifier.ps1 index 244bc85..6a94eee 100644 --- a/Start-DoneTickNotifier.ps1 +++ b/Start-DoneTickNotifier.ps1 @@ -3,7 +3,6 @@ [string] $dtAPIKey = $ENV:DONETICKAPIKEY [string] $appriseWebhookURL = $ENV:APPRISEWEBHOOKURL [string] $appriseWebhookTag = $ENV:APPRISEWEBHOOKTAG -[int[]] $notificationTimes = $ENV:NOTIFICATIONTIMES -split "," function Send-Notification @@ -51,87 +50,54 @@ function Get-Chores } } -if (-not $notificationTimes) { $notificationTimes = @(8) } -else { $notificationTimes = $notificationTimes | Sort-Object } -Write-Host "Notification times: $notificationTimes" +$today = (Get-Date "23:59:59") +$chores = Get-Chores -while ($true) { - $today = (Get-Date "23:59:59") - $chores = Get-Chores - - $overdueTasks = @() - $todaysTasks = @() - - foreach($chore in $chores) +$overdueTasks = @() +$todaysTasks = @() + +foreach($chore in $chores) +{ + if ($chore.nextDueDate) { - if ($chore.nextDueDate) + $dueDate = (Get-Date $chore.nextDueDate).ToLocalTime() + if (($dueDate - $today).Days -lt 0) #OVERDUE { - $dueDate = (Get-Date $chore.nextDueDate).ToLocalTime() - if (($dueDate - $today).Days -lt 0) #OVERDUE - { - write-host "$($chore.name) $dueDate is overdue!" - $overdueTasks += $chore - } - elseif (($dueDate - $today) -lt 1) #due today - { - write-host "$($chore.name) $dueDate is due today!" - $todaysTasks += $chore - # Send-Notification -title "TASK DUE TODAY" -content "$($chore.Name) is due today!" - } - else - { - write-host "$($chore.name) $dueDate is due in the future" - } + write-host "$($chore.name) $dueDate is overdue!" + $overdueTasks += $chore } - - } - - if ($overdueTasks.Count -ne 0) - { - Write-Host "Sending a notification for $($overdueTasks.Count) overdue tasks" - $content = "The following tasks are overdue!`n" - foreach($overdueTask in $overdueTasks) + elseif (($dueDate - $today) -lt 1) #due today { - $content += "$($overdueTask.Name) was due $(Get-Date $overdueTask.nextDueDate -Format "MM/dd/yyyy HH:mm")`n" + write-host "$($chore.name) $dueDate is due today!" + $todaysTasks += $chore + # Send-Notification -title "TASK DUE TODAY" -content "$($chore.Name) is due today!" } - Send-Notification -title "OVERDUE TASKS" -content $content - } - - if ($todaysTasks.Count -ne 0) - { - Write-Host "Sending a notification for $($todaysTasks.Count) tasks due today" - $content = "The following tasks are due today!`n" - foreach($task in $todaysTasks) + else { - $content += "$($task.Name) is due $(Get-Date $task.nextDueDate -Format "MM/dd/yyyy HH:mm")`n" + write-host "$($chore.name) $dueDate is due in the future" } - Send-Notification -title "TODAY'S TASKS" -content $content } - Write-Host "Finding next notification time..." - Write-Host "Current time: $(Get-Date)" - $nextNotificationTomorrow = $true - foreach($time in $notificationTimes) +} + +if ($overdueTasks.Count -ne 0) +{ + Write-Host "Sending a notification for $($overdueTasks.Count) overdue tasks" + $content = "The following tasks are overdue!`n" + foreach($overdueTask in $overdueTasks) { - $now = Get-Date - $diff = $now.Hour - $time - if ($diff -lt 0) # next notification time - { - $nextNotificationTomorrow = $false - Write-Host "Next notification time is $time`:00" - $sleepTime = ($diff * -1) * 60 * 60 # hours * mins * seconds - Write-Host "Sleeping for $sleepTime seconds" - Start-Sleep -Seconds $sleepTime - continue # leave loop - } + $content += "$($overdueTask.Name) was due $((Get-Date $overdueTask.nextDueDate -Format "MM/dd/yyyy HH:mm").ToLocalTime())`n" } - if ($nextNotificationTomorrow) + Send-Notification -title "OVERDUE TASKS" -content $content +} + +if ($todaysTasks.Count -ne 0) +{ + Write-Host "Sending a notification for $($todaysTasks.Count) tasks due today" + $content = "The following tasks are due today!`n" + foreach($task in $todaysTasks) { - $time = $notificationTimes[0] - Write-Host "Next notification time is $time`:00" - $diff = 24 - $now.Hour + $time - $sleepTime = $diff * 60 * 60 # hours * mins * seconds - Write-Host "Sleeping for $sleepTime seconds" - Start-Sleep -Seconds $sleepTime + $content += "$($task.Name) is due $((Get-Date $task.nextDueDate -Format "MM/dd/yyyy HH:mm").ToLocalTime())`n" } + Send-Notification -title "TODAY'S TASKS" -content $content } \ No newline at end of file diff --git a/docker-compose.yaml b/docker-compose.yaml index 66d4cdf..609c08f 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -12,6 +12,5 @@ services: - DONETICKAPIKEY=adminpass # donetick API key - APPRISEWEBHOOKURL=https://apprisehost/notify/config # apprise notification url - APPRISEWEBHOOKTAG=all # apprise notification tag - - NOTIFICATIONTIMES=8,12,17 # hours when notifications will be sent - TZ=America/Chicago # set timezone from this list: https://en.wikipedia.org/wiki/List_of_tz_database_time_zones#List - - JOB_SCHEDULE=0 * * * * \ No newline at end of file + - JOB_SCHEDULE=0 8,17 * * * # when to notify about overdue tasks or tasks due today \ No newline at end of file