Permalink
Browse files

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

  • Loading branch information...
dima767 committed Jun 1, 2009
1 parent 09a4705 commit dd425e29b32feb58d4d6fd1b97b56362520bf6dd
Showing with 38 additions and 1 deletion.
  1. +3 −0 changelog.txt
  2. +35 −1 grails-app/taglib/NiceDateTagLib.groovy
  3. BIN lib/joda-time-1.6.jar
View
@@ -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
@@ -1,3 +1,5 @@
+import org.joda.time.*
+
class NiceDateTagLib {
public static String getNiceDate(Date date) {
@@ -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
@@ -52,6 +86,6 @@ class NiceDateTagLib {
}
def niceAgoDate = { attrs, body ->
- out << getNiceDate(attrs.date)
+ out << getNiceDateUsingJoda(attrs.date)
}
}
View
Binary file not shown.

0 comments on commit dd425e2

Please sign in to comment.