List of usage examples for java.util Date getClass
@HotSpotIntrinsicCandidate public final native Class<?> getClass();
From source file:jp.co.ctc_g.jfw.core.util.Dates.java
/** * <ul>// w w w .j ava 2 s .c o m * ????????. * </ul> * @param date * @param increment ? * @return date ??? */ public static Date addMillisecond(Date date, int increment) { if (increment == 0) { return date; } long time = date.getTime(); time = time + increment; /* * ???????????? Calendar????????java.util.Date??????? */ return instantiateDate(date.getClass(), time); }
From source file:org.pentaho.platform.repository.runtime.RuntimeElement.java
/** * Sets a date property in the paramMap. If null comes in, it removes the value from the map. Special * implementation note - Null values aren't supported in the Map. So, if a null value is passed in, this * implementation will remove the entry from the map. * /*from w ww. j ava2s. c om*/ * @param key * Key in the paramMap * @param value * The property value to set. */ public void setDateProperty(final String key, final Date value) { this.updateOk(); trace(Messages.getInstance().getString("RTREPO.DEBUG_PROPERTY_GETSET", "setDate", key)); //$NON-NLS-1$ //$NON-NLS-2$ checkType(key, value.getClass().getName(), true); Map theMap = getParamMapDT(); if (value != null) { theMap.put(key, value); } else { theMap.remove(key); } }
From source file:org.pentaho.platform.engine.services.runtime.SimpleRuntimeElement.java
/** * Sets a date property in the paramMap. If null comes in, it removes the value from the map. Special * implementation note - Null values aren't supported in the Map. So, if a null value is passed in, this * implementation will remove the entry from the map. * //from w w w.j a v a 2s.c o m * @param key * Key in the paramMap * @param value * The property value to set. */ public void setDateProperty(final String key, final Date value) { this.updateOk(); trace(Messages.getInstance().getString("RTREPO.DEBUG_PROPERTY_GETSET", "setDate", key)); //$NON-NLS-1$ //$NON-NLS-2$ Map theMap = getParamMapDT(); if (value != null) { checkType(key, value.getClass().getName(), true); theMap.put(key, value); } else { theMap.remove(key); } }
From source file:jp.co.ctc_g.jfw.core.util.Dates.java
/** * ????????.//from w w w . jav a 2 s . c o m * @param date ? * @param inclement ?.????????. * @return ?? */ public static Date addYear(Date date, int inclement) { if (inclement == 0) { return date; } Calendar currentCalendar = Dates.getCalendarInstance(date); currentCalendar.set(currentCalendar.get(Calendar.YEAR) + inclement, currentCalendar.get(Calendar.MONTH), currentCalendar.get(Calendar.DATE), currentCalendar.get(Calendar.HOUR_OF_DAY), currentCalendar.get(Calendar.MINUTE), currentCalendar.get(Calendar.SECOND)); long time = currentCalendar.getTimeInMillis(); /* * ???????????? Calendar????????java.util.Date??????? */ return instantiateDate(date.getClass(), time); }
From source file:jp.co.ctc_g.jfw.core.util.Dates.java
/** * <p>// w ww. j ava 2s .co m * ??????. * </p> * @param date ? * @return ??? */ public static Date endOfMonth(Date date) { Calendar currentCalendar = Dates.getCalendarInstance(date); int day = DAY_OF_MONTH[currentCalendar.get(Calendar.MONTH)]; if (!isLeapYear(currentCalendar.get(Calendar.YEAR)) && currentCalendar.get(Calendar.MONTH) == 1) { day--; } currentCalendar.set(currentCalendar.get(Calendar.YEAR), currentCalendar.get(Calendar.MONTH), day, currentCalendar.get(Calendar.HOUR_OF_DAY), currentCalendar.get(Calendar.MINUTE), currentCalendar.get(Calendar.SECOND)); currentCalendar.set(Calendar.MILLISECOND, 0); long time = currentCalendar.getTimeInMillis(); /* * ???????????? Calendar????????java.util.Date??????? */ return instantiateDate(date.getClass(), time); }
From source file:org.apache.openjpa.util.ProxyManagerImpl.java
public Date copyDate(Date orig) { if (orig == null) return null; if (orig instanceof Proxy) return (Date) ((Proxy) orig).copy(orig); ProxyDate proxy = getFactoryProxyDate(orig.getClass()); return (Date) proxy.copy(orig); }
From source file:jp.co.ctc_g.jfw.core.util.Dates.java
/** * ????????.<br>/*from w w w. j av a 2s. com*/ * ???????????????.<br> * :531?1??630????. * @param date ? * @param inclement ?.????????. * @return ?? */ public static Date addMonth(Date date, int inclement) { if (inclement == 0) { return date; } Calendar currentCalendar = Dates.getCalendarInstance(date); int year = currentCalendar.get(Calendar.YEAR); int calendarMonth = currentCalendar.get(Calendar.MONTH); int month = Dates.toRealMonth(calendarMonth); month += inclement; for (; (month) <= 0 || (month) >= 13;) { if ((month) >= 13) { year++; month -= 12; } else { year--; month += 12; } } int day = currentCalendar.get(Calendar.DATE); int dayOfMonth = DAY_OF_MONTH[calendarMonth]; if (day == dayOfMonth) { Date firstDate = Dates.getDate(year, month, 1); Date endOfMonth = Dates.endOfMonth(firstDate); Calendar inclementCalendar = Dates.getCalendarInstance(endOfMonth); day = inclementCalendar.get(Calendar.DATE); } currentCalendar.set(year, Dates.toCalendarMonth(month), day, currentCalendar.get(Calendar.HOUR_OF_DAY), currentCalendar.get(Calendar.MINUTE), currentCalendar.get(Calendar.SECOND)); long time = currentCalendar.getTimeInMillis(); /* * ???????????? Calendar????????java.util.Date??????? */ return instantiateDate(date.getClass(), time); }
From source file:jp.co.ctc_g.jfw.core.util.Dates.java
/** * ????????./*from w w w .j ava 2 s .c o m*/ * @param date ? * @param inclement ?.????????. * @return ?? */ public static Date addDay(Date date, int inclement) { if (inclement == 0) { return date; } Calendar currentCalendar = Dates.getCalendarInstance(date); int year = currentCalendar.get(Calendar.YEAR); int month = Dates.toRealMonth(currentCalendar.get(Calendar.MONTH)); int day = currentCalendar.get(Calendar.DATE); if (inclement >= 0) { for (int index = 0; index < inclement; index++) { day++; if (!enableDayOfMonth(year, month, day)) { day = 1; month++; if (month >= 13 || !enableDayOfMonth(year, month, day)) { month = 1; year++; } } } } else { for (int index = inclement; index < 0; index++) { day--; if (day <= 0) { month--; if (month <= 0) { year--; if (year <= 0) { throw new InternalException(Dates.class, "E-UTIL#0036"); } else { month = 12; day = DAY_OF_MONTH[11]; } } else { day = DAY_OF_MONTH[month - 1]; if (!isLeapYear(year) && month == 2) { day--; } } } } } currentCalendar.set(year, Dates.toCalendarMonth(month), day, currentCalendar.get(Calendar.HOUR_OF_DAY), currentCalendar.get(Calendar.MINUTE), currentCalendar.get(Calendar.SECOND)); long time = currentCalendar.getTimeInMillis(); /* * ???????????? Calendar????????java.util.Date??????? */ return instantiateDate(date.getClass(), time); }
From source file:jp.co.ctc_g.jfw.core.util.Dates.java
/** * <p>//from w ww .j av a 2 s . c om * ?????????. * </p> * @param date ?? * @param type ?????? * @return ??? */ public static Date truncate(Date date, DateType type) { Calendar currentCalendar = Dates.getCalendarInstance(date); int year = currentCalendar.get(Calendar.YEAR); int month = currentCalendar.get(Calendar.MONTH); int day = currentCalendar.get(Calendar.DATE); int hour = currentCalendar.get(Calendar.HOUR_OF_DAY); int minute = currentCalendar.get(Calendar.MINUTE); int second = currentCalendar.get(Calendar.SECOND); int millis = currentCalendar.get(Calendar.MILLISECOND); if (Objects.equals(type, Dates.YEAR)) { month = 0; day = 1; hour = 0; minute = 0; second = 0; millis = 0; } else if (Objects.equals(type, Dates.MONTH)) { day = 1; hour = 0; minute = 0; second = 0; millis = 0; } else if (Objects.equals(type, Dates.DAY)) { hour = 0; minute = 0; second = 0; millis = 0; } else if (Objects.equals(type, Dates.HOUR)) { minute = 0; second = 0; millis = 0; } else if (Objects.equals(type, Dates.MINUTE)) { second = 0; millis = 0; } else if (Objects.equals(type, Dates.SECOND)) { millis = 0; } else if (Objects.equals(type, Dates.MSEC)) { /* * Timestamp?????? ???????????????????? */ if (date instanceof java.sql.Timestamp) { // ??? java.sql.Timestamp timestamp = (java.sql.Timestamp) date; millis = timestamp.getNanos() / NANOS_2_MSEC; } } currentCalendar.set(year, month, day, hour, minute, second); currentCalendar.set(Calendar.MILLISECOND, millis); long afterMillis = currentCalendar.getTimeInMillis(); /* * ???????????? Calendar????????java.util.Date??????? */ return instantiateDate(date.getClass(), afterMillis); }
From source file:jp.co.ctc_g.jfw.core.util.Dates.java
/** * ????????./*from w w w. j a va 2 s.co m*/ * @param date ? * @param inclement ?.????????. * @return ?? */ public static Date addHour(Date date, int inclement) { if (inclement == 0) { return date; } Calendar currentCalendar = Dates.getCalendarInstance(date); int year = currentCalendar.get(Calendar.YEAR); int month = Dates.toRealMonth(currentCalendar.get(Calendar.MONTH)); int day = currentCalendar.get(Calendar.DATE); int hour = currentCalendar.get(Calendar.HOUR_OF_DAY); if (inclement >= 0) { for (int index = 0; index < inclement; index++) { hour++; if (hour >= 24) { hour = 0; day++; if (!enableDayOfMonth(year, month, day)) { day = 1; month++; if (month >= 13 || !enableDayOfMonth(year, month, day)) { month = 1; year++; } } } } } else { for (int index = inclement; index < 0; index++) { hour--; if (hour < 0) { hour = 23; day--; if (day <= 0) { month--; if (month <= 0) { year--; if (year <= 0) { throw new InternalException(Dates.class, "E-UTIL#0036"); } else { month = 12; day = DAY_OF_MONTH[11]; } } else { day = DAY_OF_MONTH[month - 1]; if (!isLeapYear(year) && month == 2) { day--; } } } } } } currentCalendar.set(year, Dates.toCalendarMonth(month), day, hour, currentCalendar.get(Calendar.MINUTE), currentCalendar.get(Calendar.SECOND)); long time = currentCalendar.getTimeInMillis(); /* * ???????????? Calendar????????java.util.Date??????? */ return instantiateDate(date.getClass(), time); }