I calendar parsing
1

Configure Feed

Select the types of activity you want to include in your feed.

Gleam 100.0%
12 1 0

Clone this repository

https://git.vm.fail/kwando.tngl.sh/gcal https://git.vm.fail/did:plc:cajnfvmvbzh5xiijl6ipc4df
ssh://git@knot1.tangled.sh:2222/kwando.tngl.sh/gcal ssh://git@knot1.tangled.sh:2222/did:plc:cajnfvmvbzh5xiijl6ipc4df

For self-hosted knots, clone URLs may differ based on your setup.


README.md

gcal#

An iCal (.ics) parser for Gleam. Parses VCALENDAR and VEVENT components with full support for folded lines, escaped text, property parameters, and timezone-aware datetime resolution.

gleam add gcal
import gcal
import gleam/option
import gleam/time/timestamp
import tzif/database

pub fn main() {
  let ical = "BEGIN:VCALENDAR\nVERSION:2.0\nPRODID:-//Test//EN\n"
    <> "BEGIN:VEVENT\nSUMMARY:Meeting\n"
    <> "DTSTART:20230101T100000Z\nDTEND:20230101T110000Z\n"
    <> "UID:123@test\nEND:VEVENT\nEND:VCALENDAR"

  let assert Ok(db) = database.load_from_os()
  let parser = gcal.new_parser(db)
  let assert Ok(calendar) = gcal.parse(parser, ical, option.None)

  calendar.timezone
  // -> "UTC"

  let assert [event] = calendar.events
  event.summary
  // -> "Meeting"
  event.is_all_day
  // -> False
  timestamp.to_unix_seconds(event.dtstart)
  // -> 1672567200.0
}

API#

  • new_parser(tz_db: TzDatabase) -> Parser — create a parser with a timezone database.
  • parse(parser: Parser, input: String, timezone: Option(String)) -> Result(Calendar, ParseError) — parse an iCal string. Pass Some(tz) to resolve floating times to a specific timezone, or None to use X-WR-TIMEZONE or UTC.

Development#

gleam test  # Run the tests