Example usage for org.joda.time DateTime toString

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

Introduction

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

Prototype

@ToString
public String toString() 

Source Link

Document

Output the date time in ISO8601 format (yyyy-MM-ddTHH:mm:ss.SSSZZ).

Usage

From source file:com.pacoapp.paco.triggering.AlarmCreator2.java

License:Open Source License

private void createAlarm(DateTime alarmTime, ExperimentDAO experiment) {
    Log.i(PacoConstants.TAG,// w w w.  ja v  a  2 s.c o m
            "Creating alarm: " + alarmTime.toString() + " for experiment: " + experiment.getTitle());
    PendingIntent intent = createAlarmReceiverIntentForExperiment(alarmTime);
    alarmManager.cancel(intent);
    alarmManager.set(AlarmManager.RTC_WAKEUP, alarmTime.getMillis(), intent);
}

From source file:com.pacoapp.paco.triggering.NotificationCreator.java

License:Open Source License

private void createAllNotificationsForLastMinute(long alarmTime) {
    DateTime alarmAsDateTime = new DateTime(alarmTime);
    Log.i(PacoConstants.TAG, "Creating All notifications for last minute from signaled alarmTime: "
            + alarmAsDateTime.toString());

    List<ExperimentDAO> experimentDAOs = Lists.newArrayList();
    for (Experiment experiment : experimentProviderUtil.getJoinedExperiments()) {
        experimentDAOs.add(experiment.getExperimentDAO());
    }//from   w  w  w  . j a  v  a  2 s . c o  m
    List<ActionSpecification> times = ActionScheduleGenerator.getAllAlarmsWithinOneMinuteofNow(
            alarmAsDateTime.minusSeconds(59), experimentDAOs, new AndroidEsmSignalStore(context),
            experimentProviderUtil);

    for (ActionSpecification timeExperiment : times) {
        if (timeExperiment.action == null) {
            continue; // not a notification action specification
        }
        // TODO might we be able to timeout all notifications for all experiments
        // instead of doing this for each experiment?
        final Long experimentId = timeExperiment.experiment.getId();
        ExperimentGroup experimentGroup = timeExperiment.experimentGroup;
        if (experimentGroup == null) {
            timeoutNotifications(experimentProviderUtil.getAllNotificationsFor(experimentId));
        } else {
            List<NotificationHolder> notificationsForGroup = experimentProviderUtil
                    .getNotificationsFor(experimentId, experimentGroup.getName());
            timeoutNotifications(notificationsForGroup);
        }
        createNewNotificationForExperiment(context, timeExperiment, false);
    }
}

From source file:com.precioustech.fxtrading.oanda.restapi.order.OandaOrderManagementProvider.java

License:Apache License

HttpPost createPostCommand(Order<String, Long> order, Long accountId) throws Exception {
    HttpPost httpPost = new HttpPost(this.url + OandaConstants.ACCOUNTS_RESOURCE + TradingConstants.FWD_SLASH
            + accountId + ordersResource);
    httpPost.setHeader(this.authHeader);
    List<NameValuePair> params = Lists.newArrayList();
    // TODO: apply proper rounding. Oanda rejects 0.960000001
    params.add(new BasicNameValuePair(instrument, order.getInstrument().getInstrument()));
    params.add(new BasicNameValuePair(side, OandaUtils.toSide(order.getSide())));
    params.add(new BasicNameValuePair(type, OandaUtils.toType(order.getType())));
    params.add(new BasicNameValuePair(units, String.valueOf(order.getUnits())));
    params.add(new BasicNameValuePair(takeProfit, String.valueOf(order.getTakeProfit())));
    params.add(new BasicNameValuePair(stopLoss, String.valueOf(order.getStopLoss())));
    if (order.getType() == OrderType.LIMIT && order.getPrice() != 0.0) {
        DateTime now = DateTime.now();/*from w  w w.j  a v a 2s.  com*/
        DateTime nowplus4hrs = now.plusHours(4);// TODO: why this code
        // for expiry?
        String dateStr = nowplus4hrs.toString();
        params.add(new BasicNameValuePair(price, String.valueOf(order.getPrice())));
        params.add(new BasicNameValuePair(expiry, dateStr));
    }
    httpPost.setEntity(new UrlEncodedFormEntity(params));
    return httpPost;
}

From source file:com.precioustech.fxtrading.trade.Trade.java

License:Apache License

public Trade(M tradeId, long units, TradingSignal side, TradeableInstrument<N> instrument, DateTime tradeDate,
        double takeProfitPrice, double executionPrice, double stopLoss, K accountId) {
    this.tradeId = tradeId;
    this.units = units;
    this.side = side;
    this.instrument = instrument;
    this.tradeDate = tradeDate;
    this.takeProfitPrice = takeProfitPrice;
    this.executionPrice = executionPrice;
    this.stopLoss = stopLoss;
    this.accountId = accountId;
    this.toStr = String.format(
            "Trade Id=%d, Units=%d, Side=%s, Instrument=%s, TradeDate=%s, TP=%3.5f, Price=%3.5f, SL=%3.5f",
            tradeId, units, side, instrument, tradeDate.toString(), takeProfitPrice, executionPrice, stopLoss);
}

From source file:com.restservice.database.Transactor.java

License:Open Source License

/**
 * Adds a search term to the database, to be processed by the daemon.
 * /*from   w w w. j av a2  s  .co m*/
 * @param term
 *            String that should be looked for
 * @throws SQLException
 *             thrown if a SQL-Error occurs
 */
public void saveSearchTerm(String term) throws SQLException {
    try {

        connect = DriverManager.getConnection(dbUrl);

        readStatement = connect.prepareStatement(readQuery);
        readStatement.execute();

        prepStatement = connect.prepareStatement(
                "insert into search_terms (term, active, current_start, old_start, interval_length, time_last_fetched, last_fetched_tweet_id, last_fetched_tweet_count, when_created)"
                        + "values (?, ?, ?, ?, ?, ?, ?, ?, ?);");

        DateTime now = new DateTime(DateTimeZone.UTC);

        String sNow = now.toString();
        sNow = sNow.replace("T", " ");
        if (sNow.indexOf(".") > -1)
            sNow = sNow.substring(0, sNow.indexOf("."));

        //System.out.println("SQL UTC time: " + Timestamp.valueOf(sNow).toString());

        prepStatement.setString(1, term);
        prepStatement.setBoolean(2, true);
        prepStatement.setTimestamp(3, Timestamp.valueOf(sNow));
        prepStatement.setNull(4, java.sql.Types.NULL);
        prepStatement.setTime(5, Time.valueOf("00:15:00"));
        prepStatement.setNull(6, java.sql.Types.NULL);
        prepStatement.setNull(7, java.sql.Types.NULL);
        prepStatement.setNull(8, java.sql.Types.NULL);
        prepStatement.setTimestamp(9, Timestamp.valueOf(sNow));

        prepStatement.execute();
    } catch (SQLException e) {
        throw e;
    } finally {
        close();
    }
}

From source file:com.salesmanBuddy.dao.SharedDAO.java

License:Open Source License

protected List<Licenses> getLicensesWithStockNumberFromTo(String stockNumber, DateTime from, DateTime to) {
    final String sql = "SELECT l.* from answers a, questions q, licenses l WHERE a.answerText = ? AND q.tag = ? AND a.questionId = q.id AND l.id = a.licenseId AND l.created between ? and ? ORDER BY l.created";
    return this.getList(sql, Licenses.class, stockNumber, QUESTION_STOCK_NUMBER, from.toString(),
            to.toString());/*from   w w w.  j  av  a 2s.c  o  m*/
}

From source file:com.salesmanBuddy.dao.SharedDAO.java

License:Open Source License

protected List<Licenses> getLicensesForUserIdDateRange(Integer userId, DateTime to, DateTime from) {
    final String sql = "SELECT * FROM licenses WHERE userId = ? AND created BETWEEN ? AND ?";
    return this.getList(sql, Licenses.class, userId, from.toString(), to.toString());
}

From source file:com.salesmanBuddy.dao.SharedDAO.java

License:Open Source License

protected List<Licenses> getLicensesForDealershipIdDateRange(Integer dealershipId, DateTime from, DateTime to) {
    final String sql = "SELECT * FROM licenses WHERE userId IN (SELECT id FROM users WHERE dealershipId = ?) AND created BETWEEN ? AND ?";
    return this.getList(sql, Licenses.class, dealershipId, from.toString(), to.toString());
}

From source file:com.salesmanBuddy.dao.SharedDAO.java

License:Open Source License

protected List<StockNumbers> getStockNumbersForDealershipFromTo(Integer dealershipId, DateTime from,
        DateTime to) {//from   w  ww.ja v  a2s  .co m
    final String sql = "SELECT * FROM stockNumbers WHERE dealershipId = ? AND soldOn between ? and ?";
    return this.getList(sql, StockNumbers.class, dealershipId, from.toString(), to.toString());
}

From source file:com.sos.hibernate.classes.UtcTimeHelper.java

License:Apache License

public static String convertTimeZonesToString(String dateFormat, String fromTimeZone, String toTimeZone,
        DateTime fromDateTime) {/*from   w ww  .j  a  v a 2s  .co  m*/
    DateTimeZone fromZone = DateTimeZone.forID(fromTimeZone);
    DateTimeZone toZone = DateTimeZone.forID(toTimeZone);

    DateTime dateTime = new DateTime(fromDateTime);

    dateTime = dateTime.withZoneRetainFields(fromZone);

    DateTime toDateTime = new DateTime(dateTime).withZone(toZone);

    DateTimeFormatter oFormatter = DateTimeFormat.forPattern("yyyy-MM-dd'T'H:mm:ss.SSSZ");
    DateTimeFormatter oFormatter2 = DateTimeFormat.forPattern(dateFormat);

    DateTime newDate = oFormatter.withOffsetParsed().parseDateTime(toDateTime.toString());

    return oFormatter2.withZone(toZone).print(newDate.getMillis());

}