Code Monkey home page Code Monkey logo

clj-icalendar's Introduction

clj-icalendar

A Clojure library that is a very thin wrapper around ical4j.

Clojars Project

Usage

To create an empty calendar, call

(create-cal "Acme, Inc." "Acme Calendar" "V0.1" "EN")

which will return an object that, when converted to a string, produces a valid iCalendar with no events.

BEGIN:VCALENDAR
PRODID:-//Acme\\, Inc. //Acme Calendar V0.1//EN
VERSION:2.0
METHOD:PUBLISH
CALSCALE:GREGORIAN
END:VCALENDAR

To create an event with a duration, call create-event with start date, end date, title, and keyword args for unique-id, description, url, location, and organizer url. Start date and end date are of type java.util.Date. Below, ->date is a utility method that converts an ISO8601 formatted date string to a java.util.Date.

(create-event  (->date "2015-12-25T09:16:00-07:00") 
               (->date "2015-12-31T11:37:00-07:00") 
               "Family Vacation" 
               :unique-id "1234" 
               :description "Have fun." 
               :url "http://www.example.com/1234" 
               :location "1313 Mockingbird Lane" 
               :organizer "http://www.example.com")

One can also create an event that has a start time, but no duration. For this, call the function create-event-no-duration.

(create-event-no-duration  (->date "2015-12-25T09:16:00-07:00") 
                           "Let the dog out" 
                           :unique-id "1234" 
                           :description "Dog must go out" 
                           :url "http://www.example.com/1234" 
                           :location "1313 Mockingbird Lane" 
                           :organizer "http://www.example.com")

To create an all day event, call create-all-day-event. The time portion of the start date argument will be truncated.

(create-all-day-event  (->date "2015-11-16T09:16:00-07:00") 
                       "Attend Clojure Conj" 
                       :unique-id "1234" 
                       :description "Clojure/conj is the original conference for Clojure and its community." 
                       :url "http://clojure-conj.org/" 
                       :location "Philadelphia, Pennsylvania USA" 
                       :organizer "http://cognitect.com/")

To add an event to a calendar, call add-event!, passing in the calendar and the event.

(add-event! (create-cal "Acme, Inc." "Acme Calendar" "V0.1" "EN") event)

Finally, to print the output, call output-calendar, passing in the calendar, which will give an iCalendar compliant String.

(let [cal  (ical/create-cal "Acme, Inc." "Acme Calendar" "V0.1" "EN")
      ical-events (map #(ical/create-event %) events))
      _ (reduce (fn [cal event] (ical/add-event! cal event)) cal ical-events)]
    (ical/output-calendar cal))

The output should look similar to this

BEGIN:VCALENDAR
PRODID:-//Acme\\, Inc. //Acme Calendar V0.1//EN
VERSION:2.0
METHOD:PUBLISH
CALSCALE:GREGORIAN
BEGIN:VEVENT
DTSTAMP:20151025T122307Z
DTSTART:20151225T161600Z
DTEND:20151231T183700Z
SUMMARY:Spain Vacation
UID:1234
ORGANIZER:http://www.example.com
URL:http://www.example.com/1234
LOCATION:Barcelona, Spain
DESCRIPTION:Spend time at vacation home.
END:VEVENT
END:VCALENDAR

License

Copyright © 2015

Distributed under the Eclipse Public License either version 1.0 or (at your option) any later version.

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.