EventParser

final class EventParser

Parser for a sched.com .ics file, based on https://jococruise2019.sched.com export.

  • Parses an array of raw sched.com .ics strings to an Event array.

    Declaration

    Swift

    func parse(_ dataString: String) throws -> [Event]

    Parameters

    icsArray

    Array of strings from a sched.com .ics export.

    connection

    The connection to a database.

    Return Value

    [Event] containing the events.

  • Creates an Event from an array of the raw lines appearing between BEGIN:VEVENT and END:VEVENT lines in a sched.com .ics file. Escape characters that may appear in “SUMMARY”, “DESCRIPTION” and “LOCATION” values are stripped.

    Declaration

    Swift

    func makeEvent(from properties: [String]) throws -> Event?

    Parameters

    components

    [String] containing the lines to be processed.

    Return Value

    Event if the date strings could be parsed, else nil.

  • Declaration

    Swift

    func unescapedTextValue(_ value: any StringProtocol) -> String
  • Declaration

    Swift

    let gmtDateFormatter: DateFormatter
  • Declaration

    Swift

    let tzDateFormatter: DateFormatter
  • Declaration

    Swift

    func parseDateFromProperty(property keyAndParams: [Substring], value: String) throws -> Date

Validation

  • Takes a set of schedule events and compares it against the db. Returns a summary of what would change if the schedule is applied. Shows deleted events, added events, events with modified times, events with changes to their title or description text).

    Declaration

    Swift

    func validateEvents(_ updateEvents: [Event], updatesAgeRating: Bool, on db: Database) async throws -> EventUpdateDifferenceData

    Parameters

    updateEvents

    The new schedule, from parse() on a sched.com .ics export or from SchedSession.makeEvent().

    updatesAgeRating

    TRUE if the source carries age ratings (the Sched API does, the .ics export doesn’t). If FALSE, age ratings are ignored when looking for changes.

    db

    The connection to a database.

    Return Value

    EventUpdateDifferenceData with info on the events that were modified/added/removed .

  • Takes a set of schedule events, updates the db with new info from the schedule. Returns a summary of what changed and how (deleted events, added events, events with modified times, events with changes to their title or description text).

    Declaration

    Swift

    func updateDatabase(from updateEvents: [Event], updatesAgeRating: Bool, on db: Database, forumAuthor: UserHeader,
    		processDeletes: Bool = true, makeForumPosts: Bool = true) async throws

    Parameters

    updateEvents

    The new schedule, from parse() on a sched.com .ics export or from SchedSession.makeEvent().

    updatesAgeRating

    TRUE if the source carries age ratings. If FALSE, existing events keep their age ratings.

    db

    The connection to a database.

    forumAuthor

    If there are changes and makeForumPosts is TRUE, the user to use as the author of the relevant forum posts.

    processDeletes

    If TRUE (the default) events in the db but not in scheduleFileStr will be deleted from the db. Set to FALSE if you are applying a schedule patch (e.g. a schedule file with a single new event).

    makeForumPosts

    Adds forum posts to each Event forum’s thread announcing the changes that were made to the event.