Last active
January 25, 2017 21:32
-
-
Save kousen/e24a8267c4394bb0c519333244d3ad57 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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