Coder Social home page Coder Social logo

icalswift's Introduction

iCalSwift

iCalendar(RFC 5545) encoder and decoder for Swift

Encode a VEvent

let alarm = ICalAlarm.audioProp(
            trigger: Date(),
            duration: .init(totalSeconds: 3000),
            repetition: nil,
            attach: nil)

let event = ICalEvent(
            dtstamp: Date(),
            uid: "[email protected]",
            classification: nil,
            created: Date(),
            description: "example",
            dtstart: .init(date: Date()),
            lastModified: Date(),
            location: "1",
            organizer: nil,
            priority: 1,
            seq: nil,
            status: "CONFIRMED",
            summary: "Spinning",
            transp: "SPAQUE",
            url: nil,
            dtend: nil,
            duration: nil,
            recurrenceID: Date(),
            rrule: nil,
            rdates: [Date(), Date(), Date()],
            exrule: nil,
            exdates: [Date(), Date()],
            alarms: [alarm],
            timeZone: nil,
            extendProperties: ["X-EXTEND-PROPERTY": "TEST"])

let vEncoded = event.vEncoded
        
print(vEncoded)

This will encode a VEvent to

BEGIN:VEVENT
DTSTAMP:20220305T092707Z
UID:[email protected]
CREATED:20220305T092707Z
DESCRIPTION:example
DTSTART:20220305T092707Z
LAST-MODIFIED:20220305T092707Z
LOCATION:1
PRIORITY:1
STATUS:CONFIRMED
SUMMARY:Spinning
TRANSP:SPAQUE
RECURRENCE-ID:20220305T092707Z
RRULE:FREQ=DAILY;INTERVAL=30;COUNT=3;BYMINUTE=10,30;BYDAY=1FR;WKST=SU
RDATE:20220305T092707Z
RDATE:20220305T092707Z
RDATE:20220305T092707Z
EXDATE:20220305T092707Z
EXDATE:20220305T092707Z
X-EXTEND-PROPERTY:TEST
BEGIN:VALAM
ACTION:AUDIO
TRIGGER:20220305T092707Z
DURATION:P0DT0H50M0S
END:VALAM
END:VEVENT

Decode a VEvent

let sampleICS = """
BEGIN:VEVENT
DTSTAMP:20220305T092707
UID:[email protected]
...
END:VALAM
END:VEVENT
"""

let parser = ICalParser()
let vEvents = parser.parseEvent(ics: sampleICS)
       
vEvents.forEach { vEvent in
    print(vEvent.vEncoded)
}

icalswift's People

Contributors

chan614 avatar rnine avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.