>     private static TimeZone getTimeZone(String timeZone) {
>       if (timeZone == null || "".equals(timeZone.trim())) {
>         return TimeZone.getDefault();
>       } else {
>         return TimeZone.getTimeZone(timeZone);
>       }
>     }
> 
> The new code you inserted does handle the timezone string a 
> bit different then above and it is probably a good idea to do 
> it everywhere the same.

Changed the DateFormat code.

    private static TimeZone getTimeZone(String timeZone) {
        if (timeZone == null || "".equals(timeZone.trim())) {
            return TimeZone.getDefault();
        } else {
            TimeZone tz = TimeZone.getTimeZone(timeZone);
            if (!tz.getID().equals(timeZone)) {
                tz = TimeZone.getDefault();
            }
            return tz;
        }
    }

> A small remark: it does not make things faster by using an if 
> statement with Calandar.getInstance(), because then Calendar 
> will lookup the timezone anyway with TimeZone.getDefault().

I don't see the difference between the 2 below in speed and I have no idea
how to write it differently. The JVM has to do the same amount of method
invocations. So what is bad in the first according to you?

    private Calendar getCalendar() {
        if (timezone != null) {
            TimeZone tz = TimeZone.getTimeZone(timezone);
            if (tz.getID().equals(timezone)) {
                return Calendar.getInstance(tz);
            }
            else {
                return Calendar.getInstance();
            }
        }
        else {
            return Calendar.getInstance();
        }
    }

    private Calendar getCalendar() {
        if (timezone != null) {
            TimeZone tz = TimeZone.getTimeZone(timezone);
            if (!tz.getID().equals(timezone)) {
                tz = TimeZone.getDefault();
            }
            return Calendar.getInstance(tz);
        }
        else {
            return Calendar.getInstance();
        }
    }

Nico
-------------------------------------------------------------
Premature optimization is the root of all evil - Donald Knuth


Reply via email to