1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
|
package org.terst.doot.widget.ui
import android.content.Intent
import android.net.Uri
import androidx.compose.runtime.Composable
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.dp
import androidx.glance.*
import androidx.glance.action.actionParametersOf
import androidx.glance.action.clickable
import androidx.glance.appwidget.action.actionRunCallback
import androidx.glance.appwidget.action.actionStartActivity
import androidx.glance.layout.*
import androidx.glance.text.FontWeight
import androidx.glance.text.Text
import androidx.glance.text.TextStyle
import androidx.glance.unit.ColorProvider
import org.terst.doot.widget.data.*
import java.time.Instant
import java.time.LocalDate
import java.time.ZoneId
import java.time.ZonedDateTime
import java.time.temporal.ChronoUnit
fun sourceColor(source: String): Color = when (source) {
"doot" -> Color(0xFF14B8A6)
"todoist" -> Color(0xFFE44332)
"trello" -> Color(0xFF0079BF)
"calendar" -> Color(0xFF9B59B6)
"plantoeat" -> Color(0xFF5CB85C)
"gtasks" -> Color(0xFFF39C12)
else -> Color(0xFF888888)
}
/** Parses a "#RRGGBB" string into a Glance-compatible Color, defaulting to gray on failure. */
internal fun parseGlanceHexColor(hex: String): Color = runCatching {
Color(android.graphics.Color.parseColor(hex))
}.getOrDefault(Color.Gray)
private val HALO_INSET = 1.dp
private val HALO_SPAN = 2.dp
/**
* Glance's TextStyle has no shadow parameter (checked through 1.3.0-alpha02,
* the latest available build) and RemoteViews doesn't expose
* TextView.setShadowLayer as a remotable action, so there's no direct API
* for a text drop shadow in an app widget. Faked instead by stacking four
* copies of the text at the four diagonal corners around the real text,
* forming a halo/outline -- not a single offset drop shadow.
*
* A single-corner shadow (the original version of this, 2026-07-28) only
* protects legibility on the one side it's offset toward; the other three
* sides of every glyph get no help, so text over a busy/light region of the
* wallpaper on those sides still washes out (reported 2026-08-06). Four
* corners is the "poor man's text outline" technique long used for exactly
* this class of problem (subtitles, map labels, game HUD text) wherever the
* background can't be controlled or blurred. True N/S/E/W-neighbor outline
* would be marginally more even, but Glance's Box has no negative-padding
* or per-child-alignment primitive to express that -- only "push further
* from the shared top-start anchor" -- so diagonal corners is what's
* actually achievable with the stacking trick already in use here, and it
* reads the same as true 4-neighbor at this offset distance.
*
* [haloColor] must be passed by the caller (usually palette.haloColor), not
* hardcoded here: a dark halo behind already-dark text (every light-mode
* palette variant, which uses system_*_900/_700 shades) does essentially
* nothing, since dark-on-dark blends into itself regardless of the
* wallpaper behind it. Bug found 2026-08-06 -- this used to be a module-level
* constant, always black, silently ineffective for half the themes.
*
* Cost: 5 Text nodes per call instead of 2, i.e. every call site's share of
* the widget's RemoteViews node count goes up 2.5x. Verified this doesn't
* cause rendering problems by building and installing on a real device
* emulator rather than assuming -- if a future change adds enough more text
* rows that this becomes a real concern, drop to 2 opposite corners before
* reverting to a single-side shadow.
*/
@Composable
fun ShadowedText(
text: String,
style: TextStyle,
haloColor: Color,
modifier: GlanceModifier = GlanceModifier,
maxLines: Int = Int.MAX_VALUE
) {
val shadowStyle = style.copy(color = ColorProvider(haloColor))
Box(modifier = modifier) {
Text(text = text, style = shadowStyle, maxLines = maxLines) // top-left corner
Text(
text = text, style = shadowStyle, maxLines = maxLines,
modifier = GlanceModifier.padding(start = HALO_SPAN) // top-right corner
)
Text(
text = text, style = shadowStyle, maxLines = maxLines,
modifier = GlanceModifier.padding(top = HALO_SPAN) // bottom-left corner
)
Text(
text = text, style = shadowStyle, maxLines = maxLines,
modifier = GlanceModifier.padding(start = HALO_SPAN, top = HALO_SPAN) // bottom-right corner
)
Text(
text = text, style = style, maxLines = maxLines,
modifier = GlanceModifier.padding(start = HALO_INSET, top = HALO_INSET) // real text, centered
)
}
}
/** Opens the event's source URL (Google Calendar, Plan to Eat, etc.) directly. */
fun calendarViewIntent(url: String): Intent =
Intent(Intent.ACTION_VIEW, Uri.parse(url.ifEmpty { "https://calendar.google.com" })).apply {
addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
}
@Composable
fun AllDayRow(
event: WidgetItem,
textSize: WidgetTextSize,
variant: MultiDayVariant = MultiDayVariant.NONE,
palette: WidgetPalette,
titleColor: Color = palette.textPrimary
) {
val label = multiDayLabel(event, variant)
Row(
modifier = GlanceModifier
.fillMaxWidth()
.padding(vertical = 3.dp)
.clickable(actionStartActivity(calendarViewIntent(event.url))),
verticalAlignment = Alignment.CenterVertically
) {
// Matches HourRow's 32dp hour-label gutter so this row's text lines up
// with EventBlock's text in the grid below it, instead of sitting flush left.
Spacer(modifier = GlanceModifier.width(32.dp))
ShadowedText(
text = event.title,
style = TextStyle(
color = ColorProvider(titleColor),
fontSize = textSize.scaledContentSize(13),
fontWeight = textSize.scaledContentWeight(FontWeight.Medium)
),
haloColor = palette.haloColor,
modifier = GlanceModifier.padding(start = 8.dp),
maxLines = 1
)
if (label.isNotEmpty()) {
ShadowedText(
// Full opacity, matching EventBlock's upcoming (non-past) events --
// the label is time-relevant info, not secondary chrome.
text = label,
style = TextStyle(
color = ColorProvider(titleColor),
fontSize = textSize.scaledContentSize(13),
fontWeight = textSize.scaledContentWeight(FontWeight.Medium)
),
haloColor = palette.haloColor,
modifier = GlanceModifier.padding(start = 4.dp),
maxLines = 1
)
}
}
}
@Composable
fun RefreshButton(isRefreshing: Boolean, palette: WidgetPalette) {
Box(
modifier = GlanceModifier
.size(24.dp)
.clickable(actionRunCallback<RefreshTaskAction>()),
contentAlignment = Alignment.Center
) {
Image(
provider = ImageProvider(
if (isRefreshing) org.terst.doot.widget.R.drawable.ic_refresh_loading
else org.terst.doot.widget.R.drawable.ic_refresh
),
contentDescription = if (isRefreshing) "Refreshing" else "Refresh",
colorFilter = ColorFilter.tint(ColorProvider(palette.textSecondary)),
modifier = GlanceModifier.size(14.dp)
)
}
}
@Composable
fun QuickAddButton(palette: WidgetPalette) {
val context = LocalContext.current
val intent = Intent(context, QuickAddActivity::class.java).apply {
addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
}
Box(
modifier = GlanceModifier
.size(24.dp)
.clickable(actionStartActivity(intent)),
contentAlignment = Alignment.Center
) {
Image(
provider = ImageProvider(org.terst.doot.widget.R.drawable.ic_add),
contentDescription = "Add task",
colorFilter = ColorFilter.tint(ColorProvider(palette.textSecondary)),
modifier = GlanceModifier.size(14.dp)
)
}
}
@Composable
fun HourRow(
hour: Int,
nowZoned: ZonedDateTime,
scheduled: List<WidgetItem>,
fragments: List<TaskFragment>,
@Suppress("UNUSED_PARAMETER") zone: ZoneId,
textSize: WidgetTextSize,
palette: WidgetPalette,
hideCheckboxes: Boolean = false
) {
val hourStart = nowZoned.withHour(hour).withMinute(0).withSecond(0).withNano(0).toInstant()
val hourEnd = hourStart.plus(1, ChronoUnit.HOURS)
val isNowHour = nowZoned.hour == hour
val eventsHere = scheduled.filter { event ->
event.start?.let { s ->
val start = Instant.parse(s)
start >= hourStart && start < hourEnd
} ?: false
}
val fragsHere = fragments.filter { frag ->
frag.startTime >= hourStart && frag.startTime < hourEnd
}
Row(
modifier = GlanceModifier.fillMaxWidth().wrapContentHeight(),
verticalAlignment = Alignment.Top
) {
ShadowedText(
text = hourLabel(hour),
style = TextStyle(
color = ColorProvider(palette.textMuted),
fontSize = textSize.scaledHeaderSize(10),
fontWeight = textSize.scaledHeaderWeight(FontWeight.Normal)
),
haloColor = palette.haloColor,
modifier = GlanceModifier.width(32.dp).padding(top = 2.dp)
)
Column(modifier = GlanceModifier.defaultWeight()) {
// Hour divider line
Box(modifier = GlanceModifier.fillMaxWidth().height(1.dp).background(palette.divider)) {}
// NOW indicator
if (isNowHour) {
Box(
modifier = GlanceModifier
.fillMaxWidth()
.height(1.dp)
.background(palette.nowLine)
.padding(vertical = 2.dp)
) {}
}
// Past events never reach here -- WidgetRoot pulls them out of `scheduled`
// before this point (see isPastEvent) and renders them as list rows above
// the grid instead, the same way past tasks already float above it.
eventsHere.forEach { event ->
EventBlock(event, textSize, palette)
}
fragsHere.forEach { frag ->
TaskFragmentBlock(frag, textSize, palette, hideCheckboxes)
}
}
}
}
@Composable
fun EventBlock(event: WidgetItem, textSize: WidgetTextSize, palette: WidgetPalette) {
Row(
modifier = GlanceModifier
.fillMaxWidth()
.padding(vertical = 4.dp)
.clickable(actionStartActivity(calendarViewIntent(event.url))),
verticalAlignment = Alignment.CenterVertically
) {
ShadowedText(
text = event.title,
style = TextStyle(
color = ColorProvider(palette.textPrimary),
fontSize = textSize.scaledContentSize(14),
fontWeight = textSize.scaledContentWeight(FontWeight.Normal)
),
haloColor = palette.haloColor,
modifier = GlanceModifier.padding(start = 8.dp),
maxLines = 1
)
}
}
@Composable
fun TaskFragmentBlock(fragment: TaskFragment, textSize: WidgetTextSize, palette: WidgetPalette, hideCheckboxes: Boolean = false) {
Column(
modifier = GlanceModifier
.fillMaxWidth()
.padding(vertical = 2.dp)
) {
fragment.slots.forEach { slot ->
TaskRow(slot.task, textSize, palette, hideCheckboxes)
}
}
}
@Composable
fun TaskRow(
task: WidgetItem,
textSize: WidgetTextSize,
palette: WidgetPalette,
hideCheckboxes: Boolean = false,
titleColor: Color = palette.textPrimary,
// Null (default) preserves the grid's existing behavior, where HourRow's own
// hour-label column already supplies the 32dp gutter externally and this row
// starts flush at the Column edge. TomorrowSection passes 32.dp so its task
// rows reserve the same leading width as AllDayRow's Spacer(32.dp) and
// TimeLabeledEventRow's width(32.dp) time label, keeping titles aligned with
// tomorrow's events regardless of hideCheckboxes/completable/dot sizing.
gutterWidth: Dp? = null
) {
val context = LocalContext.current
val detailIntent = Intent(context, TaskDetailActivity::class.java).apply {
putExtra(TaskDetailActivity.EXTRA_ID, task.id)
putExtra(TaskDetailActivity.EXTRA_SOURCE, task.source)
putExtra(TaskDetailActivity.EXTRA_TITLE, task.title)
putExtra(TaskDetailActivity.EXTRA_COMPLETABLE, task.completable)
putExtra(TaskDetailActivity.EXTRA_DUE_DATE, task.dueDate)
addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
}
// Split into two sibling clickable regions to avoid the Glance/RemoteViews limitation
// where a parent clickable silently overrides a nested child clickable. The checkbox
// gets its own non-overlapping Box; the title region handles the detail-open action.
Row(
modifier = GlanceModifier
.fillMaxWidth()
.padding(
start = if (gutterWidth != null) 0.dp else 8.dp,
end = 8.dp,
top = 5.dp,
bottom = 5.dp
),
verticalAlignment = Alignment.CenterVertically
) {
// Suppressing checkboxes drops this leading element entirely rather than just
// hiding its icon -- the title Box below already carries its own 8dp start
// padding (matching EventBlock's), so with nothing ahead of it in the Row,
// task titles land flush with event titles instead of offset by unused space.
// Tradeoff: tap-to-complete-from-the-widget goes with it (TaskDetailActivity's
// Complete button still works), which is what "so everything lines up" implies.
//
// When gutterWidth is set (TomorrowSection), that reasoning doesn't apply --
// the row it's aligning against (TimeLabeledEventRow) always reserves a fixed
// 32dp leading width whether or not there's a visible label there, so this
// leading slot is reserved too, checkboxes shown or not.
val leadingContent: @Composable () -> Unit = {
if (!hideCheckboxes) {
if (task.completable) {
Box(
modifier = GlanceModifier
.size(24.dp)
.clickable(
actionRunCallback<CompleteTaskAction>(
actionParametersOf(
CompleteTaskAction.idKey to task.id,
CompleteTaskAction.sourceKey to task.source
)
)
),
contentAlignment = Alignment.Center
) {
Image(
provider = ImageProvider(org.terst.doot.widget.R.drawable.ic_checkbox_empty),
contentDescription = "Complete ${task.title}",
colorFilter = ColorFilter.tint(ColorProvider(palette.textSecondary)),
modifier = GlanceModifier.size(14.dp)
)
}
} else {
Box(
modifier = GlanceModifier
.size(8.dp)
.background(palette.textMuted)
) {}
}
}
}
if (gutterWidth != null) {
Box(modifier = GlanceModifier.width(gutterWidth), contentAlignment = Alignment.CenterStart) {
leadingContent()
}
} else {
leadingContent()
}
if (task.projectColor != null) {
Box(
modifier = GlanceModifier
.size(6.dp)
.background(parseGlanceHexColor(task.projectColor))
) {}
Spacer(modifier = GlanceModifier.width(4.dp))
}
Box(
modifier = GlanceModifier
.defaultWeight()
.clickable(actionStartActivity(detailIntent))
.padding(start = 8.dp),
contentAlignment = Alignment.CenterStart
) {
ShadowedText(
text = task.title,
style = TextStyle(
color = ColorProvider(titleColor),
fontSize = textSize.scaledContentSize(14),
fontWeight = textSize.scaledContentWeight(FontWeight.Normal)
),
haloColor = palette.haloColor,
maxLines = 1
)
}
if (task.chainTotal > 0) {
ShadowedText(
text = "${task.chainPosition}/${task.chainTotal}",
style = TextStyle(
color = ColorProvider(palette.textMuted),
fontSize = textSize.scaledContentSize(11)
),
haloColor = palette.haloColor,
modifier = GlanceModifier.padding(start = 4.dp)
)
}
if (task.bucketState == "active") {
Box(
modifier = GlanceModifier
.padding(start = 4.dp)
.clickable(
actionRunCallback<DeferTaskAction>(
actionParametersOf(DeferTaskAction.idKey to task.id)
)
)
) {
ShadowedText(
text = "defer",
style = TextStyle(
color = ColorProvider(palette.textSecondary),
fontSize = textSize.scaledContentSize(11)
),
haloColor = palette.haloColor
)
}
}
}
}
@Composable
fun TomorrowSection(
items: List<WidgetItem>,
fragments: List<TaskFragment>,
allDayEvents: List<WidgetItem>,
multiDayEvents: List<Pair<WidgetItem, MultiDayVariant>>,
zone: ZoneId,
textSize: WidgetTextSize,
palette: WidgetPalette,
hideCheckboxes: Boolean = false
) {
// This whole section renders inside a single LazyColumn `item { }` slot
// (see DootWidget.kt), which composes to one RemoteViews node -- without
// an explicit Column wrapping the divider/header/rows below, they have
// no shared vertical-flow container and all stack at the same position
// instead of flowing top-to-bottom.
Column(modifier = GlanceModifier.fillMaxWidth()) {
Box(modifier = GlanceModifier.fillMaxWidth().height(1.dp).padding(vertical = 4.dp).background(palette.divider)) {}
Row(modifier = GlanceModifier.fillMaxWidth().padding(top = 6.dp, bottom = 2.dp)) {
ShadowedText(
"TOMORROW",
style = TextStyle(
color = ColorProvider(palette.textSecondary),
fontSize = textSize.scaledHeaderSize(11),
fontWeight = textSize.scaledHeaderWeight(FontWeight.Bold)
),
haloColor = palette.haloColor
)
}
allDayEvents.forEach { AllDayRow(it, textSize, palette = palette, titleColor = palette.textSecondary) }
multiDayEvents.forEach { (item, variant) -> AllDayRow(item, textSize, variant, palette, titleColor = palette.textSecondary) }
items.forEach { item ->
if (item.type == "event") {
TimeLabeledEventRow(item, zone, textSize, palette, titleColor = palette.textSecondary)
} else {
TaskRow(
item, textSize, palette, hideCheckboxes,
titleColor = palette.textSecondary,
gutterWidth = 32.dp
)
}
}
fragments.forEach { frag ->
frag.slots.forEach { slot ->
TaskRow(
slot.task, textSize, palette, hideCheckboxes,
titleColor = palette.textSecondary,
gutterWidth = 32.dp
)
}
}
}
}
/**
* A time-label + title row for an event shown outside the hourly grid --
* used for tomorrow's events (no grid exists past today) and, since the
* 2026-08-05 "past events shouldn't stretch the grid" change, for today's
* already-ended events too (same treatment past tasks already got: once
* past, it's just a list item, not a grid slot). [titleColor]/[alpha] let
* each caller keep its own existing look -- tomorrow's events are
* de-emphasized via textSecondary at full opacity; today's past events
* keep EventBlock's previous textPrimary-at-50%-alpha treatment.
*/
@Composable
fun TimeLabeledEventRow(
event: WidgetItem,
zone: ZoneId,
textSize: WidgetTextSize,
palette: WidgetPalette,
titleColor: Color,
alpha: Float = 1f
) {
val timeLabel = event.start?.let {
val t = Instant.parse(it).atZone(zone)
hourLabel(t.hour) + if (t.minute > 0) t.minute.toString().padStart(2, '0') else ""
} ?: ""
Row(
modifier = GlanceModifier
.fillMaxWidth()
.padding(vertical = 3.dp)
.clickable(actionStartActivity(calendarViewIntent(event.url))),
verticalAlignment = Alignment.CenterVertically
) {
ShadowedText(
text = timeLabel,
style = TextStyle(
color = ColorProvider(palette.textMuted.copy(alpha = alpha)),
fontSize = textSize.scaledHeaderSize(10),
fontWeight = textSize.scaledHeaderWeight(FontWeight.Normal)
),
haloColor = palette.haloColor.copy(alpha = palette.haloColor.alpha * alpha),
modifier = GlanceModifier.width(32.dp)
)
ShadowedText(
text = event.title,
style = TextStyle(
color = ColorProvider(titleColor.copy(alpha = alpha)),
fontSize = textSize.scaledContentSize(13),
fontWeight = textSize.scaledContentWeight(FontWeight.Normal)
),
haloColor = palette.haloColor.copy(alpha = palette.haloColor.alpha * alpha),
modifier = GlanceModifier.padding(start = 8.dp),
maxLines = 1
)
}
}
/**
* True for a calendar event (never a task -- past tasks are already handled
* separately by SlotPacker) whose end time has passed. Matches the "past"
* semantics EventBlock used to compute inline before the 2026-08-05 change
* that pulls past events out of the grid entirely: an event with no end
* time is never past (still ongoing/current, not stale).
*/
internal fun isPastEvent(item: WidgetItem, now: Instant): Boolean {
if (item.type == "task") return false
val end = item.end?.let { runCatching { Instant.parse(it) }.getOrNull() } ?: return false
return end < now
}
private val MOON_PHASES = listOf("🌑", "🌒", "🌓", "🌔", "🌕", "🌖", "🌗", "🌘") // 🌑🌒🌓🌔🌕🌖🌗🌘
private val KNOWN_NEW_MOON: LocalDate = LocalDate.of(2000, 1, 6) // widely-used reference new moon (18:14 UTC)
private const val SYNODIC_MONTH_DAYS = 29.53058867
/**
* Today's moon phase, purely computed from the date -- no network call, no
* API key, just days-since-a-known-new-moon modulo the synodic month.
* Accurate to within about a day, which is the point: a small, honestly-fun
* touch for the "TODAY" header, not a navigation instrument. (Requested
* 2026-08-06 as "do something fun and surprising" -- picked this because
* it's a nice detail widgets basically never have, actually useful if you
* sail, and costs nothing to compute or maintain.)
*/
internal fun moonPhaseEmoji(date: LocalDate): String {
val daysSince = ChronoUnit.DAYS.between(KNOWN_NEW_MOON, date).toDouble()
val phase = ((daysSince % SYNODIC_MONTH_DAYS) + SYNODIC_MONTH_DAYS) % SYNODIC_MONTH_DAYS
val index = ((phase / SYNODIC_MONTH_DAYS) * MOON_PHASES.size).toInt().coerceIn(0, MOON_PHASES.size - 1)
return MOON_PHASES[index]
}
internal fun hourLabel(hour: Int): String = when {
hour == 0 -> "12a"
hour < 12 -> "${hour}a"
hour == 12 -> "12p"
else -> "${hour - 12}p"
}
internal fun calcGridStart(events: List<WidgetItem>, nowHour: Int): Int {
val earliest = events.mapNotNull { it.start }
.mapNotNull { runCatching { Instant.parse(it) }.getOrNull() }
.minOrNull()
?.atZone(ZoneId.systemDefault())?.hour
?: nowHour
return maxOf(0, minOf(earliest, nowHour) - 1)
}
internal fun calcGridEnd(events: List<WidgetItem>, nowHour: Int): Int {
val latest = events.mapNotNull { it.end }
.mapNotNull { runCatching { Instant.parse(it) }.getOrNull() }
.maxOrNull()
?.atZone(ZoneId.systemDefault())?.hour
?: (nowHour + 8)
return minOf(23, maxOf(latest, nowHour + 1) + 1)
}
|