Showing Upcoming Concerts

A slight variation of my “Upcoming Days Off”: “Upcoming Concerts” (which I also store in a separate calendar; this time called “Concerts”):

function handleEvents(events) {
  let table = new UITable();
  for (event of events) {
    let row = new UITableRow();
    row.height = 40;
    row.cellSpacing = 10;
    let columnOptions = [
      {value: event.startDate, format: {weekday: "long"   }, align: "right",  weight: 100},
      {value: event.startDate, format: {day:     "2-digit"}, align: "center", weight:  10},
      {value: event.startDate, format: {month:   "long"   }, align: "left",   weight: 100},
      {value: event.title,                                   align: "left",   weight: 100},
      {value: event.location,                                align: "left",   weight: 150}
    ];
    for (options of columnOptions) {
      let cell = createCell(options);
      row.addCell(cell);
    }
    table.addRow(row);
  }
  QuickLook.present(table);
}

function createCell(options) {
  let value = options["value"];
  let format = options["format"];
  let text = format ? value.toLocaleDateString("en-US", format) : value;
  let cell = UITableCell.text(text);
  cell.widthWeight = options["weight"];
  cell[options["align"] + "Aligned"]();
  return cell;
}

function handleError(val) {
  console.error(val);
}

function handleCalendar(calendar) {
  let start = new Date();
  let end   = new Date(2999, 11, 31);
  CalendarEvent.between(start, end, [calendar]).then(handleEvents, handleError);
}  

let calendar = Calendar.forEventsByTitle("Concerts").then(handleCalendar, handleError);

This code is even less clean than the “Upcoming Days Off”, but it does the job for now…

It shows the date (like in “Upcoming Days Off”), but also the title (usually name of the band) and location (usually name of the venue or festival).

3 Likes

Hm. Siri shortcuts finally worked one time for me with iOS 12 Beta 8.

This script puts too much info in a row… (I was checking the layout in full screen landscape so far)