Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
dima767 committed Jun 1, 2009
1 parent 09a4705 commit dd425e2
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 1 deletion.
3 changes: 3 additions & 0 deletions changelog.txt
@@ -1,5 +1,8 @@
== Changes in version 1.3

* http://github.com/dima767/grails-crowd/issues/closed/#issue/1
* http://github.com/dima767/grails-crowd/issues/closed/#issue/3

* Upgraded to Grails 1.1.1

== Changes in version 1.2.3
Expand Down
36 changes: 35 additions & 1 deletion grails-app/taglib/NiceDateTagLib.groovy
@@ -1,3 +1,5 @@
import org.joda.time.*

class NiceDateTagLib {

public static String getNiceDate(Date date) {
Expand Down Expand Up @@ -43,7 +45,39 @@ class NiceDateTagLib {

}

public static String getNiceDateUsingJoda(Date date) {
def from = null
def to = null
try {
from = new DateTime(date)
to = new DateTime(new Date())
}
catch(Exception e) {
return ''
}

Period period = new Period(from, to, PeriodType.yearMonthDayTime())
def mi = period.minutes
def h = period.hours
def d = period.days
def m = period.months
def y = period.years

def output = ''
if(y > 0) output += "$y " + "year" + (y > 1 ? "s " : " ")
if(m > 0) output += "$m " + "month" + (m > 1 ? "s " : " ")
if(w > 0) output += "$w " + "week" + (w > 1 ? "s " : " ")
if(d > 0) output += "$d " + "day" + (d > 1 ? "s " : " ")
if(h > 0) output += "$h " + "hour" + (h > 1 ? "s " : " ")
if(mi > 0) output += "$mi " + "minute" + (mi > 1 ? "s " : " ")
if(output.size() > 0) {
output += ' ago'
}
else {
output += 'less than a minute ago'
}
return output
}

def niceDate = { attrs, body ->
def date = attrs.date
Expand All @@ -52,6 +86,6 @@ class NiceDateTagLib {
}

def niceAgoDate = { attrs, body ->
out << getNiceDate(attrs.date)
out << getNiceDateUsingJoda(attrs.date)
}
}
Binary file added lib/joda-time-1.6.jar
Binary file not shown.

0 comments on commit dd425e2

Please sign in to comment.