Removed Date extension (no longer needed)
This commit is contained in:
@@ -1,40 +0,0 @@
|
||||
//
|
||||
// DateExtension.swift
|
||||
// Nextcloud Cookbook iOS Client
|
||||
//
|
||||
// Created by Vincent Meilinger on 29.09.23.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
extension Date {
|
||||
static var zero: Date {
|
||||
let dateFormatter = DateFormatter()
|
||||
dateFormatter.dateFormat = "HH:mm"
|
||||
if let date = dateFormatter.date(from:"00:00") {
|
||||
return date
|
||||
} else {
|
||||
return Date()
|
||||
}
|
||||
}
|
||||
|
||||
static func toPTRepresentation(date: Date) -> String? {
|
||||
// PT0H18M0S
|
||||
let dateComponents = Calendar.current.dateComponents([.hour, .minute], from: date)
|
||||
if let hour = dateComponents.hour, let minute = dateComponents.minute {
|
||||
return "PT\(hour)H\(minute)M0S"
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
static func fromPTRepresentation(_ representation: String) -> Date {
|
||||
let (hour, minute) = DateFormatter.stringToComponents(duration: representation)
|
||||
let dateFormatter = DateFormatter()
|
||||
dateFormatter.dateFormat = "HH:mm"
|
||||
if let date = dateFormatter.date(from:"\(hour):\(minute)") {
|
||||
return date
|
||||
} else {
|
||||
return Date()
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -9,7 +9,7 @@ import Foundation
|
||||
import SwiftSoup
|
||||
|
||||
class RecipeScraper {
|
||||
func scrape(url: String) throws -> RecipeDetail? {
|
||||
func scrape(url: String) async throws -> RecipeDetail? {
|
||||
var contents: String? = nil
|
||||
if let url = URL(string: url) {
|
||||
do {
|
||||
@@ -107,7 +107,18 @@ class RecipeScraper {
|
||||
entries.append(text)
|
||||
}
|
||||
return entries
|
||||
} else if let text = dict[key] as? String {
|
||||
return [text]
|
||||
}
|
||||
return []
|
||||
}
|
||||
|
||||
private func joinedStringForKey(_ key: String, dict: Dictionary<String, Any>) -> String {
|
||||
if let value = dict[key] as? [String] {
|
||||
return value.joined(separator: ",")
|
||||
} else if let value = dict[key] as? String {
|
||||
return value
|
||||
}
|
||||
return ""
|
||||
}
|
||||
}
|
||||
|
||||
@@ -85,12 +85,14 @@ struct RecipeEditView: View {
|
||||
Section {
|
||||
TextField("URL (e.g. example.com/recipe)", text: $importURL)
|
||||
.onSubmit {
|
||||
do {
|
||||
if let recipe = try RecipeScraper().scrape(url: importURL) {
|
||||
self.recipe = recipe
|
||||
Task {
|
||||
do {
|
||||
if let recipe = try await RecipeScraper().scrape(url: importURL) {
|
||||
self.recipe = recipe
|
||||
}
|
||||
} catch {
|
||||
print("Error")
|
||||
}
|
||||
} catch {
|
||||
print("Error")
|
||||
}
|
||||
}
|
||||
} header: {
|
||||
|
||||
Reference in New Issue
Block a user