Example usage for org.joda.time DateTime plusDays

List of usage examples for org.joda.time DateTime plusDays

Introduction

In this page you can find the example usage for org.joda.time DateTime plusDays.

Prototype

public DateTime plusDays(int days) 

Source Link

Document

Returns a copy of this datetime plus the specified number of days.

Usage

From source file:com.ext.portlet.epsos.EpsosHelperService.java

public static Assertion createTRCAWithRef(String email, EhrPatientClientDto patient, String purposeOfUse,
        String refAssertionId) throws ConfigurationException {
    // assertion//from w  w  w  .j a va 2  s  . co  m
    DefaultBootstrap.bootstrap();
    XMLObjectBuilderFactory builderFactory = Configuration.getBuilderFactory();

    SAMLObjectBuilder<Assertion> builder = (SAMLObjectBuilder<Assertion>) builderFactory
            .getBuilder(Assertion.DEFAULT_ELEMENT_NAME);

    // Create the NameIdentifier
    SAMLObjectBuilder nameIdBuilder = (SAMLObjectBuilder) builderFactory
            .getBuilder(NameID.DEFAULT_ELEMENT_NAME);
    NameID nameId = (NameID) nameIdBuilder.buildObject();
    nameId.setValue(email);
    nameId.setFormat(NameID.EMAIL);

    Assertion assertion = create(Assertion.class, Assertion.DEFAULT_ELEMENT_NAME);

    assertion.setID("_" + UUID.randomUUID());
    assertion.setVersion(SAMLVersion.VERSION_20);
    assertion.setIssueInstant(new org.joda.time.DateTime().minusHours(3));

    Subject subject = create(Subject.class, Subject.DEFAULT_ELEMENT_NAME);
    assertion.setSubject(subject);
    subject.setNameID(nameId);

    //Create and add Subject Confirmation
    SubjectConfirmation subjectConf = create(SubjectConfirmation.class,
            SubjectConfirmation.DEFAULT_ELEMENT_NAME);
    subjectConf.setMethod(SubjectConfirmation.METHOD_SENDER_VOUCHES);
    assertion.getSubject().getSubjectConfirmations().add(subjectConf);

    String refAssId = refAssertionId;

    // Advice
    //Create and add Advice
    Advice advice = create(Advice.class, Advice.DEFAULT_ELEMENT_NAME);
    assertion.setAdvice(advice);

    //Create and add AssertionIDRef
    AssertionIDRef aIdRef = create(AssertionIDRef.class, AssertionIDRef.DEFAULT_ELEMENT_NAME);
    aIdRef.setAssertionID(refAssId);
    advice.getAssertionIDReferences().add(aIdRef);

    //Advice advice = create(Advice.class,Advice.DEFAULT_ELEMENT_NAME);
    //AssertionIDReference air = create(AssertionIDReference.class,AssertionIDReference.DEFAULT_ELEMENT_NAME);
    //air.setReference(refAssId);
    //advice.getAssertionIDReferences().add(air);
    //assertion.setAdvice(advice);

    //Create and add conditions
    Conditions conditions = create(Conditions.class, Conditions.DEFAULT_ELEMENT_NAME);
    org.joda.time.DateTime now = new org.joda.time.DateTime();
    conditions.setNotBefore(now.minusHours(4));
    conditions.setNotOnOrAfter(now.plusDays(1)); // According to Spec
    assertion.setConditions(conditions);

    Issuer issuer = new IssuerBuilder().buildObject();
    issuer.setValue("urn:idp:countryB");
    issuer.setNameQualifier("urn:epsos:wp34:assertions");
    assertion.setIssuer(issuer);

    //Add and create the authentication statement
    AuthnStatement authStmt = create(AuthnStatement.class, AuthnStatement.DEFAULT_ELEMENT_NAME);
    authStmt.setAuthnInstant(now.minusHours(1));
    assertion.getAuthnStatements().add(authStmt);

    //Create and add AuthnContext
    AuthnContext ac = create(AuthnContext.class, AuthnContext.DEFAULT_ELEMENT_NAME);
    AuthnContextClassRef accr = create(AuthnContextClassRef.class, AuthnContextClassRef.DEFAULT_ELEMENT_NAME);
    accr.setAuthnContextClassRef(AuthnContext.PREVIOUS_SESSION_AUTHN_CTX);
    ac.setAuthnContextClassRef(accr);
    authStmt.setAuthnContext(ac);

    AttributeStatement attrStmt = create(AttributeStatement.class, AttributeStatement.DEFAULT_ELEMENT_NAME);

    String pat = patient.getPid().get(0).getPatientID() + "^^^&"
            + patient.getPid().get(0).getDomain().getAuthUniversalID() + "&"
            + patient.getPid().get(0).getDomain().getAuthUniversalIDType();
    // XSPA Subject
    Attribute attrPID = createAttribute(builderFactory, "XSPA subject",
            "urn:oasis:names:tc:xacml:1.0:resource:resource-id", pat, "", "");
    attrStmt.getAttributes().add(attrPID);
    // XSPA Purpose of Use
    Attribute attrPID_6 = createAttribute(builderFactory, "XSPA Purpose Of Use",
            "urn:oasis:names:tc:xspa:1.0:subject:purposeofuse", purposeOfUse, "", "");
    attrStmt.getAttributes().add(attrPID_6);

    assertion.getStatements().add(attrStmt);
    return assertion;
}

From source file:com.facebook.presto.atop.AtopSplitManager.java

License:Apache License

@Override
public ConnectorSplitSource getSplits(ConnectorTransactionHandle transactionHandle, ConnectorSession session,
        ConnectorTableLayoutHandle layoutHandle) {
    AtopTableLayoutHandle handle = checkType(layoutHandle, AtopTableLayoutHandle.class, "layoutHandle");

    AtopTableHandle table = handle.getTableHandle();

    List<ConnectorSplit> splits = new ArrayList<>();
    DateTime end = DateTime.now().withZone(timeZone);
    for (Node node : nodeManager.getActiveDatasourceNodes(connectorId.getId())) {
        DateTime start = end.minusDays(maxHistoryDays - 1).withTimeAtStartOfDay();
        while (start.isBefore(end)) {
            DateTime splitEnd = start.withTime(23, 59, 59, 999);
            Domain splitDomain = Domain.create(
                    ValueSet.ofRanges(// ww w.ja  v  a2s.  c  o m
                            Range.range(TIMESTAMP, start.getMillis(), true, splitEnd.getMillis(), true)),
                    false);
            if (handle.getStartTimeConstraint().overlaps(splitDomain)
                    && handle.getEndTimeConstraint().overlaps(splitDomain)) {
                splits.add(new AtopSplit(table.getTable(), node.getHostAndPort(), start));
            }
            start = start.plusDays(1).withTimeAtStartOfDay();
        }
    }

    return new FixedSplitSource(connectorId.getId(), splits);
}

From source file:com.fengduo.bee.commons.util.TimeHelper.java

License:Open Source License

private static long calcDelay(DateTime targetDatetimeOfToday) {
    long delay = 0;
    DateTime now = new DateTime();

    // ??//from  ww  w  . j a  v a 2  s  . c om
    if (now.isAfter(targetDatetimeOfToday)) {
        delay = now.plusDays(1).getMillis() - now.getMillis();

        // 
    } else {
        delay = targetDatetimeOfToday.getMillis() - now.getMillis();
    }

    return delay;
}

From source file:com.flipkart.foxtrot.core.querystore.impl.ElasticsearchUtils.java

License:Apache License

@VisibleForTesting
public static String[] getIndices(final String table, final ActionRequest request, final Interval interval) {
    DateTime start = interval.getStart().toLocalDate().toDateTimeAtStartOfDay();
    if (start.getYear() <= 1970) {
        logger.warn("Request of type {} running on all indices", request.getClass().getSimpleName());
        return new String[] { getIndices(table) };
    }// ww  w  .  j  a  v  a  2  s  .  c  o m
    List<String> indices = Lists.newArrayList();
    final DateTime end = interval.getEnd().plusDays(1).toLocalDate().toDateTimeAtStartOfDay();
    while (start.getMillis() < end.getMillis()) {
        final String index = getCurrentIndex(table, start.getMillis());
        indices.add(index);
        start = start.plusDays(1);
    }
    logger.info("Request of type {} on indices: {}", request.getClass().getSimpleName(), indices);
    return indices.toArray(new String[indices.size()]);
}

From source file:com.github.terma.gigaspacewebconsole.provider.executor.gigaspace.TimestampPreprocessor.java

License:Apache License

private String timestampString(Matcher matcher, final DateTime timestamp) {
    final int sign = matcher.group(1).equals("-") ? -1 : 1;
    final int quantity = sign * Integer.parseInt(matcher.group(2));
    final String type = matcher.group(3);

    DateTime updatedTimestamp;/*from  w  w w .  j  a  va2  s.c  o m*/
    switch (type) {
    case "h":
        updatedTimestamp = timestamp.plusHours(quantity);
        break;
    case "d":
        updatedTimestamp = timestamp.plusDays(quantity);
        break;
    case "w":
        updatedTimestamp = timestamp.plusWeeks(quantity);
        break;
    default:
        throw new IllegalArgumentException();
    }

    return Long.toString(updatedTimestamp.getMillis());
}

From source file:com.google.android.apps.paco.Experiment.java

License:Open Source License

DateTime scheduleESM(DateTime now, Context context) {
    SignalSchedule schedule = (SignalSchedule) getSignalingMechanisms().get(0);
    if (schedule.convertEsmPeriodToDays() == 1 && !schedule.getEsmWeekends() && TimeUtil.isWeekend(now)) {
        now = TimeUtil.skipWeekends(now);
    }/*  www. jav a  2  s . com*/
    ensureScheduleIsGeneratedForPeriod(now, context);
    // generate at least the next period, so we always have a next time for ESMs.
    DateTime nextPeriod = now.plusDays(schedule.convertEsmPeriodToDays());
    if (schedule.convertEsmPeriodToDays() == 1 && !schedule.getEsmWeekends()
            && TimeUtil.isWeekend(nextPeriod)) {
        nextPeriod = TimeUtil.skipWeekends(nextPeriod);
    }

    ensureScheduleIsGeneratedForPeriod(nextPeriod, context);
    DateTime next = lookupNextTimeOnEsmSchedule(now, context); // anymore this period
    if (next != null) {
        return next;
    }
    return lookupNextTimeOnEsmSchedule(nextPeriod, context);
}

From source file:com.google.android.apps.paco.Experiment.java

License:Open Source License

private DateTime lookupNextTimeOnEsmSchedule(DateTime now, Context context) {
    AlarmStore alarmStore = new AlarmStore(context);
    List<DateTime> signals = alarmStore.getSignals(getId(), getPeriodStart(now).getMillis());

    DateTime next = getNextSignalAfterNow(now, signals);
    if (next != null) {
        return next;
    }// w  ww. j  ava2  s.co  m
    SignalSchedule schedule = (SignalSchedule) getSignalingMechanisms().get(0);
    DateTime nextPeriod = now.plusDays(schedule.convertEsmPeriodToDays());
    if (schedule.convertEsmPeriodToDays() == 1 && !schedule.getEsmWeekends()
            && TimeUtil.isWeekend(nextPeriod)) {
        nextPeriod = TimeUtil.skipWeekends(nextPeriod);
    }

    ensureScheduleIsGeneratedForPeriod(nextPeriod, context);
    signals = alarmStore.getSignals(getId(), getPeriodStart(nextPeriod).getMillis());
    return getNextSignalAfterNow(now, signals);
}

From source file:com.google.android.apps.paco.NonESMSignalGenerator.java

License:Open Source License

private DateTime scheduleMonthly(DateTime now) {
    DateTime nowMidnight = now.toDateMidnight().toDateTime();

    if (schedule.getByDayOfMonth()) {
        int nowDOM = nowMidnight.getDayOfMonth();
        if (nowDOM == schedule.getDayOfMonth()) {
            DateTime nextTimeToday = getNextTimeToday(now, nowMidnight);
            if (nextTimeToday != null) {
                return nextTimeToday;
            }/*from  ww w.  jav a2 s.  com*/
        }
        DateTime nextDay = getNextScheduleDay(nowMidnight.plusDays(1));
        return getFirstScheduledTimeOnDay(nextDay);
    } else {
        DateTime nextDay = getNextScheduleDay(nowMidnight);
        if (nextDay.equals(nowMidnight)) {
            DateTime nextTimeToday = getNextTimeToday(now, nextDay);
            if (nextTimeToday != null) {
                return nextTimeToday;
            }
            nextDay = getNextScheduleDay(nowMidnight.plusDays(1));
            return getFirstScheduledTimeOnDay(nextDay);
        } else {
            return getFirstScheduledTimeOnDay(nextDay);
        }
    }
}

From source file:com.google.android.apps.paco.NonESMSignalGenerator.java

License:Open Source License

private DateTime scheduleWeekly(DateTime now) {
    DateTime nowMidnight = now.toDateMidnight().toDateTime();
    int nowDow = nowMidnight.getDayOfWeek(); // joda starts Monday, I start Sunday
    Integer nowDowIndex = SignalSchedule.DAYS_OF_WEEK[nowDow == 7 ? 0 : nowDow]; // joda is 1 based, and starts on Monday. we are 0-based, Sunday-start
    if ((schedule.getWeekDaysScheduled() & nowDowIndex) == nowDowIndex) {
        DateTime nextTimeToday = getNextTimeToday(now, nowMidnight);
        if (nextTimeToday != null) {
            return nextTimeToday;
        }//from   www . ja v a 2  s. com
    }
    DateTime nextDay = getNextScheduleDay(nowMidnight.plusDays(1));
    return getFirstScheduledTimeOnDay(nextDay);
}

From source file:com.google.android.apps.paco.NonESMSignalGenerator.java

License:Open Source License

private DateTime scheduleDaily(DateTime now) {
    DateTime nowMidnight = now.toDateMidnight().toDateTime();
    if (nextRepeatDaily(nowMidnight).equals(nowMidnight)) {
        DateTime nextTimeToday = getNextTimeToday(now, nowMidnight);
        if (nextTimeToday != null) {
            return nextTimeToday;
        }/* ww w  .j a v  a  2  s  . c  o  m*/
    }
    DateTime nextDay = getNextScheduleDay(nowMidnight.plusDays(1));
    return getFirstScheduledTimeOnDay(nextDay);
}