Skip to content

Commit 29490a5

Browse files
committed
fix: 위젯 스냅샷 갱신 기준 시점 통일
1 parent f587821 commit 29490a5

2 files changed

Lines changed: 9 additions & 8 deletions

File tree

Widget/DevLogWidgetCore/Sources/Sync/WidgetSyncEventHandler.swift

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -40,14 +40,15 @@ private extension WidgetSyncEventHandler {
4040
case .syncRequested:
4141
Task { [weak self] in
4242
guard let self else { return }
43-
async let todaySnapshot: Void = updateTodayWidgetSnapshot()
44-
async let heatmapSnapshot: Void = updateHeatmapWidgetSnapshot()
43+
let now = Date()
44+
async let todaySnapshot: Void = updateTodayWidgetSnapshot(now: now)
45+
async let heatmapSnapshot: Void = updateHeatmapWidgetSnapshot(now: now)
4546
_ = await (todaySnapshot, heatmapSnapshot)
4647
}
4748
}
4849
}
4950

50-
func updateTodayWidgetSnapshot() async {
51+
func updateTodayWidgetSnapshot(now: Date) async {
5152
do {
5253
async let todosWithDueDate = fetchTodayTodos(
5354
dueDateFilter: .withDueDate,
@@ -65,7 +66,7 @@ private extension WidgetSyncEventHandler {
6566
)
6667
snapshotUpdater.updateTodaySnapshot(
6768
todos: (todayTodosWithDueDate + todayTodosWithoutDueDate).map(WidgetTodoSnapshot.fromDomain),
68-
now: Date()
69+
now: now
6970
)
7071
} catch {
7172
logger.error(
@@ -75,9 +76,8 @@ private extension WidgetSyncEventHandler {
7576
}
7677
}
7778

78-
func updateHeatmapWidgetSnapshot() async {
79-
let currentDate = Date()
80-
let quarterStart = Calendar.current.startOfQuarter(for: currentDate)
79+
func updateHeatmapWidgetSnapshot(now: Date) async {
80+
let quarterStart = Calendar.current.startOfQuarter(for: now)
8181
guard let nextQuarterStart = Calendar.current.date(byAdding: .month, value: 3, to: quarterStart) else {
8282
return
8383
}
@@ -108,7 +108,7 @@ private extension WidgetSyncEventHandler {
108108
completedTodos: completedTodoItems.map(WidgetTodoSnapshot.fromDomain),
109109
deletedTodos: deletedTodoItems.map(WidgetTodoSnapshot.fromDomain),
110110
quarterStart: quarterStart,
111-
now: currentDate
111+
now: now
112112
)
113113
} catch {
114114
logger.error(

Widget/DevLogWidgetCore/Tests/Sync/WidgetSyncEventHandlerTests.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ struct WidgetSyncEventHandlerTests {
4949
#expect(heatmapUpdates.first?.createdTodos.map(\.id) == ["created"])
5050
#expect(heatmapUpdates.first?.completedTodos.map(\.id) == ["completed"])
5151
#expect(heatmapUpdates.first?.deletedTodos.map(\.id) == ["deleted"])
52+
#expect(todayUpdates.first?.now == heatmapUpdates.first?.now)
5253
#expect(queries.count == 5)
5354
#expect(Set(queries.map(\.sortTarget)) == Set([
5455
.dueDate,

0 commit comments

Comments
 (0)