/** * Get the month of a date. The first month of the year is JANUARY which is 0. * @param when The date. * @param tz The time zone; if null, the current time zone is assumed. */ public static final int monthOfDate(Date when, TimeZone tz) { if (tz == null) tz = TimeZones.getCurrent(); final Calendar cal = Calendar.getInstance(tz); cal.setTimeInMillis(when.getTime()); //don't call cal.setTime(Date) which will reset the TimeZone. return cal.get(Calendar.MONTH); }
_timeZone = TimeZones.getTimeZone(-timeZoneOfs);
/** Carry over the info stored in the constructor to * the current thread. */ public void carryOver() { ExecutionsCtrl.setCurrent(_exec); final ExecutionCtrl execCtrl = (ExecutionCtrl) _exec; execCtrl.onActivate(); if (Locales.getThreadLocal() == null) Locales.setThreadLocal(_locale); else _locale = null; if (TimeZones.getThreadLocal() == null) TimeZones.setThreadLocal(_timeZone); else _timeZone = null; final Page page = _exec.getDesktop().getFirstPage(); if (page != null) execCtrl.setCurrentPage(page); }
public static final void cleanup(ServletRequest request, Object old) { if (old != null) { request.removeAttribute(ATTR_SETUP); SessionsCtrl.setCurrent((Session) null); final Object[] op = (Object[]) old; TimeZones.setThreadLocal((TimeZone) op[1]); DateFormats.setLocalFormatInfo((DateFormatInfo) op[2]); Charsets.cleanup(request, op[0]); } }
/** Cleans up the info carried from onPiggyback to the current thread. * <p>Note: {@link #carryOver} and {@link #cleanup} must be * called in the same thread. */ public void cleanup() { ((ExecutionCtrl) _exec).onDeactivate(); ExecutionsCtrl.setCurrent(null); if (_locale != null) Locales.setThreadLocal(null); if (_timeZone != null) TimeZones.setThreadLocal(null); } }
/** * Whether the given date in the specified TimeZone is the first day of that * month. If TimeZone is null, meaning use default TimeZone of the JVM. */ final public static boolean isBeginOfMonth(Date when, TimeZone tz) { if (tz == null) tz = TimeZones.getCurrent(); final Calendar cal = Calendar.getInstance(tz); cal.setTimeInMillis(when.getTime()); //don't call cal.setTime(Date) which will reset the TimeZone. final int day = cal.get(Calendar.DAY_OF_MONTH); return day == 1; } /**
private static final Object setup(Object sess, ServletRequest request, ServletResponse response, String charset) { final Object[] old; if (request.getAttribute(ATTR_SETUP) != null) { //has been setup old = null; } else { final HttpSession hsess; if (sess instanceof Session) { final Session se = (Session) sess; //Invoke the request interceptors se.getWebApp().getConfiguration().invokeRequestInterceptors(se, request, response); hsess = (HttpSession) se.getNativeSession(); } else { hsess = (HttpSession) sess; } final Object ol = Charsets.setup(hsess, request, response, charset); //Charsets will handle PREFERRED_LOCALE //time zone final TimeZone tz = getTimeZone(hsess); final Object otz = TimeZones.setThreadLocal(tz); //date format info final DateFormatInfo dfinfo = getDateFormatInfo(hsess); final Object odi = DateFormats.setLocalFormatInfo(dfinfo); request.setAttribute(ATTR_SETUP, Boolean.TRUE); //mark as setup old = new Object[] { ol, otz, odi }; } if (sess instanceof Session) SessionsCtrl.setCurrent((Session) sess); return old; }
/** * Get the day of month of a date. The first day of the month has value 1. * @param when The date. * @param tz The time zone; if null, the current time zone is assumed. */ public static final int dayMonthOfDate(Date when, TimeZone tz) { if (tz == null) tz = TimeZones.getCurrent(); final Calendar cal = Calendar.getInstance(tz); cal.setTimeInMillis(when.getTime()); //don't call cal.setTime(Date) which will reset the TimeZone. return cal.get(Calendar.DAY_OF_MONTH); }
TimeZones.setThreadLocal(_timeZone); TimeZones.setThreadLocal(_timeZone = null);
/** * Given a date, a proper TimeZone, return the two month int. e.g. 1, 3, 5, 7, 9, 11. * If TimeZone is null, meaning use default TimeZone of the JVM. */ final public static short twoMonthShort(Date when, TimeZone tz) { if (tz == null) tz = TimeZones.getCurrent(); final Calendar cal = Calendar.getInstance(tz); cal.setTimeInMillis(when.getTime()); //don't call cal.setTime(Date) which will reset the TimeZone. final int month = (cal.get(Calendar.MONTH) / 2) * 2 + 1; return (short)month; }
/** * Get the month of a date. The first month of the year is JANUARY which is 1. * @param when The date. * @param tz The time zone; if null, the current time zone is assumed. */ public static final int monthOfDatePlus1(Date when, TimeZone tz) { if (tz == null) tz = TimeZones.getCurrent(); final Calendar cal = Calendar.getInstance(tz); cal.setTimeInMillis(when.getTime()); //don't call cal.setTime(Date) which will reset the TimeZone. return cal.get(Calendar.MONTH) + 1; }
/** * Whether the given date in the specified TimeZone is the last day of that * month. If TimeZone is null, meaning use default TimeZone of the JVM. */ final public static boolean isEndOfMonth(Date when, TimeZone tz) { if (tz == null) tz = TimeZones.getCurrent(); final Calendar cal = Calendar.getInstance(tz); cal.setTimeInMillis(when.getTime()); //don't call cal.setTime(Date) which will reset the TimeZone. final int day = cal.get(Calendar.DAY_OF_MONTH); final int maxDay = cal.getActualMaximum(Calendar.DAY_OF_MONTH); return day == maxDay; }
/** * Get the year of a date. * @param when The date. * @param tz The time zone; if null, the current time zone is assumed. * @see #localizedYearOfDate */ public static final int yearOfDate(Date when, TimeZone tz) { if (tz == null) tz = TimeZones.getCurrent(); final Calendar cal = Calendar.getInstance(tz); cal.setTimeInMillis(when.getTime()); //don't call cal.setTime(Date) which will reset the TimeZone. return cal.get(Calendar.YEAR); }
/** * Date Arithmetic function. Adds the specified (signed) amount of time to the given date, * based on the calendar's rules. * @param when The based date. * @param tz The time zone; if null, the current time zone is assumed. * @param field The time field. * @param amount The amount of date or time to be added to the field. */ public static final Date add(Date when, TimeZone tz, int field, int amount) { if (tz == null) tz = TimeZones.getCurrent(); final Calendar cal = Calendar.getInstance(tz); cal.setTimeInMillis(when.getTime());//don't call cal.setTime(Date) which will reset the TimeZone. cal.add(field, amount); return cal.getTime(); }
private static SimpleDateFormat getDateFormat(TimeZone tzone) { SimpleDateFormat df = new SimpleDateFormat("yyyyMMdd", Locales.getCurrent()); df.setTimeZone(tzone != null ? tzone : TimeZones.getCurrent()); return df; }
/** Returns the date format of the time only, * * <p>Default: it uses SimpleDateFormat to format the date. */ protected DateFormat getDateFormat(String fmt) { final DateFormat df = new SimpleDateFormat(fmt, _locale != null ? _locale : Locales.getCurrent()); final TimeZone tz = _tzone != null ? _tzone : TimeZones.getCurrent(); df.setTimeZone(tz); return df; }
/** * Given a date, a proper TimeZone, return the beginning date of * the specified date and TimeZone. If TimeZone is null, meaning use Default * TimeZone of the JVM. */ final public static Date beginOfDate(Date when, TimeZone tz) { if (tz == null) tz = TimeZones.getCurrent(); final Calendar cal = Calendar.getInstance(tz); cal.setTimeInMillis(when.getTime());//don't call cal.setTime(Date) which will reset the TimeZone. final int day = cal.get(Calendar.DAY_OF_MONTH); final int year = cal.get(Calendar.YEAR); final int month = cal.get(Calendar.MONTH); cal.clear(); cal.set(year, month, day); return cal.getTime(); }
private DateFormat getDateFormat() { final DateFormat df = new SimpleDateFormat("yyyy/MM/dd", Locales.getCurrent()); df.setTimeZone(TimeZones.getCurrent()); return df; }
private static SimpleDateFormat getLocalizedSimpleDateFormat(String formatPtn) { SimpleDateFormat sdf = new SimpleDateFormat(formatPtn, Locales.getCurrent()); sdf.setTimeZone(TimeZones.getCurrent()); return sdf; } }
private static SimpleDateFormat getLocalizedSimpleDateFormat(String formatPtn) { SimpleDateFormat sdf = new SimpleDateFormat(formatPtn, Locales.getCurrent()); sdf.setTimeZone(TimeZones.getCurrent()); return sdf; } }