Skip to content

Instantly share code, notes, and snippets.

@kousen
Last active January 25, 2017 21:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save kousen/e24a8267c4394bb0c519333244d3ad57 to your computer and use it in GitHub Desktop.
Save kousen/e24a8267c4394bb0c519333244d3ad57 to your computer and use it in GitHub Desktop.
#!/usr/bin/env groovy
import java.time.LocalDate
import java.time.Month
import static java.time.temporal.ChronoUnit.*
LocalDate electionDay = LocalDate.of(2020, Month.NOVEMBER, 3)
LocalDate now = LocalDate.now()
println "${DAYS.between(now, electionDay)} days to go..."
String pluralize(long num) {
num == 1 ? '' : 's'
}
assert pluralize(1) == ''
(2..31).each { assert pluralize(it) == 's' }
long years = YEARS.between(now, electionDay)
long months = MONTHS.between(now.plusYears(years), electionDay)
long days = DAYS.between(now.plusYears(years).plusMonths(months), electionDay)
println "($years year${pluralize(years)}, $months month${pluralize(months)}, and $days day${pluralize(days)})"
assert now.plusYears(years).plusMonths(months).plusDays(days) == electionDay
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment