Java Code Examples for com.ibm.icu.util.Calendar#getTimeInMillis()

The following examples show how to use com.ibm.icu.util.Calendar#getTimeInMillis() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ObjectTypeTests.java    From scipio-erp with Apache License 2.0 6 votes vote down vote up
public ObjectTypeTests(String name) {
    super(name);
    ntstmp = new Timestamp(781L);
    ntstmp.setNanos(123000000);
    list = new ArrayList<Object>();
    list.add("one");
    list.add("two");
    list.add("three");
    map = new LinkedHashMap<String, Object>();
    map.put("one", "1");
    map.put("two", "2");
    map.put("three", "3");
    set = new LinkedHashSet<Object>(list);
    Calendar cal = UtilDateTime.getCalendarInstance(localeData.goodTimeZone, localeData.goodLocale);
    cal.set(1969, Calendar.DECEMBER, 31, 0, 0, 0);
    cal.set(Calendar.MILLISECOND, 0);
    sqlDt = new java.sql.Date(cal.getTimeInMillis());
}
 
Example 2
Source File: DateTimeConverters.java    From scipio-erp with Apache License 2.0 6 votes vote down vote up
public java.sql.Date convert(String obj, Locale locale, TimeZone timeZone, String formatString) throws ConversionException {
    String trimStr = obj.trim();
    if (trimStr.length() == 0) {
        return null;
    }
    DateFormat df = null;
    if (UtilValidate.isEmpty(formatString)) {
        df = UtilDateTime.toDateFormat(UtilDateTime.getDateFormat(), timeZone, locale);
    } else {
        df = UtilDateTime.toDateFormat(formatString, timeZone, locale);
    }
    try {
        java.util.Date parsedDate = df.parse(trimStr);
        Calendar cal = UtilDateTime.toCalendar(parsedDate, timeZone, locale);
        cal.set(cal.get(Calendar.YEAR), cal.get(Calendar.MONTH), cal.get(Calendar.DAY_OF_MONTH), 0, 0, 0);
        cal.set(Calendar.MILLISECOND, 0);
        return new java.sql.Date(cal.getTimeInMillis());
    } catch (ParseException e) {
        throw new ConversionException(e);
    }
}
 
Example 3
Source File: UtilDateTime.java    From scipio-erp with Apache License 2.0 5 votes vote down vote up
public static Timestamp getHourEnd(Timestamp stamp, Long hoursLater, TimeZone timeZone, Locale locale) {
    Calendar tempCal = toCalendar(stamp, timeZone, locale);
    tempCal.set(tempCal.get(Calendar.YEAR), tempCal.get(Calendar.MONTH), tempCal.get(Calendar.DAY_OF_MONTH), tempCal.get(Calendar.HOUR_OF_DAY), 59, 59);
    tempCal.add(Calendar.HOUR_OF_DAY, hoursLater.intValue());
    Timestamp retStamp = new Timestamp(tempCal.getTimeInMillis());
    retStamp.setNanos(0);
    return retStamp;
}
 
Example 4
Source File: EntitySyncServices.java    From scipio-erp with Apache License 2.0 5 votes vote down vote up
/**
 * Clean EntitySyncRemove Info
 *@param dctx The DispatchContext that this service is operating in
 *@param context Map containing the input parameters
 *@return Map with the result of the service, the output parameters
 */
public static Map<String, Object> cleanSyncRemoveInfo(DispatchContext dctx, Map<String, ? extends Object> context) {
    Debug.logInfo("Running cleanSyncRemoveInfo", module);
    Delegator delegator = dctx.getDelegator();
    Locale locale = (Locale) context.get("locale");

    try {
        // find the largest keepRemoveInfoHours value on an EntitySyncRemove and kill everything before that, if none found default to 10 days (240 hours)
        double keepRemoveInfoHours = 24;

        List<GenericValue> entitySyncRemoveList = EntityQuery.use(delegator).from("EntitySync").queryList();
        for (GenericValue entitySyncRemove: entitySyncRemoveList) {
            Double curKrih = entitySyncRemove.getDouble("keepRemoveInfoHours");
            if (curKrih != null) {
                double curKrihVal = curKrih;
                if (curKrihVal > keepRemoveInfoHours) {
                    keepRemoveInfoHours = curKrihVal;
                }
            }
        }


        int keepSeconds = (int) Math.floor(keepRemoveInfoHours * 3600);

        Calendar nowCal = Calendar.getInstance();
        nowCal.setTimeInMillis(System.currentTimeMillis());
        nowCal.add(Calendar.SECOND, -keepSeconds);
        Timestamp keepAfterStamp = new Timestamp(nowCal.getTimeInMillis());

        int numRemoved = delegator.removeByCondition("EntitySyncRemove", EntityCondition.makeCondition(ModelEntity.STAMP_TX_FIELD, EntityOperator.LESS_THAN, keepAfterStamp));
        Debug.logInfo("In cleanSyncRemoveInfo removed [" + numRemoved + "] values with TX timestamp before [" + keepAfterStamp + "]", module);

        return ServiceUtil.returnSuccess();
    } catch (GenericEntityException e) {
        Debug.logError(e, "Error cleaning out EntitySyncRemove info: " + e.toString(), module);
        return ServiceUtil.returnError(UtilProperties.getMessage(resource, "EntityExtErrorCleaningEntitySyncRemove", UtilMisc.toMap("errorString", e.toString()), locale));
    }
}
 
Example 5
Source File: TemporalExpressions.java    From scipio-erp with Apache License 2.0 5 votes vote down vote up
protected Calendar prepareCal(Calendar cal) {
    // Performs a "sane" skip forward in time - avoids time consuming loops
    // like incrementing every second from Jan 1 2000 until today
    Calendar skip = (Calendar) cal.clone();
    skip.setTime(this.start);
    long deltaMillis = cal.getTimeInMillis() - this.start.getTime();
    if (deltaMillis < 1000) {
        return skip;
    }
    long divisor = deltaMillis;
    if (this.freqType == Calendar.DAY_OF_MONTH) {
        divisor = 86400000;
    } else if (this.freqType == Calendar.HOUR) {
        divisor = 3600000;
    } else if (this.freqType == Calendar.MINUTE) {
        divisor = 60000;
    } else if (this.freqType == Calendar.SECOND) {
        divisor = 1000;
    } else {
        return skip;
    }
    long units = deltaMillis / divisor;
    units -= units % this.freqCount;
    skip.add(this.freqType, (int)units);
    while (skip.after(cal)) {
        skip.add(this.freqType, -this.freqCount);
    }
    return skip;
}
 
Example 6
Source File: DataTypeUtil.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
/**
   * mask out time info for sql Date
   * @param date
   * @return
   */
  private static java.sql.Date maskSQLDate( java.sql.Date date )
  {
  	Calendar calendar = Calendar.getInstance( );
calendar.clear( );
calendar.setTimeInMillis( date.getTime( ) );
calendar.set( Calendar.HOUR_OF_DAY, 0 );
calendar.set( Calendar.MINUTE, 0 );
calendar.set( Calendar.SECOND, 0 );
calendar.set( Calendar.MILLISECOND, 0 );		
return new java.sql.Date( calendar.getTimeInMillis( ) );
  }
 
Example 7
Source File: UtilDateTime.java    From scipio-erp with Apache License 2.0 5 votes vote down vote up
public static Timestamp getYearStart(Timestamp stamp, int daysLater, int monthsLater, int yearsLater, TimeZone timeZone, Locale locale) {
    Calendar tempCal = toCalendar(stamp, timeZone, locale);
    tempCal.set(tempCal.get(Calendar.YEAR), Calendar.JANUARY, 1, 0, 0, 0);
    tempCal.add(Calendar.YEAR, yearsLater);
    tempCal.add(Calendar.MONTH, monthsLater);
    tempCal.add(Calendar.DAY_OF_MONTH, daysLater);
    Timestamp retStamp = new Timestamp(tempCal.getTimeInMillis());
    retStamp.setNanos(0);
    return retStamp;
}
 
Example 8
Source File: SecuredHierarchy.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
public SecuredHierarchy( IDocumentManager documentManager,
		String dimensionName, String hierarchyName, Set<String> notAccessibleLevels )
{
	super( documentManager, dimensionName, hierarchyName );
	this.notAccessibleLevels = notAccessibleLevels;
	Calendar calendar = Calendar.getInstance( );
	calendar.clear( );
	calendar.set( 0, 0, 1, 0, 0, 0 );
	this.nullTime = calendar.getTimeInMillis( );
}
 
Example 9
Source File: UtilDateTime.java    From scipio-erp with Apache License 2.0 5 votes vote down vote up
public static Timestamp getWeekStart(Timestamp stamp, int daysLater, int weeksLater, TimeZone timeZone, Locale locale) {
    Calendar tempCal = toCalendar(stamp, timeZone, locale);
    tempCal.set(tempCal.get(Calendar.YEAR), tempCal.get(Calendar.MONTH), tempCal.get(Calendar.DAY_OF_MONTH), 0, 0, 0);
    tempCal.add(Calendar.DAY_OF_MONTH, daysLater);
    tempCal.set(Calendar.DAY_OF_WEEK, tempCal.getFirstDayOfWeek());
    tempCal.add(Calendar.WEEK_OF_MONTH, weeksLater);
    Timestamp retStamp = new Timestamp(tempCal.getTimeInMillis());
    retStamp.setNanos(0);
    return retStamp;
}
 
Example 10
Source File: DataTypeUtil.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
/**
   * 
   * @param date
   * @return
   */
  private static java.sql.Date toSqlDate( Date date )
  {
  	Calendar calendar = Calendar.getInstance( );
calendar.clear( );
calendar.setTimeInMillis( date.getTime( ) );
calendar.set( Calendar.HOUR_OF_DAY, 0 );
calendar.set( Calendar.MINUTE, 0 );
calendar.set( Calendar.SECOND, 0 );
calendar.set( Calendar.MILLISECOND, 0 );		
return new java.sql.Date( calendar.getTimeInMillis( ) );
  }
 
Example 11
Source File: DataTypeUtil.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
/**
* 
* @param date
* @return
*/
  private static java.sql.Time toSqlTime( Date date )
  {
  	Calendar calendar = Calendar.getInstance( );
calendar.clear( );
calendar.setTimeInMillis( date.getTime( ) );
calendar.set( Calendar.YEAR, 1970 );
calendar.set( Calendar.MONTH, 0 );
calendar.set( Calendar.DAY_OF_MONTH, 1 );
return new java.sql.Time( calendar.getTimeInMillis( ) );
  }
 
Example 12
Source File: DateUtil.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
/**
   * 
   * @param date
   * @return
   */
  private static java.sql.Time toSqlTime( Date date )
  {
  	Calendar calendar = Calendar.getInstance( );
calendar.clear( );
calendar.setTimeInMillis( date.getTime( ) );
calendar.set( Calendar.YEAR, 1970 );
calendar.set( Calendar.MONTH, 0 );
calendar.set( Calendar.DAY_OF_MONTH, 1 );
calendar.set( Calendar.MILLISECOND, 0 );
return new java.sql.Time( calendar.getTimeInMillis( ) );
  }
 
Example 13
Source File: DateUtil.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
/**
   * 
   * @param date
   * @return
   */
  private static java.sql.Date toSqlDate( Date date )
  {
  	Calendar calendar = Calendar.getInstance( );
calendar.clear( );
calendar.setTimeInMillis( date.getTime( ) );
calendar.set( Calendar.HOUR_OF_DAY, 0 );
calendar.set( Calendar.MINUTE, 0 );
calendar.set( Calendar.SECOND, 0 );
calendar.set( Calendar.MILLISECOND, 0 );		
return new java.sql.Date( calendar.getTimeInMillis( ) );
  }
 
Example 14
Source File: DateTimeTests.java    From scipio-erp with Apache License 2.0 5 votes vote down vote up
public void testDateTimeConverters() throws Exception {
    Calendar cal = Calendar.getInstance();
    long currentTime = cal.getTimeInMillis();
    cal.set(cal.get(Calendar.YEAR), cal.get(Calendar.MONTH), cal.get(Calendar.DAY_OF_MONTH), 0, 0, 0);
    cal.set(Calendar.MILLISECOND, 0);
    long longTime = cal.getTimeInMillis(); // Start of day today
    assertNotEquals("currentTime and longTime are not equal", currentTime, longTime);
    java.util.Date utilDate = new java.util.Date(longTime);
    java.sql.Date sqlDate = new java.sql.Date(longTime);
    java.sql.Timestamp timestamp = new java.sql.Timestamp(longTime);
    // Source class = java.util.Date
    assertConversion("DateToLong", new DateTimeConverters.DateToLong(), utilDate, longTime);
    assertConversion("DateToSqlDate", new DateTimeConverters.DateToSqlDate(), utilDate, new java.sql.Date(longTime));
    assertConversion("DateToString", new DateTimeConverters.DateToString(), utilDate, utilDate.toString());
    assertConversion("DateToTimestamp", new DateTimeConverters.DateToTimestamp(), utilDate, timestamp);
    // Source class = java.sql.Date
    assertConversion("SqlDateToLong", new DateTimeConverters.DateToLong(), sqlDate, longTime);
    assertConversion("SqlDateToDate", new DateTimeConverters.SqlDateToDate(), sqlDate, utilDate);
    assertConversion("SqlDateToString", new DateTimeConverters.SqlDateToString(), sqlDate, sqlDate.toString());
    assertConversion("SqlDateToTimestamp", new DateTimeConverters.SqlDateToTimestamp(), sqlDate, timestamp);
    // Source class = java.sql.Timestamp
    assertConversion("TimestampToLong", new DateTimeConverters.DateToLong(), timestamp, longTime);
    assertConversion("TimestampToDate", new DateTimeConverters.TimestampToDate(), timestamp, utilDate);
    assertConversion("TimestampToSqlDate", new DateTimeConverters.TimestampToSqlDate(), timestamp, sqlDate);
    assertConversion("TimestampToString", new DateTimeConverters.TimestampToString(), timestamp, timestamp.toString());
    // Source class = java.lang.Long
    assertConversion("LongToDate", new DateTimeConverters.NumberToDate(), longTime, utilDate);
    assertConversion("LongToSqlDate", new DateTimeConverters.NumberToSqlDate(), longTime, sqlDate);
    assertConversion("LongToSqlDate", new DateTimeConverters.NumberToSqlDate(), currentTime, sqlDate); //Test conversion to start of day
    assertConversion("LongToTimestamp", new DateTimeConverters.NumberToTimestamp(), longTime, timestamp);
    // Source class = java.lang.String
    assertConversion("StringToTimestamp", new DateTimeConverters.StringToTimestamp(), timestamp.toString(), timestamp);
}
 
Example 15
Source File: DataTypeUtil.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
/**
   * 
   * @param hour
   * @param minute
   * @param second
   * @return
   */
  private static Time toSqlTime( int hour, int minute, int second )
  {
  	Calendar calendar = Calendar.getInstance( );
calendar.clear( );
calendar.set( Calendar.HOUR_OF_DAY, hour );
calendar.set( Calendar.MINUTE, minute );
calendar.set( Calendar.SECOND, second );
return new java.sql.Time( calendar.getTimeInMillis( ) );
  }
 
Example 16
Source File: DateTimeConverters.java    From scipio-erp with Apache License 2.0 5 votes vote down vote up
public java.sql.Date convert(java.util.Date obj) throws ConversionException {
    Calendar cal = Calendar.getInstance();
    cal.setTime(obj);
    cal.set(cal.get(Calendar.YEAR), cal.get(Calendar.MONTH), cal.get(Calendar.DAY_OF_MONTH), 0, 0, 0);
    cal.set(Calendar.MILLISECOND, 0);
    return new java.sql.Date(cal.getTimeInMillis());
}
 
Example 17
Source File: DateTime.java    From org.openntf.domino with Apache License 2.0 5 votes vote down vote up
@Override
public double timeDifferenceDouble(final org.openntf.formula.DateTime dt) {
	if (dt instanceof lotus.domino.DateTime) {
		return timeDifferenceDouble((lotus.domino.DateTime) dt);
	}
	Calendar thisCal = this.toJavaCal();
	Calendar thatCal = dt.toJavaCal();
	return (thisCal.getTimeInMillis() - thatCal.getTimeInMillis()) / 1000;
}
 
Example 18
Source File: DateTimeConverters.java    From scipio-erp with Apache License 2.0 4 votes vote down vote up
public Long convert(Calendar obj) throws ConversionException {
    return obj.getTimeInMillis();
}
 
Example 19
Source File: AbstractDesignAgent.java    From org.openntf.domino with Apache License 2.0 4 votes vote down vote up
@Override
public Long getLastRunDuration() {
	List<String> lastRunLog = getRunLogAsList();
	if (!lastRunLog.isEmpty()) {
		String strStart = "";
		String strEnd = "";
		try {
			for (String str : lastRunLog) {
				if (Strings.startsWithIgnoreCase(str, "Started running agent")) {
					strStart = str.substring(str.length() - 19, str.length());
					if (strStart.contains("AM") || strStart.contains("PM")) {
						strStart = str.substring(str.length() - 22, str.length() - 3);
					}
				} else if (Strings.startsWithIgnoreCase(str, "Done running agent")) {
					strEnd = str.substring(str.length() - 19, str.length());
					if (strEnd.contains("AM") || strEnd.contains("PM")) {
						strEnd = str.substring(str.length() - 22, str.length() - 3);
					}
				}
			}
			if (strStart == "" || strEnd == "") {
				return Long.MIN_VALUE;
			}
			// Adjust for pre-2000 dates, which don't have four-digit year
			if ("/9".equals(strStart.substring(7, 9))) {
				strStart = strStart.substring(2);
			}
			if ("/9".equals(strEnd.substring(7, 9))) {
				strEnd = strEnd.substring(2);
			}
			DateTime start = Factory.getSession(SessionType.CURRENT).createDateTime(strStart);
			DateTime end = Factory.getSession(SessionType.CURRENT).createDateTime(strEnd);
			Calendar thisCal = start.toJavaCal();
			Calendar thatCal = end.toJavaCal();
			return (thatCal.getTimeInMillis() - thisCal.getTimeInMillis()) / 1000;
		} catch (Exception e) {
			DominoUtils.handleException(e, "Error on " + getName() + " - start: " + strStart + ", end: " + strEnd);
		}
	}
	return Long.MIN_VALUE;
}
 
Example 20
Source File: UtilDateTime.java    From scipio-erp with Apache License 2.0 4 votes vote down vote up
public static Timestamp adjustTimestamp(Timestamp stamp, Integer adjType, Integer adjQuantity) {
    Calendar tempCal = toCalendar(stamp);
    tempCal.add(adjType, adjQuantity);
    return new Timestamp(tempCal.getTimeInMillis());
}