ussrinivas / google-rfc-2445

Automatically exported from code.google.com/p/google-rfc-2445
Apache License 2.0
0 stars 0 forks source link

<!DOCTYPE PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

Read Me

Online Documentation

The javadoc is available online.

Downloading

The source is available from subversion. See the project page for instructions on how to download the source from subversion.

Building

Requires ant to build with junit for testing, and optionally joda-time installed.

Once you've got ant set up and installed, run ant default to build the jars and documentation, and then read the documentation in the docs directory. You can use the jar at jars/rfc2445.jar in your program.

To build without joda-time, run ant rfc2445-no-joda and it will produce a version of the jar without the joda-time compatibility classes.

Using

Using the API is pretty easy. Pass in some ical and you get back a date iterable, which can be used in a for-each loop thusly:

// A compatibility layer for joda-time
import com.google.ical.compat.jodatime.LocalDateIteratorFactory;
// A Joda time class that represents a day regardless of timezone
import org.joda.time.LocalDate;

public class ThirteenFridaysTheThirteenth {

  /** print the first 13 Friday the 13ths in the 3rd millenium AD. */
  public static void main(String[] args) throws java.text.ParseException {
    LocalDate start = new LocalDate(2001, 4, 13);

    // Every friday the thirteenth.
    String ical = "RRULE:FREQ=MONTHLY"
                  + ";BYDAY=FR"  // every Friday
                  + ";BYMONTHDAY=13"  // that occurs on the 13th of the month
                  + ";COUNT=13";  // stop after 13 occurences

    // Print out each date in the series.
    for (LocalDate date :
         LocalDateIteratorFactory.createLocalDateIterable(ical, start, true)) {
      System.out.println(date);
    }
  }

}

See RFC 2445 for the recurrence rule syntax and what it means, and the examples later in the same document.

If you use java.util.Date and java.util.Calendar in your application instead of Joda-Time, you can use the com.google.ical.compat.javautil package instead to provide Date objects.

Running tests

If you make source changes, you can run ant runtests to run build and run the tests.