Groovy web console

subscribe to the feed Subscribe
to this
site

Weekly Confluence Link Markup

Published 9 years ago by Burke Mamlin with tags openmrs confluence wiki markup calendar
Actions  ➤ Edit in console Back to console Show/hide line numbers View recent scripts
/*
Generate calendar of Confluence wiki links for weekly meetings

This is a handy little script for generating wiki markup for a bunch
of links to weekly meeting minutes.  It demonstrates some Groovy 
Calendar fun along with some Groovy date range fun.
*/
import static java.util.Calendar.*
startDate = Calendar.instance
endDate = Calendar.instance

// Define date range for links
startDate.set 2005, NOVEMBER, 3
endDate.time += 30 // go up to 30 days in the future

// Define format of page name
pageName = "%tY-%<tm-%<td Developers Conference Call"

date = Calendar.instance
month = year = -1
firstDay = true
(startDate.time..endDate.time).step(7) // range of dates for each week
.sort{ a,b -> a.year==b.year && a.month==b.month ? a <=> b : -(a <=> b) } // year/month desc, day asc
.each{ d ->
  date.time = d
  dateMonth = date.get(MONTH)
  dateYear = date.get(YEAR)
  
  if (year != dateYear) {
    print "\n{expand}\n\n{expand:$dateYear}"
    year = dateYear
  }
  if (month != dateMonth) {
    print String.format("\n* %tb: ", date.time)
    month = dateMonth
    firstDay = true
  }
  if (!firstDay) print " | "
  print "[${date.get(DAY_OF_MONTH)}|${String.format(pageName,date.time)}]"
  firstDay = false
  date.time -= 7
}