feat: shift recurring event date if lands on weekends
This commit is contained in:
parent
f7558c0eb5
commit
fb0cfb5a45
8 changed files with 191 additions and 66 deletions
|
|
@ -4,6 +4,7 @@ import "git.juancwu.dev/juancwu/budgit/internal/misc/timezone"
|
|||
import "git.juancwu.dev/juancwu/budgit/internal/model"
|
||||
import "git.juancwu.dev/juancwu/budgit/internal/ui/components/button"
|
||||
import "git.juancwu.dev/juancwu/budgit/internal/ui/components/card"
|
||||
import "git.juancwu.dev/juancwu/budgit/internal/ui/components/checkbox"
|
||||
import "git.juancwu.dev/juancwu/budgit/internal/ui/components/form"
|
||||
import "git.juancwu.dev/juancwu/budgit/internal/ui/components/input"
|
||||
import "git.juancwu.dev/juancwu/budgit/internal/ui/components/textarea"
|
||||
|
|
@ -27,9 +28,10 @@ type RecurringEventFormProps struct {
|
|||
DayOfWeek string
|
||||
DayOfMonth string
|
||||
MonthOfYear string
|
||||
FireTime string
|
||||
Timezone string
|
||||
StartDate string
|
||||
FireTime string
|
||||
Timezone string
|
||||
StartDate string
|
||||
BusinessDaysOnly bool
|
||||
|
||||
TitleErr string
|
||||
KindErr string
|
||||
|
|
@ -307,6 +309,24 @@ templ RecurringEventForm(props RecurringEventFormProps) {
|
|||
}
|
||||
}
|
||||
</div>
|
||||
@form.Item() {
|
||||
<div class="flex items-start gap-2">
|
||||
@checkbox.Checkbox(checkbox.Props{
|
||||
ID: "business_days_only",
|
||||
Name: "business_days_only",
|
||||
Value: "1",
|
||||
Checked: props.BusinessDaysOnly,
|
||||
})
|
||||
<div class="space-y-1">
|
||||
<label for="business_days_only" class="text-sm font-medium leading-none cursor-pointer">
|
||||
Skip non-business days
|
||||
</label>
|
||||
@form.Description() {
|
||||
If a firing lands on Saturday or Sunday, push it to the following Monday.
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
@form.Item() {
|
||||
@form.Label(form.LabelProps{For: "description"}) {
|
||||
Description
|
||||
|
|
|
|||
|
|
@ -19,39 +19,43 @@ var weekdayLabels = []string{"Sunday", "Monday", "Tuesday", "Wednesday", "Thursd
|
|||
|
||||
func recurrenceSummary(ev *model.RecurringEvent) string {
|
||||
timePart := fmt.Sprintf(" at %02d:%02d", ev.FireHour, ev.FireMinute)
|
||||
suffix := ""
|
||||
if ev.BusinessDaysOnly {
|
||||
suffix = " (skips weekends)"
|
||||
}
|
||||
switch ev.Frequency {
|
||||
case model.RecurringFrequencyDaily:
|
||||
if ev.IntervalCount == 1 {
|
||||
return "Daily" + timePart
|
||||
return "Daily" + timePart + suffix
|
||||
}
|
||||
return fmt.Sprintf("Every %d days%s", ev.IntervalCount, timePart)
|
||||
return fmt.Sprintf("Every %d days%s", ev.IntervalCount, timePart) + suffix
|
||||
case model.RecurringFrequencyWeekly:
|
||||
dow := ""
|
||||
if ev.DayOfWeek != nil && *ev.DayOfWeek >= 0 && *ev.DayOfWeek < len(weekdayLabels) {
|
||||
dow = " on " + weekdayLabels[*ev.DayOfWeek]
|
||||
}
|
||||
if ev.IntervalCount == 1 {
|
||||
return "Weekly" + dow + timePart
|
||||
return "Weekly" + dow + timePart + suffix
|
||||
}
|
||||
return fmt.Sprintf("Every %d weeks%s%s", ev.IntervalCount, dow, timePart)
|
||||
return fmt.Sprintf("Every %d weeks%s%s", ev.IntervalCount, dow, timePart) + suffix
|
||||
case model.RecurringFrequencyMonthly:
|
||||
dom := ""
|
||||
if ev.DayOfMonth != nil {
|
||||
dom = fmt.Sprintf(" on day %d", *ev.DayOfMonth)
|
||||
}
|
||||
if ev.IntervalCount == 1 {
|
||||
return "Monthly" + dom + timePart
|
||||
return "Monthly" + dom + timePart + suffix
|
||||
}
|
||||
return fmt.Sprintf("Every %d months%s%s", ev.IntervalCount, dom, timePart)
|
||||
return fmt.Sprintf("Every %d months%s%s", ev.IntervalCount, dom, timePart) + suffix
|
||||
case model.RecurringFrequencyYearly:
|
||||
date := ""
|
||||
if ev.MonthOfYear != nil && ev.DayOfMonth != nil {
|
||||
date = fmt.Sprintf(" on %s %d", time.Month(*ev.MonthOfYear).String(), *ev.DayOfMonth)
|
||||
}
|
||||
if ev.IntervalCount == 1 {
|
||||
return "Yearly" + date + timePart
|
||||
return "Yearly" + date + timePart + suffix
|
||||
}
|
||||
return fmt.Sprintf("Every %d years%s%s", ev.IntervalCount, date, timePart)
|
||||
return fmt.Sprintf("Every %d years%s%s", ev.IntervalCount, date, timePart) + suffix
|
||||
}
|
||||
return string(ev.Frequency)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue