Example usage for org.springframework.format.datetime.joda JodaTimeContextHolder getJodaTimeContext

List of usage examples for org.springframework.format.datetime.joda JodaTimeContextHolder getJodaTimeContext

Introduction

In this page you can find the example usage for org.springframework.format.datetime.joda JodaTimeContextHolder getJodaTimeContext.

Prototype

@Nullable
public static JodaTimeContext getJodaTimeContext() 

Source Link

Document

Return the JodaTimeContext associated with the current thread, if any.

Usage

From source file:net.asfun.jangod.lib.filter.DatetimeFilter.java

@Override
public Object filter(Object object, JangodInterpreter interpreter, String... arg) throws InterpretException {
    if (object == null) {
        return object;
    }//from www . j a  v  a  2s .  c  o m
    if (object instanceof DateTime) { // joda DateTime
        DateTimeFormatter formatter;
        DateTimeFormatter a = DateTimeFormat.forPattern(interpreter.evaluateExpressionAsString(arg[0]));
        if (arg.length == 1) {
            DateTimeFormatter forPattern = a;
            JodaTimeContext jodaTimeContext = JodaTimeContextHolder.getJodaTimeContext();
            if (jodaTimeContext == null) {
                jodaTimeContext = new JodaTimeContext();
            }
            formatter = jodaTimeContext.getFormatter(forPattern);
        } else if (arg.length == 2) {
            formatter = a.withChronology(ISOChronology
                    .getInstance(DateTimeZone.forID(interpreter.evaluateExpressionAsString(arg[1]))));
        } else {
            throw new InterpretException("filter date expects 1 or 2 args >>> " + arg.length);
        }
        return formatter.print((DateTime) object);
    } else {
        SimpleDateFormat sdf;
        if (arg.length == 1) {
            sdf = new SimpleDateFormat(interpreter.evaluateExpressionAsString(arg[0]));
            sdf.setTimeZone(interpreter.getConfiguration().getTimezone());
        } else if (arg.length == 2) {
            sdf = new SimpleDateFormat(interpreter.evaluateExpressionAsString(arg[0]));
            sdf.setTimeZone(TimeZone.getTimeZone(interpreter.evaluateExpressionAsString(arg[1])));
        } else {
            throw new InterpretException("filter date expects 1 or 2 args >>> " + arg.length);
        }
        return sdf.format(object);
    }
}

From source file:com.springsource.greenhouse.home.DateTimeZoneHandlerInterceptor.java

public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler,
        ModelAndView modelAndView) throws Exception {
    if (modelAndView != null) {
        modelAndView.addObject("jodaTimeContext", JodaTimeContextHolder.getJodaTimeContext());
    }//  www . j a  va  2s.co m
}

From source file:name.cphillipson.experimental.gwt.server.interceptor.DateTimeZoneHandlerInterceptor.java

@Override
public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler,
        ModelAndView modelAndView) throws Exception {
    if (modelAndView != null) {
        modelAndView.addObject("jodaTimeContext", JodaTimeContextHolder.getJodaTimeContext());
    }/*w  ww  . ja v a 2  s.c o m*/
}