HistoryToolbarMenuCases.swift
1.57 KB
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
//
// HistoryToolbar.swift
// browser
//
// Created by Artem Talko on 14.11.2023.
//
import UIKit
enum menuCases: CaseIterable {
case allTime
case lastMonth
case todayAndYesterday
case today
case lastHour
var action: UIAction {
switch self {
case .allTime:
return UIAction(title: "All time") { _ in
HistoryDBManager.shared.cleanHistory()
}
case .lastMonth:
return UIAction(title: "The last 30 days") { _ in
let lastMonth = Calendar.current.date(byAdding: .day, value: -30, to: Date()) ?? Date()
HistoryDBManager.shared.deleteHistoryInRange(startDate: lastMonth)
}
case .todayAndYesterday:
return UIAction(title: "Today and yesterday") { _ in
let yesterday = Calendar.current.date(byAdding: .day, value: -1, to: Date()) ?? Date()
HistoryDBManager.shared.deleteHistoryInRange(startDate: yesterday)
}
case .today:
return UIAction(title: "Today") { _ in
let startOfToday = Calendar.current.startOfDay(for: Date())
HistoryDBManager.shared.deleteHistoryInRange(startDate: startOfToday)
}
case .lastHour:
return UIAction(title: "The last hour") { _ in
let lastHour = Calendar.current.date(byAdding: .hour, value: -1, to: Date()) ?? Date()
HistoryDBManager.shared.deleteHistoryInRange(startDate: lastHour)
}
}
}
}