當前位置: 首頁>>代碼示例>>Java>>正文


Java DateUtils.truncate方法代碼示例

本文整理匯總了Java中org.apache.commons.lang.time.DateUtils.truncate方法的典型用法代碼示例。如果您正苦於以下問題:Java DateUtils.truncate方法的具體用法?Java DateUtils.truncate怎麽用?Java DateUtils.truncate使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.apache.commons.lang.time.DateUtils的用法示例。


在下文中一共展示了DateUtils.truncate方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: pushMessage

import org.apache.commons.lang.time.DateUtils; //導入方法依賴的package包/類
private void pushMessage(Connection connection, String queueName, String messageId, String payload, long offsetTimeInSecond) {
	String PUSH_MESSAGE = "INSERT INTO queue_message (created_on, deliver_on, queue_name, message_id, offset_time_seconds, payload) VALUES (:createdOn, :deliverOn, :queueName, :messageId, :offsetSeconds, :payload)";
	String UPDATE_MESSAGE = "UPDATE queue_message SET payload = :payload WHERE queue_name = :queueName AND message_id = :messageId";

	createQueueIfNotExists(connection, queueName);

	Date now = DateUtils.truncate(new Date(), Calendar.SECOND);
	Date deliverTime = new Date(now.getTime() + (offsetTimeInSecond*1000));
	boolean exists = existsMessage(connection, queueName, messageId);

	if (!exists) {
		connection.createQuery(PUSH_MESSAGE)
				.addParameter("createdOn", now)
				.addParameter("deliverOn", deliverTime)
				.addParameter("queueName", queueName)
				.addParameter("messageId", messageId)
				.addParameter("offsetSeconds", offsetTimeInSecond)
				.addParameter("payload", payload).executeUpdate();
	} else {
		connection.createQuery(UPDATE_MESSAGE)
				.addParameter("queueName", queueName)
				.addParameter("messageId", messageId)
				.addParameter("payload", payload).executeUpdate();
	}
}
 
開發者ID:Netflix,項目名稱:conductor,代碼行數:26,代碼來源:MySQLQueueDAO.java

示例2: getParams

import org.apache.commons.lang.time.DateUtils; //導入方法依賴的package包/類
@Override
public Map<String, Object> getParams() {
    Map<String, Object> params = new HashMap<>();
    for (MacroArgs macroArgs : paramNames) {
        TimeZone timeZone = macroArgs.timeZone == null ? TimeZone.getDefault() : macroArgs.timeZone;
        Date date1 = (Date) namedParameters.get(macroArgs.firstParamName);
        if (date1 == null) {
            throw new RuntimeException(String.format("Parameter %s not found for macro",
                    macroArgs.firstParamName));
        }
        Calendar calendar1 = Calendar.getInstance(timeZone);
        calendar1.setTime(date1);
        calendar1 = DateUtils.truncate(calendar1, Calendar.DAY_OF_MONTH);

        Calendar calendar2 = Calendar.getInstance(timeZone);
        calendar2.setTime(calendar1.getTime());
        calendar2.add(Calendar.DAY_OF_MONTH, 1);

        params.put(macroArgs.firstParamName, calendar1.getTime());
        params.put(macroArgs.secondParamName, calendar2.getTime());
    }
    return params;
}
 
開發者ID:cuba-platform,項目名稱:cuba,代碼行數:24,代碼來源:DateEqualsMacroHandler.java

示例3: getParams

import org.apache.commons.lang.time.DateUtils; //導入方法依賴的package包/類
@Override
public Map<String, Object> getParams() {
    Map<String, Object> params = new HashMap<>();
    for (Pair<String, TimeZone> pair : paramNames) {
        String paramName = pair.getFirst();
        TimeZone timeZone = pair.getSecond() == null ? TimeZone.getDefault() : pair.getSecond();
        Date date = (Date) namedParameters.get(paramName);
        if (date == null)
            throw new RuntimeException("Parameter " + paramName + " not found for macro");

        Calendar calendar = Calendar.getInstance(timeZone);
        calendar.setTime(date);
        calendar = DateUtils.truncate(calendar, Calendar.DAY_OF_MONTH);
        params.put(paramName, calendar.getTime());
    }
    return params;
}
 
開發者ID:cuba-platform,項目名稱:cuba,代碼行數:18,代碼來源:DateAfterMacroHandler.java

示例4: testFindSecuritySalesWithoutLots

import org.apache.commons.lang.time.DateUtils; //導入方法依賴的package包/類
@Test
public void testFindSecuritySalesWithoutLots() throws Exception {
    Date sellDate = DateUtils.truncate(new Date(), Calendar.DAY_OF_MONTH);
    Security security1 = securityDao.get((Long) SECURITY_BATCH.getValue(0, "asset_id"));
    Security security2 = securityDao.get((Long) SECURITY_BATCH.getValue(1, "asset_id"));
    Transaction saleWithoutLot1 = createTransaction(security1, sellDate,
            createTransactionDetail(SELL.code(), "123.45", "-10.0002"),
            createTransactionDetail(SELL.code(), "234.45", "-10.0002"));
    Transaction saleWithoutLot2 = createTransaction(security2, sellDate,
            createTransactionDetail(SELL.code(), "123.45", "-10.000"),
            createTransactionDetail(SELL.code(), "234.45", "-10.000"));
    Transaction saleWithoutLot3 = createTransaction(security1, DateUtils.addDays(sellDate, 1),
            createTransactionDetail(SELL.code(), "123.45", "-10.000"),
            createTransactionDetail(SELL.code(), "234.45", "-10.000"));
    Transaction sharesOutWithoutLot = createTransaction(security1, sellDate,
            createTransactionDetail(SHARES_OUT.code(), "123.45", "-10.0001"),
            createTransactionDetail(SHARES_OUT.code(), "234.45", "-10.0001"));
    Transaction buy = createTransaction(security1, new Date(),
            createTransactionDetail(BUY.code(), "-123.45", "10.000"),
            createTransactionDetail(BUY.code(), "-234.45", "10.000"));
    Transaction saleWithLot = createTransaction(security1, sellDate,
            createTransactionDetail(SELL.code(), "123.45", "-10.000"),
            createTransactionDetail(SELL.code(), "234.45", "-10.000"));
    securityLotDao.save(new SecurityLot(buy.getDetails().get(0), saleWithLot.getDetails().get(0), BigDecimal.TEN));

    List<TransactionDetail> withoutLots = transactionDetailDao.findSecuritySalesWithoutLots(security1.getName().substring(0, 7).toUpperCase(), sellDate);

    assertThat(withoutLots).isNotEmpty();
    assertThat(withoutLots.size()).isEqualTo(new HashSet<>(withoutLots).size()).as("no duplicates");
    List<Object> withoutLotIds = Lists.transform(withoutLots, UniqueId::getId);
    assertThat(withoutLotIds).contains(getIds(saleWithoutLot1.getDetails()));
    assertThat(withoutLotIds).doesNotContain(getIds(saleWithoutLot2.getDetails())).as("wrong security");
    assertThat(withoutLotIds).doesNotContain(getIds(saleWithoutLot3.getDetails())).as("wrong date");
    assertThat(withoutLotIds).contains(getIds(sharesOutWithoutLot.getDetails()));
    assertThat(withoutLotIds).doesNotContain(getIds(buy.getDetails()));
    assertThat(withoutLotIds).doesNotContain(saleWithLot.getDetails().get(0).getId());
    assertThat(withoutLotIds).contains(saleWithLot.getDetails().get(1).getId());
}
 
開發者ID:jonestimd,項目名稱:finances,代碼行數:39,代碼來源:TransactionDetailDaoImplTest.java

示例5: previousPeriod

import org.apache.commons.lang.time.DateUtils; //導入方法依賴的package包/類
/**
 * Returns the previous full period that does not include the given date. Example: date = 2007-02-15, field = month, number = 2 returns a period
 * of 2 months from 2006-12-01 to 2007-01-31
 */
public Period previousPeriod(final Calendar date) {
    Calendar end;
    if (field == Field.WEEKS) {
        // Weeks are not supported on DateUtils.truncate, so, go back to the last monday, and get weeks before
        end = DateHelper.truncate(date);
        while (end.get(Calendar.DAY_OF_WEEK) != Calendar.MONDAY) {
            end.add(Calendar.DATE, -1);
        }
    } else {
        end = DateUtils.truncate(date, field.getCalendarValue());
    }
    return periodEndingAt(end);
}
 
開發者ID:mateli,項目名稱:OpenCyclos,代碼行數:18,代碼來源:TimePeriod.java

示例6: setFromCreatedOn

import org.apache.commons.lang.time.DateUtils; //導入方法依賴的package包/類
/**
 * fromCreatedOnを設定します.
 * @param fromCreatedOn the fromCreatedOn to set
 */
public void setFromCreatedOn(Date fromCreatedOn) {
    if (fromCreatedOn != null) {
        this.fromCreatedOn = DateUtils.truncate(fromCreatedOn, Calendar.DATE);
    } else {
        this.fromCreatedOn = null;
    }
}
 
開發者ID:otsecbsol,項目名稱:linkbinder,代碼行數:12,代碼來源:SearchCorresponCondition.java

示例7: setToCreatedOn

import org.apache.commons.lang.time.DateUtils; //導入方法依賴的package包/類
/**
 * toCreatedOnを設定します.
 * @param toCreatedOn the toCreatedOn to set
 */
public void setToCreatedOn(Date toCreatedOn) {
    if (toCreatedOn != null) {
        this.toCreatedOn = DateUtils.truncate(toCreatedOn, Calendar.DATE);
    } else {
        this.toCreatedOn = null;
    }
}
 
開發者ID:otsecbsol,項目名稱:linkbinder,代碼行數:12,代碼來源:SearchCorresponCondition.java

示例8: run

import org.apache.commons.lang.time.DateUtils; //導入方法依賴的package包/類
@Override
public void run() {
    Calendar time = DateUtils.truncate(Calendar.getInstance(), Calendar.HOUR_OF_DAY);
    HourlyScheduledTasks runner = new HourlyScheduledTasks(SchedulingHandler.this, time);
    if (queue.isEmpty()) {
        // Nothing is currently being executed. Execute it right away
        runner.start();
    } else {
        // Tasks of a previous hour are being executed. Enqueue this execution
        queue.offer(runner);
    }
}
 
開發者ID:mateli,項目名稱:OpenCyclos,代碼行數:13,代碼來源:SchedulingHandler.java

示例9: setToIssuedOn

import org.apache.commons.lang.time.DateUtils; //導入方法依賴的package包/類
/**
 * toIssuedOnを設定します.
 * @param toIssuedOn the toIssuedOn to set
 */
public void setToIssuedOn(Date toIssuedOn) {
    if (toIssuedOn != null) {
        this.toIssuedOn = DateUtils.truncate(toIssuedOn, Calendar.DATE);
    } else {
        this.toIssuedOn = null;
    }
}
 
開發者ID:otsecbsol,項目名稱:linkbinder,代碼行數:12,代碼來源:SearchCorresponCondition.java

示例10: setToDeadlineForReply

import org.apache.commons.lang.time.DateUtils; //導入方法依賴的package包/類
/**
 * toDeadlineForReplyを設定します.
 * @param toDeadlineForReply the toDeadlineForReply to set
 */
public void setToDeadlineForReply(Date toDeadlineForReply) {
    if (toDeadlineForReply != null) {
        this.toDeadlineForReply = DateUtils.truncate(toDeadlineForReply, Calendar.DATE);
    } else {
        this.toDeadlineForReply = null;
    }
}
 
開發者ID:otsecbsol,項目名稱:linkbinder,代碼行數:12,代碼來源:SearchCorresponCondition.java

示例11: newBean

import org.apache.commons.lang.time.DateUtils; //導入方法依賴的package包/類
@Override
protected StockSplit newBean() {
    return new StockSplit(security, DateUtils.truncate(new Date(), Calendar.DAY_OF_MONTH), new SplitRatio());
}
 
開發者ID:jonestimd,項目名稱:finances,代碼行數:5,代碼來源:StockSplitDialog.java

示例12: testFindAvailablePurchaseShares

import org.apache.commons.lang.time.DateUtils; //導入方法依賴的package包/類
@Test
public void testFindAvailablePurchaseShares() throws Exception {
    Date sellDate = DateUtils.truncate(new Date(), Calendar.DAY_OF_MONTH);
    Account account2 = accountDao.get((Long) ACCOUNT_BATCH.getValue(1, "id"));
    Security security = securityDao.get((Long) SECURITY_BATCH.getValue(0, "asset_id"));
    Transaction buyWithoutLot1 = createTransaction(security, sellDate,
            createTransactionDetail(BUY.code(), "-100.00", "5.0"),
            createTransactionDetail(BUY.code(), "-200.00", "5.0"),
            createTransactionDetail("Dividend", "300.90"),
            createTransactionDetail("Commission", "-0.90"));
    Transaction sharesInWithoutLot = createTransaction(security, sellDate,
            createTransactionDetail(SHARES_IN.code(), "-300.90", "10.0"),
            createTransactionDetail(SHARES_IN.code(), "-150.45", "5.0"));
    Transaction buyWithWrongAccount = createTransaction(account2, security, sellDate,
            createTransactionDetail(BUY.code(), "-300.90", "10.0"),
            createTransactionDetail(BUY.code(), "-300.90", "10.0"));
    Transaction sharesInWithZeroAmount = createTransaction(account, security, sellDate,
            createTransactionDetail(SHARES_IN.code(), "0.00", "10.0"));
    Transaction buyWithNoShares = createTransaction(security, sellDate,
            createTransactionDetail(BUY.code(), "-300.90", "10.0"),
            createTransactionDetail(BUY.code(), "-300.90", "10.0"));
    Transaction sharesOutWithoutLot = createTransaction(security, sellDate,
            createTransactionDetail(SHARES_OUT.code(), "300.90", "-10.0"),
            createTransactionDetail(SHARES_OUT.code(), "300.90", "-10.0"));
    Transaction sellWithLot = createTransaction(security, sellDate,
            createTransactionDetail(SELL.code(), "300.90", "-10.0"),
            createTransactionDetail(SELL.code(), "300.90", "-10.0"));
    securityLotDao.save(new SecurityLot(buyWithNoShares.getDetails().get(0), sellWithLot.getDetails().get(1), BigDecimal.TEN));
    securityLotDao.save(new SecurityLot(buyWithNoShares.getDetails().get(1), sellWithLot.getDetails().get(0), BigDecimal.TEN));
    Transaction buyWithLot2 = createTransaction(security, DateUtils.addDays(sellDate, 1),
            createTransactionDetail(BUY.code(), "-400.90", "10.0"),
            createTransactionDetail(BUY.code(), "-200.90", "10.0"));
    Transaction sellWithLot2 = createTransaction(security, sellDate,
            createTransactionDetail(SELL.code(), "300.90", "-10.0"),
            createTransactionDetail(SELL.code(), "300.90", "-10.0"));
    securityLotDao.save(new SecurityLot(buyWithLot2.getDetails().get(0), sellWithLot2.getDetails().get(1), new BigDecimal("9")));

    TransactionDetail sale = createTransaction(security, sellDate, createTransactionDetail("Sell", "9")).getDetails().get(0);
    List<TransactionDetail> withoutLots = transactionDetailDao.findAvailablePurchaseShares(sale);

    assertThat(withoutLots).isNotEmpty();
    assertThat(withoutLots.size()).isEqualTo(new HashSet<>(withoutLots).size()).as("no duplicates");
    List<Object> withoutLotIds = Lists.transform(withoutLots, UniqueId::getId);
    assertThat(withoutLotIds).contains(getIds(buyWithoutLot1.getDetails().subList(0, 2)));
    assertThat(withoutLotIds).doesNotContain(getIds(buyWithoutLot1.getDetails().subList(2, 4)));
    assertThat(withoutLotIds).contains(getIds(sharesInWithoutLot.getDetails()));
    assertThat(withoutLotIds).doesNotContain(getIds(buyWithWrongAccount.getDetails())).as("purchase from wrong account");
    assertThat(withoutLotIds).contains(getIds(sharesInWithZeroAmount.getDetails())).as("purchase with wrong price");
    assertThat(withoutLotIds).doesNotContain(getIds(buyWithNoShares.getDetails())).as("purchase with no available shares");
    assertThat(withoutLotIds).doesNotContain(getIds(sellWithLot.getDetails())).as("sale");
    assertThat(withoutLotIds).doesNotContain(getIds(sharesOutWithoutLot.getDetails())).as("shares out");
    assertThat(withoutLotIds).doesNotContain(getIds(buyWithLot2.getDetails())).as("after sell date");
}
 
開發者ID:jonestimd,項目名稱:finances,代碼行數:54,代碼來源:TransactionDetailDaoImplTest.java

示例13: newDate

import org.apache.commons.lang.time.DateUtils; //導入方法依賴的package包/類
private Date newDate(int dateOffset) {
    return DateUtils.truncate(DateUtils.addDays(new Date(), dateOffset), Calendar.DAY_OF_MONTH);
}
 
開發者ID:jonestimd,項目名稱:finances,代碼行數:4,代碼來源:SecurityTest.java

示例14: getDayWorkSchedule

import org.apache.commons.lang.time.DateUtils; //導入方法依賴的package包/類
public DayWorkSchedule getDayWorkSchedule(String providerNo, Calendar date) {
	// algorithm
	//----------
	// select entries from scheduledate for the given day/provider where status = 'A' (for active?)
	// "hour" setting is the template to apply, i.e. template name
	// select entry from scheduletemplate to get the template to apply for the given day
	// timecode is a breakdown of the day into equal slots, where _ means nothing and some letter means a code in scheduletemplatecode
	// The only way to know the duration of the time code is to divide it up, i.e. minutes_per_day/timecode.length, i.e. 1440 minutes per second / 96 length = 15 minutes per slot.
	// For each time slot, then look up the scheduletemplatecode

	DayWorkSchedule dayWorkSchedule = new DayWorkSchedule();

	ScheduleHoliday scheduleHoliday = scheduleHolidayDao.find(date.getTime());
	dayWorkSchedule.setHoliday(scheduleHoliday != null);

	ScheduleDate scheduleDate = scheduleDateDao.findByProviderNoAndDate(providerNo, date.getTime());
	if (scheduleDate == null) {
		logger.debug("No scheduledate for date requested. providerNo=" + providerNo + ", date=" + date.getTime());
		return (null);
	}
	String scheduleTemplateName = scheduleDate.getHour();

	// okay this is a mess, the ScheduleTemplate is messed up because no one links there via a PK, they only link there via the name column
	// and the name column isn't unique... so... we will have to do a search for the right template.
	// first we'll check under the providersId, if not we'll check under the public id.
	ScheduleTemplatePrimaryKey scheduleTemplatePrimaryKey = new ScheduleTemplatePrimaryKey(providerNo, scheduleTemplateName);
	ScheduleTemplate scheduleTemplate = scheduleTemplateDao.find(scheduleTemplatePrimaryKey);
	if (scheduleTemplate == null) {
		scheduleTemplatePrimaryKey = new ScheduleTemplatePrimaryKey(ScheduleTemplatePrimaryKey.DODGY_FAKE_PROVIDER_NO_USED_TO_HOLD_PUBLIC_TEMPLATES, scheduleTemplateName);
		scheduleTemplate = scheduleTemplateDao.find(scheduleTemplatePrimaryKey);
	}

	//  if it's still null, then ignore it as there's no schedule for the day.
	if (scheduleTemplate != null) {
		// time interval
		String timecode = scheduleTemplate.getTimecode();
		int timeSlotDuration = (60 * 24) / timecode.length();
		dayWorkSchedule.setTimeSlotDurationMin(timeSlotDuration);

		// sort out designated timeslots and their purpose
		Calendar timeSlot = (Calendar) date.clone();

		//make sure the appts returned are in local time. 
		timeSlot.setTimeZone(Calendar.getInstance().getTimeZone());
		timeSlot = DateUtils.truncate(timeSlot, Calendar.DAY_OF_MONTH);
		TreeMap<Calendar, Character> allTimeSlots = dayWorkSchedule.getTimeSlots();

		for (int i = 0; i < timecode.length(); i++) {
			// ignore _ because that's a blank place holder identifier... also not my fault, just processing what's been already written.
			if ('_' != timecode.charAt(i)) {
				allTimeSlots.put((Calendar) timeSlot.clone(), timecode.charAt(i));
			}

			timeSlot.add(GregorianCalendar.MINUTE, timeSlotDuration);
		}
	}

	// This method will not log access as the schedule is not private medical data.
	return (dayWorkSchedule);
}
 
開發者ID:williamgrosset,項目名稱:OSCAR-ConCert,代碼行數:61,代碼來源:ScheduleManager.java

示例15: includes

import org.apache.commons.lang.time.DateUtils; //導入方法依賴的package包/類
/**
 * Checks whether the given date is included in this period. When the useTime flag is true, the time of the parameter (date) and the time of the
 * begin and end dates of the period are taken into account to compute the result. If the exact begin date/time is included depends on the
 * <code>inclusiveBegin</code> flag; by default, this is true, so begin date/time is considered to be <strong>included</strong> in the period. If
 * the exact end date/time is included depends on the <code>inclusiveEnd</code> flag; which behaves in the same way as the inclusiveBegin flag.
 * Both are true by default.<br>
 * When the useTime flag is false, the dates are truncated to compute the result, and the inclusiveBegin and inclusiveEnd flags are ignored.
 */
public boolean includes(final Calendar date) {
    if (date == null) {
        return false;
    } else if (begin == null && end == null) {
        return true;
    } else {
        if (useTime) {
            if (begin == null) {
                return (inclusiveEnd) ? !end.before(date) : date.before(end);
            } else if (end == null) {
                return (inclusiveBegin) ? !date.before(begin) : begin.before(date);
            } else {
                final boolean beginOK = (inclusiveBegin) ? !date.before(begin) : begin.before(date);
                final boolean endOK = (inclusiveEnd) ? !end.before(date) : date.before(end);
                return beginOK && endOK;
            }
        } else {
            final Calendar tDate = DateUtils.truncate(date, Calendar.DATE);
            Calendar tBegin = begin;
            Calendar tEnd = end;

            if (begin != null) {
                tBegin = DateUtils.truncate(begin, Calendar.DATE);
            }
            if (end != null) {
                // If not using time, we'll assume the end of the interval is
                // the instant before the next day.
                tEnd = DateHelper.truncateNextDay(end);
            }

            if (tBegin == null) {
                // it's included if the date is an instant before the next day.
                return tDate.before(tEnd);
            } else if (tEnd == null) {
                // it's included if the date is not before the begin
                return !tDate.before(tBegin);
            } else {
                return !tDate.before(tBegin) && tDate.before(tEnd);
            }
        }
    }
}
 
開發者ID:mateli,項目名稱:OpenCyclos,代碼行數:51,代碼來源:Period.java


注:本文中的org.apache.commons.lang.time.DateUtils.truncate方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。