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


Java DateTime.plusSeconds方法代碼示例

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


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

示例1: evaluate

import org.joda.time.DateTime; //導入方法依賴的package包/類
/** {@inheritDoc} */
public void evaluate(MessageContext messageContext) throws SecurityPolicyException {
    if (!(messageContext instanceof SAMLMessageContext)) {
        log.debug("Invalid message context type, this policy rule only supports SAMLMessageContext");
        return;
    }
    SAMLMessageContext samlMsgCtx = (SAMLMessageContext) messageContext;

    if (samlMsgCtx.getInboundSAMLMessageIssueInstant() == null) {
        if(requiredRule){
            log.warn("Inbound SAML message issue instant not present in message context");
            throw new SecurityPolicyException("Inbound SAML message issue instant not present in message context");
        }else{
            return;
        }
    }

    DateTime issueInstant = samlMsgCtx.getInboundSAMLMessageIssueInstant();
    DateTime now = new DateTime();
    DateTime latestValid = now.plusSeconds(clockSkew);
    DateTime expiration = issueInstant.plusSeconds(clockSkew + expires);

    // Check message wasn't issued in the future
    if (issueInstant.isAfter(latestValid)) {
        log.warn("Message was not yet valid: message time was {}, latest valid is: {}", issueInstant, latestValid);
        throw new SecurityPolicyException("Message was rejected because was issued in the future");
    }

    // Check message has not expired
    if (expiration.isBefore(now)) {
        log.warn("Message was expired: message issue time was '" + issueInstant + "', message expired at: '"
                + expiration + "', current time: '" + now + "'");
        throw new SecurityPolicyException("Message was rejected due to issue instant expiration");
    }

}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:37,代碼來源:IssueInstantRule.java

示例2: overlaps

import org.joda.time.DateTime; //導入方法依賴的package包/類
/**
 *  start   | end    | overlaps?
 * ---------+--------+--------------------------------------------------
 *  now     | now    | check inavailability at both stations
 *  now     | future | check inavailability at start station, be optimistic about end station
 *  future  | now    | false. cannot happen, chronologically not possible
 *  future  | future | false. both in future => be optimistic, no check
 */
@Override
public boolean overlaps(int stayTime, RouteLegList legs,
                        SharingStation startStation, RouteLegWrapper bikeWrapper,
                        SharingStation endStation, RouteLegWrapper walkWrapper) {

    // We always set stay time. Depending on DurationCheckStrategy it will be used or not.
    walkWrapper.setStayTime(stayTime);

    // -------------------------------------------------------------------------
    // 1) If in future, be optimistic and assume always available
    // -------------------------------------------------------------------------

    Interval nowTimeWindow = getNowTimeWindow();

    DateTime timeAtStartStation = legs.getAfterLastLeg();
    boolean startIsNow = nowTimeWindow.contains(timeAtStartStation);

    if (!startIsNow) {
        return false;
    }

    // -------------------------------------------------------------------------
    // 2) Check actual intervals for availability
    // -------------------------------------------------------------------------

    int bikeLegDuration = bikeWrapper.getLeg().getDuration();
    int durationAfterStartStation = bikeLegDuration + durationCheckStrategy.getDurationToCheck(walkWrapper);

    DateTime timeAtReturnStation = timeAtStartStation.plusSeconds(durationAfterStartStation);
    boolean endIsNow = nowTimeWindow.contains(timeAtReturnStation);

    if (endIsNow) {
        // Check bike availability for "HinFahrt" at start station and "RückFahrt" at end station
        return overlapsAtStation(legs, startStation, bikeLegDuration)
                || overlapsAtStation(legs, endStation, durationAfterStartStation);
    } else {
        // Check bike availability for "HinFahrt" at start station
        return overlapsAtStation(legs, startStation, bikeLegDuration);
    }
}
 
開發者ID:RWTH-i5-IDSG,項目名稱:xsharing-services-router,代碼行數:49,代碼來源:WithReturnBikeInavailabilityStrategy.java

示例3: testDeparture

import org.joda.time.DateTime; //導入方法依賴的package包/類
@Test
public void testDeparture() {

    DateTime t1 = new DateTime(2016, 5, 24, 11, 0, DateTimeZone.UTC);

    RouteLegList routeLegList = new RouteLegList(t1, false);

    WalkingLeg walkingLeg1 = new WalkingLeg(LegType.WalkingLeg, geoCoord, geoCoord, distance, 50, sr, "");
    DateTime t2 = t1.plusSeconds(50);

    routeLegList.addAndShift(new RouteLegWrapper(walkingLeg1));
    System.out.println(routeLegList);

    CarLeg carLeg = new CarLeg(LegType.CarLeg, geoCoord, geoCoord, distance, 280, sr, "");
    DateTime t3 = t2.plusSeconds(280);

    Interval interval = routeLegList.getIntervalAfterPossibleLeg(carLeg.getDuration());
    System.out.println(interval);

    Assert.assertEquals(interval, new Interval(t2, t3));
    routeLegList.addAndShift(new RouteLegWrapper(carLeg));
    System.out.println(routeLegList);

    WalkingLeg walkingLeg2 = new WalkingLeg(LegType.WalkingLeg, geoCoord, geoCoord, distance, 90, sr, "");
    DateTime t4 = t3.plusSeconds(90);

    Interval interval2 = routeLegList.getIntervalAfterPossibleLeg(walkingLeg2.getDuration());
    System.out.println(interval2);

    Assert.assertEquals(interval2, new Interval(t3, t4));

    routeLegList.addAndShift(new RouteLegWrapper(walkingLeg2));
    System.out.println(routeLegList);
}
 
開發者ID:RWTH-i5-IDSG,項目名稱:xsharing-services-router,代碼行數:35,代碼來源:RouteLegListTest.java


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