Example usage for org.joda.time DateTime minusMillis

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

Introduction

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

Prototype

public DateTime minusMillis(int millis) 

Source Link

Document

Returns a copy of this datetime minus the specified number of millis.

Usage

From source file:com.reclabs.recomendar.common.helpers.types.DateHelper.java

License:Open Source License

/**
 * Subtract to the current date the amount of that precisionType represent.
 * @param date The date to subtract/*from   www  .  ja  va  2  s. co  m*/
 * @param amount The amount to subtract
 * @param precisionType The field to subtract
 * @return The new date
 */
public static Date subtract(Date date, int amount, DatePrecisionType precisionType) {
    DateTime jodaDate1 = new DateTime(date.getTime());
    DateTime result;
    switch (precisionType) {
    case YEAR:
        result = jodaDate1.minusYears(amount);
        break;
    case MONTH:
        result = jodaDate1.minusMonths(amount);
        break;
    case DAY:
        result = jodaDate1.minusDays(amount);
        break;
    case HOUR:
        result = jodaDate1.minusHours(amount);
        break;
    case MINUTE:
        result = jodaDate1.minusMinutes(amount);
        break;
    case SECOND:
        result = jodaDate1.minusSeconds(amount);
        break;
    case MILLISECOND:
        result = jodaDate1.minusMillis(amount);
        break;
    default:
        LOGGER.warn("[Error subtract, precision value is invalid: {}]", precisionType);
        throw new RecIllegalArgumentException("The precision value is invalid " + precisionType);
    }
    return result.toDate();
}

From source file:com.sos.jobnet.creator.FrequencyChecker.java

License:Apache License

public void processJobNet(JobNetPlanDBItem bootstrapOrder) {

    String uuid = bootstrapOrder.getUuid();
    logger.info(msg.getMsg(JOBNETCH_I_0001, uuid)); // processing jobnet with id %1$s.
    logger.debug(msg.getMsg(JOBNETCH_D_0002, bootstrapOrder.getNodeId())); // bootstrap order has node id %2$s.

    Date d = bootstrapOrder.getPlannedStartTime();
    if (d == null) {
        String msgText = msg.getMsg(JOBNETCH_E_0001); // bootstrap order has no single_start
        logger.error(msgText);/* w  w w.j  a  v a 2s. co m*/
        throw new JobNetException(msgText);
    }
    DateTime from = new DateTime(d);
    from = from.minusMillis(from.getMillisOfDay());
    DateTime to = from.plusDays(1);
    Interval baseInterval = new Interval(from, to);
    logger.debug(msg.getMsg(JOBNETCH_D_0001, fmtDateTime.print(from), fmtDateTime.print(to))); // searching for start times of job net nodes from %1$s to %2$s
    LocalDate forDay = new LocalDate(from);

    //      logger.debug(msg.getMsg(JOBNETCH_D_0003,fmtDate.print(baseInterval.getStart()))); // searching for starts at %2$s.
    List<JobNetPlanDBItem> jobnetOrders = getJobnet(uuid);
    if (jobnetOrders == null) {
        String msgText = msg.getMsg(JOBNETCH_E_0002, uuid);
        logger.error(msgText); // no jobnet found for UUID %1$s.
        throw new JobSchedulerException(msgText);
    }

    logger.debug(msg.getMsg(JOBNETCH_D_0004, jobnetOrders.size())); // the jobnet contains %1$s nodes.
    factory.setUseDefaultPeriod(true); // allows the use of runtime elements without or with incomplete periods

    planDbLayer.beginTransaction();
    for (JobNetPlanDBItem currentOrder : jobnetOrders) {
        JobNetNodeDBItem currentNode = getJobNetNode(currentOrder.getNodeId());
        if (!currentOrder.getBootstrap()) { // the properties for the bootstrap order has to be set in JobNetPlanCreator
            if (currentOrder.getIsRunnerSkipped()) {
                logger.info(msg.getMsg(JOBNETCH_I_0002, currentNode.getNode(), currentOrder.getNodeId())); // order %1$s (node id %2$s) is already skipped.
            } else {
                JSObjOrder jsOrder = getJSObjOrder(currentOrder.getOrderXml());
                JSObjRunTime runTime = jsOrder.getJSObjRunTime();
                if (runTime.hasSubsequentRunTimes()) {
                    LocalDate startDay = getNextStartDayInIntervalOrNull(runTime, baseInterval);
                    if (startDay == null) {
                        currentOrder.setIsRunnerSkipped(true);
                        // order %1$s (node id %2$s) has no start time for %3$s and will be skipped.
                        logger.info(msg.getMsg(JOBNETCH_I_0003, currentNode.getNode(), currentOrder.getNodeId(),
                                fmtDate.print(forDay)));
                    } else {
                        // order %1$s (node id %2$s) has a start time for %3$s and will NOT skipped.
                        logger.debug(msg.getMsg(JOBNETCH_I_0005, currentNode.getNode(),
                                currentOrder.getNodeId(), fmtDate.print(forDay)));
                        if (currentOrder.getIsRunnerOnDemand()) {
                            // order %1$s (node id %2$s) has to be started on demand.
                            logger.info(msg.getMsg(JOBNETCH_I_0006, currentNode.getNode(),
                                    currentOrder.getNodeId()));
                            currentOrder.setIsRunnerOnDemand(true);
                        }
                    }
                } else {
                    if (currentOrder.getIsRunnerOnDemand()) {
                        // order %1$s (node id %2$s) has no start time and will be NOT skipped.
                        currentOrder.setIsRunnerOnDemand(true);
                        logger.info(
                                msg.getMsg(JOBNETCH_I_0004, currentNode.getNode(), currentOrder.getNodeId()));
                    } else {
                        logger.debug(
                                "nothing to do - order has neither a start_time nor the parameter on_demand.");
                    }
                }
                logger.debug(currentOrder.getOrderXml().replace("\n", ""));
                planDbLayer.update(currentOrder);

            }
        }
        logRecord(currentNode, currentOrder);
    }
    planDbLayer.commit();
}

From source file:com.sos.scheduler.model.objects.IntervalConstants.java

License:Apache License

public Interval getInterval() {
    DateTime from = new DateTime();
    DateTime to = null;//from ww  w  . j ava 2 s.c om
    switch (this) {
    case CURRENT_DAY:
        from = from.minusMillis(from.getMillisOfDay());
        to = from.plusDays(1);
        break;
    case CURRENT_WEEK:
        from = from.minusMillis(from.getMillisOfDay()).minusDays(from.getDayOfWeek());
        to = from.plusWeeks(1);
        break;
    case REST_OF_DAY:
        to = from.minusMillis(from.getMillisOfDay()).plusDays(1);
        break;
    case NEXT_24H:
        to = from.plusDays(1);
        break;
    case NEXT_WEEK:
        to = from.plusWeeks(1);
        break;
    }
    return new Interval(from, to);
}

From source file:com.sos.scheduler.model.objects.JodaTools.java

License:Apache License

public static DateTime getDayInMonth(DateTime date, int day) {
    DateTime baseDate = (day > 1) ? date.minusMonths(1) : date;
    DateTime result = getEndOfMonth(baseDate).plusDays(day);
    return result.minusMillis(result.getMillisOfDay());
}

From source file:com.sos.scheduler.model.objects.JodaTools.java

License:Apache License

public static DateTime getStartOfMonth(DateTime base) {
    return base.minusMillis(base.getMillisOfDay()).minusDays(base.getDayOfMonth() - 1);
}

From source file:com.sos.scheduler.model.objects.JodaTools.java

License:Apache License

public static DateTime getStartOfDay(DateTime base) {
    return base.minusMillis(base.getMillisOfDay());
}

From source file:com.tremolosecurity.provisioning.sharepoint.SharePointGroups.java

License:Apache License

private UserGroupSoap getConnection(URL url) throws Exception {
    UserGroup ss = new UserGroup(wsdl.toURI().toURL(), SERVICE);
    UserGroupSoap port = ss.getUserGroupSoap12();

    BindingProvider provider = (BindingProvider) port;

    if (authType == AuthType.UnisonLastMile) {
        DateTime now = new DateTime();
        DateTime future = now.plusMillis(this.skew);
        now = now.minusMillis(skew);
        com.tremolosecurity.lastmile.LastMile lastmile = new com.tremolosecurity.lastmile.LastMile(
                url.getPath(), now, future, 0, "chainName");
        lastmile.getAttributes().add(new Attribute("userPrincipalName", this.administratorUPN));

        SecretKey sk = this.cfg.getSecretKey(this.keyAlias);
        Map<String, List<String>> headers = (Map<String, List<String>>) provider.getRequestContext()
                .get(MessageContext.HTTP_REQUEST_HEADERS);
        if (headers == null) {
            headers = new HashMap<String, List<String>>();
        }/*from   ww w.  j a  v  a2s  . c  o  m*/

        headers.put(this.headerName, Collections.singletonList(lastmile.generateLastMileToken(sk)));

        provider.getRequestContext().put(MessageContext.HTTP_REQUEST_HEADERS, headers);
    } else if (authType == AuthType.NTLM) {
        NtlmAuthenticator authenticator = new NtlmAuthenticator(this.administratorUPN,
                this.administratorPassword);
        Authenticator.setDefault(authenticator);

    }

    provider.getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, url.toString());

    return port;
}

From source file:com.tremolosecurity.provisioning.sharepoint.SharePointGroups.java

License:Apache License

private void touch(String upn) throws Exception {

    if (this.authType == AuthType.UnisonLastMile) {
        DateTime now = new DateTime();
        DateTime future = now.plusMillis(this.skew);
        now = now.minusMillis(skew);
        com.tremolosecurity.lastmile.LastMile lastmile = new com.tremolosecurity.lastmile.LastMile(
                "/Pages/Default.aspx", now, future, 0, "chainName");
        lastmile.getAttributes().add(new Attribute("userPrincipalName", upn));

        SecretKey sk = this.cfg.getSecretKey(this.keyAlias);

        DefaultHttpClient http = new DefaultHttpClient();
        HttpGet get = new HttpGet(this.touchURL);
        get.addHeader(this.headerName, lastmile.generateLastMileToken(sk));
        http.execute(get);//from   w  w  w  .ja v  a  2  s. co m
    } else {

    }

}

From source file:com.tremolosecurity.unison.filter.CatchFirstLogin.java

License:Apache License

@Override
public void doFilter(HttpFilterRequest request, HttpFilterResponse response, HttpFilterChain chain)
        throws Exception {
    HttpSession session = request.getSession();
    if (session.getAttribute(key) == null) {

        AuthInfo userData = ((AuthController) request.getSession().getAttribute(ProxyConstants.AUTH_CTL))
                .getAuthInfo();//from   w  w  w  . j  a  va 2  s  . c om

        Attribute attr = userData.getAttribs().get("userPrincipalName");
        if (attr == null) {
            throw new Exception("User has not userPrincipalName attribute");
        }

        DateTime now = new DateTime();
        DateTime future = now.plusMillis(this.skew);
        now = now.minusMillis(skew);
        com.tremolosecurity.lastmile.LastMile lastmile = new com.tremolosecurity.lastmile.LastMile(
                "/Pages/Default.aspx", now, future, 0, "chainName");
        lastmile.getAttributes().add(new Attribute("userPrincipalName", attr.getValues().get(0)));

        SecretKey sk = this.cfg.getSecretKey(this.keyAlias);

        DefaultHttpClient http = new DefaultHttpClient();
        HttpGet get = new HttpGet(this.touchURL);
        get.addHeader(this.headerName, lastmile.generateLastMileToken(sk));
        HttpResponse resp = http.execute(get);

        BufferedReader in = new BufferedReader(new InputStreamReader(resp.getEntity().getContent()));

        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        String line = null;
        while ((line = in.readLine()) != null) {
            baos.write(line.getBytes("UTF-8"));
            baos.write('\n');
        }

        in.close();

        String txt = new String(baos.toByteArray());

        if (txt.contains("An unexpected error has occured")) {
            response.sendRedirect(this.redirectURI);
            chain.setLogout(true);
            chain.setNoProxy(true);
            return;
        }

        session.setAttribute(key, key);
    }

    chain.nextFilter(request, response, chain);

}

From source file:com.tripadvisor.seekbar.ClockView.java

License:Apache License

public void setBounds(DateTime minTime, DateTime maxTime, boolean isMaxClock) {
    // NOTE: To show correct end time on clock, since the Interval.contains() checks for
    // millisInstant >= thisStart && millisInstant < thisEnd
    // however we want
    // millisInstant >= thisStart && millisInstant <= thisEnd
    maxTime = maxTime.plusMillis(1);//from  w ww .  j a  va  2  s  .c om
    mValidTimeInterval = new Interval(minTime, maxTime);
    maxTime = maxTime.minusMillis(1);
    mCircularClockSeekBar.reset();
    if (isMaxClock) {
        mOriginalTime = maxTime;
        mCurrentValidTime = maxTime;
        int hourOfDay = maxTime.get(DateTimeFieldType.clockhourOfDay()) % 12;
        mCircularClockSeekBar.setProgress(hourOfDay * 10);
        setClockText(mOriginalTime);
    } else {
        mOriginalTime = minTime;
        mCurrentValidTime = minTime;
        int hourOfDay = minTime.get(DateTimeFieldType.clockhourOfDay()) % 12;
        mCircularClockSeekBar.setProgress(hourOfDay * 10);
        setClockText(mOriginalTime);
    }
}