Created
May 9, 2011 13:03
-
-
Save mresetar/962484 to your computer and use it in GitHub Desktop.
Pretty time u groovy za hrvatski locale
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
@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