This repository was archived by the owner on Oct 8, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 72
/
Copy pathConfigurationSchedule.swift
82 lines (73 loc) · 2.25 KB
/
ConfigurationSchedule.swift
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
//
// ConfigurationSchedule.swift
// RsyncOSX
//
// Created by Thomas Evensen on 02/05/16.
// Copyright © 2016 Thomas Evensen. All rights reserved.
//
import Foundation
struct Log: Codable {
var dateExecuted: String?
var resultExecuted: String?
var date: Date {
return dateExecuted?.en_us_date_from_string() ?? Date()
}
}
struct ConfigurationSchedule: Codable {
var hiddenID: Int
var offsiteserver: String?
var dateStart: String
var dateStop: String?
var schedule: String
var logrecords: [Log]?
var profilename: String?
var delete: Bool?
// Used when reading JSON data from store
// see in ReadScheduleJSON
init(_ data: DecodeSchedule) {
dateStart = data.dateStart ?? ""
dateStop = data.dateStop
hiddenID = data.hiddenID ?? -1
offsiteserver = data.offsiteserver
schedule = data.schedule ?? ""
for i in 0 ..< (data.logrecords?.count ?? 0) {
if i == 0 { logrecords = [Log]() }
var log = Log()
log.dateExecuted = data.logrecords?[i].dateExecuted
log.resultExecuted = data.logrecords?[i].resultExecuted
logrecords?.append(log)
}
}
// Create an empty record with no values
init() {
hiddenID = -1
dateStart = ""
schedule = ""
}
}
extension ConfigurationSchedule: Hashable, Equatable {
static func == (lhs: ConfigurationSchedule, rhs: ConfigurationSchedule) -> Bool {
return lhs.hiddenID == rhs.hiddenID &&
lhs.dateStart == rhs.dateStart &&
lhs.schedule == rhs.schedule &&
lhs.dateStop == rhs.dateStop &&
lhs.offsiteserver == rhs.offsiteserver
}
func hash(into hasher: inout Hasher) {
hasher.combine(String(hiddenID))
hasher.combine(dateStart)
hasher.combine(schedule)
hasher.combine(dateStop)
hasher.combine(offsiteserver)
}
}
extension Log: Hashable, Equatable {
static func == (lhs: Log, rhs: Log) -> Bool {
return lhs.dateExecuted == rhs.dateExecuted &&
lhs.resultExecuted == rhs.resultExecuted
}
func hash(into hasher: inout Hasher) {
hasher.combine(dateExecuted)
hasher.combine(resultExecuted)
}
}