0

I am trying to benefit from the use of TimeCategory in Groovy and although it is a neat class, seems the locale to be used is stuck at English.

The documentation says that the Duration class (parent of TimeCategory) will Get the DST offset (if any) for the default locale and the given date1

Although I alter the locale in the execution of the program, there is no change in the outcome. Any hints or thoughts how can this be done?

use(groovy.time.TimeCategory) {
          expirationDate = creationDate + 5.years
          duration = expirationDate - new Date() 
}

Outputing duration is something like: 1822 days, 16 hours, 3 minutes... Stuck in English

Al-Punk
  • 3,531
  • 6
  • 38
  • 56
  • I didn't think `java.util.Date` stored any TimeZone information? – tim_yates Mar 06 '15 at 16:23
  • have a look here: http://stackoverflow.com/questions/1661325/simpledateformat-and-locale-based-format-string then take a look here https://github.com/vahidhedayati/grails-wschat-plugin/search?utf8=%E2%9C%93&q=TimeCategory and probably this class be of most use https://github.com/vahidhedayati/grails-wschat-plugin/blob/30460c5871b3bf303b5d76572c3ae647c17a8000/grails-app/controllers/grails/plugin/wschat/WsChatController.groovy#L76 – V H Mar 06 '15 at 16:35
  • @vahid thank you for the reference. The first link merely differs between the parsing operation. The link to the search of TimeZone in Github is a great idea. I followed the links but I do not see any thing different from my code. Pattern is same, parse a date from SimpleDateFormat (with or without locale, I have tried with, most examples are without) and then pass the reference to TimeCategory. Cannot find any reference on how to alter or force that Duration class or TimeCategory to inherit the locale from the app – Al-Punk Mar 06 '15 at 16:54

1 Answers1

1

It looks like you are calling .toString() on a groovy.time.TimeDuration object.

The docs don't mention anything about locale support.

It appears the toString method was created as a convenience method only for use when debugging.

You can see the source here:

https://github.com/groovy/groovy-core/blob/0b2182bff2250150e69ccb988f367e709b4560de/src/main/groovy/time/BaseDuration.java

MattZ
  • 266
  • 1
  • 6