Skip to content

Commit

Permalink
Fix compile warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
joshuawright11 committed Aug 20, 2021
1 parent 53dd8de commit dea98c9
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 45 deletions.
50 changes: 25 additions & 25 deletions Sources/Cron/DatePattern.swift
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public struct DatePattern {
guard let second: Token = ts.count > 1 ? ts[1] : nil else {
switch (first) {
case .wildcard: return .any
case .number(let num): return .number(num.0)
case .number(let num, _): return .number(num)
case .h: return .hash
case .l: return .lastDayOfMonth
case .lW: return .lastWeekdayOfMonth
Expand All @@ -70,35 +70,35 @@ public struct DatePattern {

guard let third: Token = ts.count > 2 ? ts[2] : nil else {
switch (first, second) {
case let (.slash, .number(step)):
return .step(.any, step.0)
case let (.number(dow), .l):
guard 0...7 ~= dow.0 else {
case let (.slash, .number(stepNum, _)):
return .step(.any, stepNum)
case let (.number(dowNum, _), .l):
guard 0...7 ~= dowNum else {
throw InternalError.parseError
}
return .lastDayOfWeek(DayOfWeek(rawValue: dow.0 % 7)!)
case let (.number(num), .w):
return .weekday(num.0)
return .lastDayOfWeek(DayOfWeek(rawValue: dowNum % 7)!)
case let (.number(num, _), .w):
return .weekday(num)
default:
throw InternalError.parseError
}
}

guard let forth: Token = ts.count > 3 ? ts[3] : nil else {
switch (first, second, third) {
case let (.number(begin), .hyphen, .number(end)):
return .range(begin.0, end.0)
case let (.wildcard, .slash, .number(step)):
return .step(.any, step.0)
case let (.number(num), .slash, .number(step)):
return .step(.number(num.0), step.0)
case let (.h, .hyphen, .number(step)):
return .step(.hash, step.0)
case let (.number(dow), .numberSign, .number(num)):
guard 0...7 ~= dow.0 else {
case let (.number(beginNum, _), .hyphen, .number(endNum, _)):
return .range(beginNum, endNum)
case let (.wildcard, .slash, .number(stepNum, _)):
return .step(.any, stepNum)
case let (.number(num, _), .slash, .number(stepNum, _)):
return .step(.number(num), stepNum)
case let (.h, .hyphen, .number(stepNum, _)):
return .step(.hash, stepNum)
case let (.number(dowNum, _), .numberSign, .number(num, _)):
guard 0...7 ~= dowNum else {
throw InternalError.parseError
}
return .nthDayOfWeek(DayOfWeek(rawValue: dow.0 % 7)!, num.0)
return .nthDayOfWeek(DayOfWeek(rawValue: dowNum % 7)!, num)
default:
throw InternalError.parseError
}
Expand All @@ -110,17 +110,17 @@ public struct DatePattern {

guard let sixth: Token = ts.count > 5 ? ts[5] : nil else {
switch (first, second, third, forth, fifth) {
case let (.number(begin), .hyphen, .number(end), .slash, .number(step)):
return .step(.range(begin.0, end.0), step.0)
case let (.number(beginNum, _), .hyphen, .number(endNum, _), .slash, .number(stepNum, _)):
return .step(.range(beginNum, endNum), stepNum)
default:
throw InternalError.parseError
}
}

guard let seventh: Token = ts.count > 6 ? ts[6] : nil else {
switch (first, second, third, forth, fifth, sixth) {
case let (.h, .openParen, .number(begin), .hyphen, .number(end), .closeParen):
return .rangedHash(begin.0, end.0)
case let (.h, .openParen, .number(beginNum, _), .hyphen, .number(endNum, _), .closeParen):
return .rangedHash(beginNum, endNum)
default:
throw InternalError.parseError
}
Expand All @@ -132,8 +132,8 @@ public struct DatePattern {

guard let _: Token = ts.count > 8 ? ts[8] : nil else {
switch (first, second, third, forth, fifth, sixth, seventh, eighth) {
case let (.h, .openParen, .number(begin), .hyphen, .number(end), .closeParen, .slash, .number(step)):
return .step(.rangedHash(begin.0, end.0), step.0)
case let (.h, .openParen, .number(beginNum, _), .hyphen, .number(endNum, _), .closeParen, .slash, .number(stepNum, _)):
return .step(.rangedHash(beginNum, endNum), stepNum)
default:
throw InternalError.parseError
}
Expand Down
8 changes: 4 additions & 4 deletions Sources/Cron/FieldPattern.swift
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ extension FieldPattern {
if let e = getWorkDays().dropFirst(n).first {
return .number(e)
}
return .none
return NumberSet.none
default:
return nil
}
Expand Down Expand Up @@ -121,12 +121,12 @@ extension FieldPattern {
if let e = getDoWDays(dw).dropFirst(n).first {
return .number(e)
}
return .none
return NumberSet.none
case .number(let dw):
if let e = getDoWDays(DayOfWeek(rawValue: dw)!).first {
return .step(e, 7)
}
return .none
return NumberSet.none
case .range(let begin, let end): // MON-FRI
let ret = (begin...end).reduce(.none) { NumberSet.or($0, .step($1, 7)) }
print(ret)
Expand Down Expand Up @@ -155,7 +155,7 @@ extension FieldPattern {
case .hash: return .number(Int(hash % Int64(max)))
case .rangedHash(let b, let e):
guard b < e else {
return .none
return NumberSet.none
}
return .number(Int(Int64(hash) % Int64(e - b) + Int64(b)))
default:
Expand Down
12 changes: 6 additions & 6 deletions Sources/Cron/NumberSet.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ extension NumberSet {
case .none : return false
case .any : return true
case .number(let v) : return v == n
case .range(let (begin, end)) : return begin <= n && n <= end
case .step(let (offset, step)) : return 0 == (n - offset) % step
case .or(let (a, b)) : return a.contains(n) || b.contains(n)
case .and(let (a, b)) : return a.contains(n) && b.contains(n)
case let .range(begin, end) : return begin <= n && n <= end
case let .step(offset, step) : return 0 == (n - offset) % step
case let .or(a, b) : return a.contains(n) || b.contains(n)
case let .and(a, b) : return a.contains(n) && b.contains(n)
}
}
}
Expand Down Expand Up @@ -65,14 +65,14 @@ extension NumberSet {
case .step(let offset, let step):
let d = Int(ceil(Double(n + 1 - offset) / Double(step)))
return d * step + offset
case .or(let (a, b)):
case let .or(a, b):
switch (a.next(n), b.next(n)) {
case (let x?, let y?): return min(x, y)
case (let x?, nil ): return x
case (nil , let y?): return y
case (nil , nil ): return nil
}
case .and(let (a, b)):
case let .and(a, b):
return _next_and(a, b, a.next(n), b.next(n))
}
}
Expand Down
20 changes: 10 additions & 10 deletions Tests/CronTests/ParserTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ extension Token: Equatable {}

public func == (lhs: Token, rhs: Token) -> Bool {
switch (lhs, rhs) {
case (.number(let (a, b)), .number(let (c, d))): return a == c && b == d
case (let .number(a, b), let .number(c, d)): return a == c && b == d
case (.wildcard, .wildcard): return true
case (.slash, .slash): return true
case (.hyphen, .hyphen): return true
Expand All @@ -149,16 +149,16 @@ public func == (lhs: FieldPattern, rhs: FieldPattern) -> Bool {
case (.any, .any): return true
case (.number(let a), .number(let b)): return a == b
case (.hash, .hash): return true
case (.rangedHash(let a), .rangedHash(let b)): return a.0 == b.0 && a.1 == b.1
case (.step(let a), .step(let b)): return a.0 == b.0 && a.1 == b.1
case (.range(let a), .range(let b)): return a.0 == b.0 && a.1 == b.1
case (let .rangedHash(a1, a2), let .rangedHash(b1, b2)): return a1 == b1 && a2 == b2
case (let .step(a1, a2), let .step(b1, b2)): return a1 == b1 && a2 == b2
case (let .range(a1, a2), let .range(b1, b2)): return a1 == b1 && a2 == b2

case (.lastDayOfMonth, .lastDayOfMonth): return true
case (.lastWeekdayOfMonth, .lastWeekdayOfMonth): return true
case (.weekday(let a), .weekday(let b)): return a == b

case (.lastDayOfWeek(let a), .lastDayOfWeek(let b)): return a == b
case (.nthDayOfWeek(let a), .nthDayOfWeek(let b)): return a.0 == b.0 && a.1 == b.1
case (let .lastDayOfWeek(a), let .lastDayOfWeek(b)): return a == b
case (let .nthDayOfWeek(a1, a2), let .nthDayOfWeek(b1, b2)): return a1 == b1 && a2 == b2

//case Or

Expand All @@ -173,10 +173,10 @@ public func == (lhs: NumberSet, rhs: NumberSet) -> Bool {
switch (lhs, rhs) {
case (.any, .any): return true
case (.number(let a), .number(let b)): return a == b
case (.range(let a), .range(let b)): return a.0 == b.0 && a.1 == b.1
case (.step(let a), .step(let b)): return a.0 == b.0 && a.1 == b.1
case (.or(let a), .or(let b)): return a.0 == b.0 && a.1 == b.1
case (.and(let a), .and(let b)): return a.0 == b.0 && a.1 == b.1
case (let .range(a1, a2), let .range(b1, b2)): return a1 == b1 && a2 == b2
case (let .step(a1, a2), let .step(b1, b2)): return a1 == b1 && a2 == b2
case (let .or(a1, a2), let .or(b1, b2)): return a1 == b1 && a2 == b2
case (let .and(a1, a2), let .and(b1, b2)): return a1 == b1 && a2 == b2
default: return false
}
}
Expand Down

0 comments on commit dea98c9

Please sign in to comment.