Merge branch '2.x' of https://github.com/jianstm/Schedule into 2.x
This commit is contained in:
commit
6df23ae87e
|
@ -8,11 +8,6 @@ struct BagKey: Equatable {
|
||||||
fileprivate init(underlying: UInt64) {
|
fileprivate init(underlying: UInt64) {
|
||||||
self.i = underlying
|
self.i = underlying
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns a Boolean value indicating whether two BagKeys are equal.
|
|
||||||
static func == (lhs: BagKey, rhs: BagKey) -> Bool {
|
|
||||||
return lhs.i == rhs.i
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A generator that can generate a sequence of unique `BagKey`.
|
/// A generator that can generate a sequence of unique `BagKey`.
|
||||||
|
@ -65,10 +60,7 @@ struct Bag<Element> {
|
||||||
|
|
||||||
/// Returns the element associated with a given key.
|
/// Returns the element associated with a given key.
|
||||||
func value(for key: BagKey) -> Element? {
|
func value(for key: BagKey) -> Element? {
|
||||||
if let entry = entries.first(where: { $0.key == key }) {
|
return entries.first(where: { $0.key == key })?.val
|
||||||
return entry.val
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Removes the given key and its associated element from this bag.
|
/// Removes the given key and its associated element from this bag.
|
||||||
|
|
|
@ -12,13 +12,7 @@ public struct Interval {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
extension Interval: Hashable {
|
extension Interval: Hashable { }
|
||||||
|
|
||||||
/// Returns a boolean value indicating whether two intervals are equal.
|
|
||||||
public static func == (lhs: Interval, rhs: Interval) -> Bool {
|
|
||||||
return lhs.nanoseconds == rhs.nanoseconds
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
extension Interval {
|
extension Interval {
|
||||||
|
|
||||||
|
|
|
@ -72,7 +72,7 @@ public struct Period {
|
||||||
let mark: Character = "秋"
|
let mark: Character = "秋"
|
||||||
str = regexp.stringByReplacingMatches(
|
str = regexp.stringByReplacingMatches(
|
||||||
in: str,
|
in: str,
|
||||||
range: NSRange(location: 0, length: str.count),
|
range: NSRange(str.startIndex..., in: str),
|
||||||
withTemplate: String(mark)
|
withTemplate: String(mark)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -85,7 +85,7 @@ public struct Period {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
var unit = String(pair[1])
|
var unit = pair[1]
|
||||||
if unit.last == "s" { unit.removeLast() }
|
if unit.last == "s" { unit.removeLast() }
|
||||||
switch unit {
|
switch unit {
|
||||||
case "year": period = period + number.years
|
case "year": period = period + number.years
|
||||||
|
|
|
@ -435,10 +435,8 @@ extension Plan {
|
||||||
guard !weekdays.isEmpty else { return .init(plan: .never) }
|
guard !weekdays.isEmpty else { return .init(plan: .never) }
|
||||||
|
|
||||||
var plan = every(weekdays[0]).plan
|
var plan = every(weekdays[0]).plan
|
||||||
if weekdays.count > 1 {
|
for weekday in weekdays.dropFirst() {
|
||||||
for i in 1..<weekdays.count {
|
plan = plan.merge(Plan.every(weekday).plan)
|
||||||
plan = plan.merge(Plan.every(weekdays[i]).plan)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return DateMiddleware(plan: plan)
|
return DateMiddleware(plan: plan)
|
||||||
}
|
}
|
||||||
|
@ -473,10 +471,8 @@ extension Plan {
|
||||||
guard !mondays.isEmpty else { return .init(plan: .never) }
|
guard !mondays.isEmpty else { return .init(plan: .never) }
|
||||||
|
|
||||||
var plan = every(mondays[0]).plan
|
var plan = every(mondays[0]).plan
|
||||||
if mondays.count > 1 {
|
for monday in mondays.dropFirst() {
|
||||||
for i in 1..<mondays.count {
|
plan = plan.merge(Plan.every(monday).plan)
|
||||||
plan = plan.merge(Plan.every(mondays[i]).plan)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return DateMiddleware(plan: plan)
|
return DateMiddleware(plan: plan)
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,15 +8,12 @@ extension TaskCenter {
|
||||||
|
|
||||||
weak var task: Task?
|
weak var task: Task?
|
||||||
|
|
||||||
let hash: Int
|
|
||||||
|
|
||||||
init(_ task: Task) {
|
init(_ task: Task) {
|
||||||
self.task = task
|
self.task = task
|
||||||
self.hash = task.hashValue
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func hash(into hasher: inout Hasher) {
|
func hash(into hasher: inout Hasher) {
|
||||||
hasher.combine(hash)
|
hasher.combine(task)
|
||||||
}
|
}
|
||||||
|
|
||||||
static func == (lhs: TaskBox, rhs: TaskBox) -> Bool {
|
static func == (lhs: TaskBox, rhs: TaskBox) -> Bool {
|
||||||
|
|
|
@ -50,10 +50,11 @@ public struct Time {
|
||||||
|
|
||||||
// swiftlint:disable force_try
|
// swiftlint:disable force_try
|
||||||
let regexp = try! NSRegularExpression(pattern: pattern, options: [])
|
let regexp = try! NSRegularExpression(pattern: pattern, options: [])
|
||||||
|
let nsString = NSString(string: string)
|
||||||
guard let matches = regexp.matches(
|
guard let matches = regexp.matches(
|
||||||
in: string,
|
in: string,
|
||||||
options: [],
|
options: [],
|
||||||
range: NSRange(location: 0, length: string.count)).first
|
range: NSRange(location: 0, length: nsString.length)).first
|
||||||
else {
|
else {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -61,11 +62,12 @@ public struct Time {
|
||||||
var hasAM = false
|
var hasAM = false
|
||||||
var hasPM = false
|
var hasPM = false
|
||||||
var values: [Int] = []
|
var values: [Int] = []
|
||||||
|
values.reserveCapacity(matches.numberOfRanges)
|
||||||
|
|
||||||
for i in 0..<matches.numberOfRanges {
|
for i in 0..<matches.numberOfRanges {
|
||||||
let range = matches.range(at: i)
|
let range = matches.range(at: i)
|
||||||
if range.length == 0 { continue }
|
if range.length == 0 { continue }
|
||||||
let captured = NSString(string: string).substring(with: range)
|
let captured = nsString.substring(with: range)
|
||||||
hasAM = ["am", "AM"].contains(captured)
|
hasAM = ["am", "AM"].contains(captured)
|
||||||
hasPM = ["pm", "PM"].contains(captured)
|
hasPM = ["pm", "PM"].contains(captured)
|
||||||
if let value = Int(captured) {
|
if let value = Int(captured) {
|
||||||
|
|
Loading…
Reference in New Issue