Skip to content

Instantly share code, notes, and snippets.

@mresetar
Created May 9, 2011 13:03
Show Gist options
  • Save mresetar/962484 to your computer and use it in GitHub Desktop.
Save mresetar/962484 to your computer and use it in GitHub Desktop.
Pretty time u groovy za hrvatski locale
@Grab(group='com.ocpsoft', module='ocpsoft-pretty-time', version='1.0.7')
import groovy.time.TimeCategory
import com.ocpsoft.pretty.time.PrettyTime
Date.metaClass.pretty = {it ->
def p = new PrettyTime(it, new Locale("hr"))
p.format(delegate)
}
use(TimeCategory){
def today = new Date()
assert "za nekoliko trenutaka" == (today + 1.milliseconds).pretty(today)
assert "prije nekoliko trenutaka" == (today - 1.milliseconds).pretty(today)
assert "za 1 dan" == 24.hours.from.now.pretty(today)
assert "prije 1 dan" == (24.hours.ago - 1.second).pretty(today)
assert "za 10 minuta" == (today + 10.minutes).pretty(today)
assert "prije 20 minuta" == (today - 20.minutes).pretty(today)
assert "za 1 tjedan" == (today + 1.week).pretty(today)
assert "prije 1 tjedan" == (today - 1.week).pretty(today)
assert "za 2 tjedna" == (today + 2.week).pretty(today)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment