Giter Site home page Giter Site logo

swift-ical's Introduction

Swift-iCal

Library to generate iCalendar objects using Swift.

Dates and DateComponents

Most dates in SwiftIcal are represented using Foundations DateComponents, and not using a Date . Date Components represent a date within a calendar and a timezone. Currently Swift-iCal only support the Gregorian calendar.

For your convenience, Swift-iCal adds an extension to Date to get the date components in a given timezone.

let myDate = Date()

# Get a in the current system timezone
let myComponents = myDate.components()

# Get components in a specific timezone
let timezone = TimeZone(identifier: "America/Toronto")
let myComponents = myDate.components(timezone: timezone)

Creating a VEVENT

All events need to be wrapped into a VCALENDAR.

let timezone = TimeZone(identifier: "America/Toronto")


let start = DateComponents(calendar: Calendar.init(identifier: .gregorian),
                           timeZone: timezone,
                           year: 2020,
                           month: 5,
                           day: 9,
                           hour: 22,
                           minute: 0,
                           second: 0)

let end = DateComponents(calendar: Calendar.init(identifier: .gregorian),
                         timeZone: timezone,
                         year: 2020,
                         month: 5,
                         day: 9,
                         hour: 23,
                         minute: 0,
                         second: 0)

let event = VEvent(summary: "Hello World", dtstart: start, dtend: end)
var calendar = VCalendar()
calendar.events.append(event)
print(calendar.icalString())

This will generate a VCalendar similar to

BEGIN:VCALENDAR
PRODID:-//SwiftIcal/EN
VERSION:2.0
BEGIN:VTIMEZONE
.....
END:VTIMEZONE
BEGIN:VEVENT
DTSTAMP:20200510T000730Z
DTSTART;TZID=America/Toronto:20200509T220000
DTEND;TZID=America/Toronto:20200509T230000
SUMMARY:Hello World
UID:14490209-562F-4A52-8E42-4020A168ECD7
TRANSP:OPAQUE
CREATED:20200510T000730Z
END:VEVENT
END:VCALENDAR

Timezones

SwiftIcal uses the timezones from the timezone database. By default all required timezones are included in a generated VCalendar.

License

Swift Bindings

Swift-iCal is licenced under The Mozilla Public License 2.0.

Libical

libical is distributed under two licenses. You may choose the terms of either:

  • The Mozilla Public License (MPL) v2.0

or

  • The GNU Lesser General Public License (LGPL) v2.1

Software distributed under these licenses is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for the specific language governing rights and limitations under the License. Libical is distributed under both the LGPL and the MPL. The MPL notice, reproduced below, covers the use of either of the licenses.


swift-ical's People

Contributors

tbartelmess avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

swift-ical's Issues

TZID generate with prefix /freeassociation.sourceforge.net/

TZID is generate with prefix /freeassociation.sourceforge.net/

BEGIN:VTIMEZONE
TZID:/freeassociation.sourceforge.net/Europe/Bratislava
BEGIN:STANDARD
TZOFFSETFROM:+0200
TZOFFSETTO:+0100
TZNAME:CET
DTSTART:19961031T030000
RRULE:FREQ=YEARLY;INTERVAL=1;BYMONTH=10;BYDAY=-1SU
END:STANDARD
BEGIN:DAYLIGHT
TZOFFSETFROM:+0100
TZOFFSETTO:+0200
TZNAME:CEST
DTSTART:19810328T020000
RRULE:FREQ=YEARLY;INTERVAL=1;BYMONTH=3;BYDAY=-1SU
END:DAYLIGHT
END:VTIMEZONE
DTSTART;TZID=/freeassociation.sourceforge.net/Europe/Bratislava:20211125T184500
DTEND;TZID=/freeassociation.sourceforge.net/Europe/Bratislava:20211125T190000

Patchsets for libical

There are a few small modifications to libical so

  • it can be built without Autotools using the Swift Package manager
  • play nice with timezone files (and not having a specific prefix)

The build tooling should have an option to automatically apply those patches to libical to make it easy to keep it up to date.

Automatically generate documentation

Currently, documentation needs to be generated manually by running

jazzy \                                          
  --module SwiftIcal \
  --swift-build-tool spm \
  --build-tool-arguments -Xswiftc,-swift-version,-Xswiftc,5

This should be moved into a GitHub action to avoid drift between the code and the generated documentation.

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.