Example usage for org.joda.time DateTime toDateTime

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

Introduction

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

Prototype

public DateTime toDateTime() 

Source Link

Document

Get this object as a DateTime by returning this.

Usage

From source file:com.ning.billing.catalog.DefaultPlan.java

License:Apache License

@Override
public DateTime dateOfFirstRecurringNonZeroCharge(final DateTime subscriptionStartDate,
        final PhaseType initialPhaseType) {
    DateTime result = subscriptionStartDate.toDateTime();
    boolean skipPhase = initialPhaseType == null ? false : true;
    for (final PlanPhase phase : getAllPhases()) {
        if (skipPhase) {
            if (phase.getPhaseType() != initialPhaseType) {
                continue;
            } else {
                skipPhase = false;//from w ww  .  j  a  v a2 s . c o  m
            }
        }
        if (phase.getRecurringPrice() == null || phase.getRecurringPrice().isZero()) {
            result = phase.getDuration().addToDateTime(result);
        } else {
            break;
        }
    }
    return result;
}

From source file:com.pacoapp.paco.shared.scheduling.NonESMSignalGenerator.java

License:Open Source License

private SignalTimeHolder getNextTimeForFixedType(SignalTime signalTime, List<SignalTimeHolder> previousTimes,
        DateTime nowMidnight) {
    if (previousTimes.size() == 0 || signalTime.getMissedBasisBehavior() == null
            || signalTime.getMissedBasisBehavior().equals(SignalTime.MISSED_BEHAVIOR_USE_SCHEDULED_TIME)) {
        return new SignalTimeHolder(null, null,
                nowMidnight.toDateTime().plusMillis(signalTime.getFixedTimeMillisFromMidnight()), signalTime);
    } else if (signalTime.getMissedBasisBehavior().equals(SignalTime.MISSED_BEHAVIOR_SKIP)
            && previousEventHasResponse(previousTimes)) {
        return new SignalTimeHolder(null, null,
                nowMidnight.toDateTime().plusMillis(signalTime.getFixedTimeMillisFromMidnight()), signalTime);
    } else {/*from www .  ja  v  a  2s . c o  m*/
        return createNullSignalTimeHolder(signalTime);
    }
}

From source file:eu.jsan.duvi.commons.conversion.date.joda.DateTimeConverter.java

License:Apache License

@Override
public Timestamp convertToDatabaseColumn(DateTime value) {
    if (value != null) {
        return new Timestamp(value.toDateTime().getMillis());
    }/*from w w  w .  j a va 2 s  . c  o  m*/
    return null;
}

From source file:net.sourceforge.fenixedu.domain.accounting.ServiceAgreementTemplate.java

License:Open Source License

public PostingRule findPostingRuleByEventTypeAndDate(EventType eventType, DateTime when) {
    final PostingRule postingRule = getPostingRuleByEventTypeAndDate(eventType, when);

    if (postingRule == null) {
        throw new DomainException(
                "error.accounting.agreement.ServiceAgreementTemplate.cannot.find.postingRule.for.eventType.and.date.desc",
                when.toDateTime().toString("dd-MM-yyyy HH:mm"),
                getEnumerationResourcesString(eventType.getQualifiedName()));
    }/*from ww w  .  ja  va 2  s .  c o  m*/

    return postingRule;

}

From source file:org.efaps.esjp.common.uitable.MultiPrint_Base.java

License:Apache License

/**
 * @param _field Field the date is wanted for
 * @return datetime array/*from  w w w  . j av a  2s  .  c o  m*/
 * @throws EFapsException on error
 */
protected Object[] getFilter(final Field _field) throws EFapsException {
    Object[] ret = null;
    final String filter = _field.getFilter().getDefaultValue();
    if (filter != null) {
        final String[] parts = filter.split(":");
        final String range = parts[0];
        final int fromSub = parts.length > 1 ? Integer.parseInt(parts[1]) : 0;
        final int rangeCount = parts.length > 2 ? Integer.parseInt(parts[2]) : 1;
        DateTime dateFrom = new DateTime();
        DateTime dateTo = new DateTime();
        if (range != null) {
            final FilterDefault def = FilterDefault.valueOf(range.toUpperCase());
            // to get a timezone dependent DateTim
            DateTime tmp = DateTimeUtil.translateFromUI(new DateTime()).withTimeAtStartOfDay();
            switch (def) {
            case TODAY:
                dateFrom = tmp.toDateTime().minusDays(fromSub).minusMinutes(1);
                dateTo = dateFrom.plusDays(rangeCount).plusSeconds(1);
                ret = new DateTime[] { dateFrom, dateTo };
                break;
            case WEEK:
                // the first of the current week
                tmp = tmp.minusDays(tmp.getDayOfWeek() - 1);
                dateFrom = tmp.minusWeeks(fromSub).minusMinutes(1);
                dateTo = tmp.plusWeeks(rangeCount);
                ret = new DateTime[] { dateFrom, dateTo };
                break;
            case MONTH:
                // the first of the current month
                tmp = tmp.minusDays(tmp.getDayOfMonth() - 1);
                // substract the month and a minute before
                dateFrom = tmp.minusMonths(fromSub).minusMinutes(1);
                // add the month
                dateTo = tmp.plusMonths(rangeCount);
                ret = new DateTime[] { dateFrom, dateTo };
                break;
            case YEAR:
                tmp = tmp.minusDays(tmp.getDayOfYear() - 1);
                dateFrom = tmp.minusYears(fromSub).minusMinutes(1);
                dateTo = tmp.plusYears(rangeCount);
                ret = new DateTime[] { dateFrom, dateTo };
                break;
            case ALL:
                ret = new String[] { "*" };
                break;
            case NONE:
                break;
            default:
                ret = new String[] { range + "*" };
                break;
            }
        }
    }
    return ret;
}

From source file:org.jlucrum.realtime.eventtypes.MarketData.java

License:Open Source License

public void setDate(DateTime date) {
    this.date = date.toDateTime();
}

From source file:org.joda.example.time.Examples.java

License:Apache License

private void runDateTime() {
    System.out.println("DateTime");
    System.out.println("=======");
    System.out.println(/*  w  w  w.jav  a 2s  . c  om*/
            "DateTime stores a the date and time using millisecs from 1970-01-01T00:00:00Z internally");
    System.out.println("DateTime is immutable and thread-safe");
    System.out.println("                      in = new DateTime()");
    DateTime in = new DateTime();
    System.out.println("Millisecond time:     in.getMillis():           " + in.getMillis());
    System.out.println("ISO string version:   in.toString():            " + in.toString());
    System.out.println("ISO chronology:       in.getChronology():       " + in.getChronology());
    System.out.println("Your time zone:       in.getDateTimeZone():     " + in.getZone());
    System.out.println("Change millis:        in.withMillis(0):         " + in.withMillis(0L));
    System.out.println("");
    System.out.println("Get year:             in.getYear():             " + in.getYear());
    System.out.println("Get monthOfYear:      in.getMonthOfYear():      " + in.getMonthOfYear());
    System.out.println("Get dayOfMonth:       in.getDayOfMonth():       " + in.getDayOfMonth());
    System.out.println("...");
    System.out.println("Property access:      in.dayOfWeek().get():                   " + in.dayOfWeek().get());
    System.out.println(
            "Day of week as text:  in.dayOfWeek().getAsText():             " + in.dayOfWeek().getAsText());
    System.out.println(
            "Day as short text:    in.dayOfWeek().getAsShortText():        " + in.dayOfWeek().getAsShortText());
    System.out.println("Day in french:        in.dayOfWeek().getAsText(Locale.FRENCH):"
            + in.dayOfWeek().getAsText(Locale.FRENCH));
    System.out.println("Max allowed value:    in.dayOfWeek().getMaximumValue():       "
            + in.dayOfWeek().getMaximumValue());
    System.out.println("Min allowed value:    in.dayOfWeek().getMinimumValue():       "
            + in.dayOfWeek().getMinimumValue());
    System.out.println(
            "Copy & set to Jan:    in.monthOfYear().setCopy(1):            " + in.monthOfYear().setCopy(1));
    System.out.println(
            "Copy & add 14 months: in.monthOfYear().addCopy(14):           " + in.monthOfYear().addToCopy(14));
    System.out.println("Add 14 mnths in field:in.monthOfYear().addWrapFieldCopy(14):  "
            + in.monthOfYear().addWrapFieldToCopy(14));
    System.out.println("...");
    System.out.println("Convert to Instant:   in.toInstant():           " + in.toInstant());
    System.out.println("Convert to DateTime:  in.toDateTime():          " + in.toDateTime());
    System.out.println("Convert to MutableDT: in.toMutableDateTime():   " + in.toMutableDateTime());
    System.out.println("Convert to Date:      in.toDate():              " + in.toDate());
    System.out.println("Convert to Calendar:  in.toCalendar(Locale.UK): "
            + in.toCalendar(Locale.UK).toString().substring(0, 46));
    System.out.println("Convert to GregCal:   in.toGregorianCalendar(): "
            + in.toGregorianCalendar().toString().substring(0, 46));
    System.out.println("");
    System.out.println("                      in2 = new DateTime(in.getMillis() + 10)");
    DateTime in2 = new DateTime(in.getMillis() + 10);
    System.out.println("Equals ms and chrono: in.equals(in2):           " + in.equals(in2));
    System.out.println("Compare millisecond:  in.compareTo(in2):        " + in.compareTo(in2));
    System.out.println("Compare millisecond:  in.isEqual(in2):          " + in.isEqual(in2));
    System.out.println("Compare millisecond:  in.isAfter(in2):          " + in.isAfter(in2));
    System.out.println("Compare millisecond:  in.isBefore(in2):         " + in.isBefore(in2));
}

From source file:org.jtotus.common.DateIterator.java

License:Open Source License

public DateIterator(DateTime startDate, DateTime endDate) {
    fromDate = startDate.toDateTime();
    toDate = endDate.toDateTime();/*from ww  w.ja  va  2 s .  c o  m*/

    if (!toDate.isAfter(fromDate)) {
        System.err.printf("Warning startin date is afte ending date! Reversing dates(" + fromDate.toDate() + ":"
                + toDate.toDate() + "\n");
        DateTime tmp = fromDate.toDateTime();
        fromDate = toDate;
        toDate = tmp;

        System.err.printf("New time startin date is afte ending date! Reversing dates(" + fromDate.toDate()
                + ":" + toDate.toDate() + "\n");
    }

    current = fromDate.toDateTime();
}

From source file:org.jtotus.database.NetworkOP.java

License:Open Source License

private String buildRequest(DateTime calendar, String stockName) {
    //&from_year=2002&from_month=01&from_day=02&to_year=2010&to_month=10&to_day=01
    DateTime fromDate = calendar.toDateTime().minusDays(4);

    SimpleDateFormat startingDate = new SimpleDateFormat("'&from_year='yyyy'&from_month='MM'&from_day='dd");
    SimpleDateFormat endingDate = new SimpleDateFormat("'&to_year='yyyy'&to_month='MM'&to_day='dd");

    String request = urlName + new StockNames().getHexName(stockName) + urlParam
            + startingDate.format(fromDate.toDate()) + endingDate.format(calendar.toDate());

    if (debug) {/*www. jav  a2 s .  c  om*/
        System.out.printf("(" + calendar.toDate() + ")The full request: %s \n", request);
    }

    return request;
}

From source file:org.killbill.billing.catalog.DefaultPlan.java

License:Apache License

@Override
public DateTime dateOfFirstRecurringNonZeroCharge(final DateTime subscriptionStartDate,
        final PhaseType initialPhaseType) {
    DateTime result = subscriptionStartDate.toDateTime();
    boolean skipPhase = initialPhaseType == null ? false : true;
    for (final PlanPhase phase : getAllPhases()) {
        if (skipPhase) {
            if (phase.getPhaseType() != initialPhaseType) {
                continue;
            } else {
                skipPhase = false;//from   w ww  . j  a  v  a 2s  .  c  om
            }
        }
        final Recurring recurring = phase.getRecurring();
        if (recurring == null || recurring.getRecurringPrice() == null
                || recurring.getRecurringPrice().isZero()) {
            result = phase.getDuration().addToDateTime(result);
        } else {
            break;
        }
    }
    return result;
}