Example usage for org.joda.time DateTime plusHours

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

Introduction

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

Prototype

public DateTime plusHours(int hours) 

Source Link

Document

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

Usage

From source file:es.ucm.fdi.tutorias.web.TutoriasController.java

License:Open Source License

@RequestMapping(method = RequestMethod.GET, value = Constants.URL_NUEVA_TUTORIA)
public ModelAndView nuevoEspacio() {
    Map<String, Object> model = new HashMap<>();
    model.put("modo", "Crear");
    model.put("method", "POST");
    model.put("users", userService.listUsers());
    model.put("tutoria", new TutoriaBuilder());
    DateTime ahora = DateTime.now();
    model.put("fecha_defecto_inicio", ahora.plusHours(2));
    model.put("fecha_defecto_fin", ahora.plusHours(3));
    return new ModelAndView("editorTutorias", model);
}

From source file:es.usc.citius.servando.calendula.activities.ConfirmActivity.java

License:Open Source License

public Pair<DateTime, DateTime> getCheckMarginInterval(DateTime intakeTime) {

    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
    String checkMarginStr = prefs.getString("check_window_margin", "" + DEFAULT_CHECK_MARGIN);
    int checkMargin = Integer.parseInt(checkMarginStr);

    DateTime start = intakeTime.minusMinutes(30);
    DateTime end = intakeTime.plusHours(checkMargin);
    return new Pair<>(start, end);

}

From source file:eu.finwest.dao.MockDataBuilder.java

private Listing prepareListing(LangVersion lang, String campaign, UserVO owner, String name,
        Listing.State state, String category, int amount, int percentage, String mantra, String summary,
        String companyUrl, DateTime createdAt, DateTime modifiedAt, String logo_url, String address,
        boolean hasBMC, boolean hasIP, String valuation, String cashflow) {
    Listing bp = new Listing();
    bp.id = id();/*from  w  ww. ja va 2s  . c  om*/
    bp.lang = lang;
    bp.currency = lang == LangVersion.PL ? Currency.PLN : Currency.EUR;
    bp.campaign = campaign != null ? campaign : (lang == LangVersion.PL ? "pl" : "en");
    bp.name = name;
    bp.summary = summary;
    bp.mantra = mantra;
    bp.owner = new Key<SBUser>(SBUser.class, owner.toKeyId());
    bp.contactEmail = owner.getEmail();
    bp.founders = getFounders(owner.getName());
    bp.type = Listing.Type.COMPANY;
    bp.notes = "Mock listing.\n";

    bp.askedForFunding = amount > 0;
    bp.suggestedAmount = amount;
    bp.suggestedPercentage = percentage;

    bp.category = category;
    bp.state = state;

    int hours = new Random().nextInt(500) + 80;
    DateTime createdTime = createdAt != null ? createdAt : new DateTime().minusHours(hours);
    if (modifiedAt != null) {
        bp.modified = modifiedAt.toDate();
    }

    bp.created = createdTime.toDate();
    switch (state) {
    case NEW:
        break;
    case POSTED:
        bp.posted = createdTime.plusHours(hours * 5 / 10).toDate();
        break;
    case ACTIVE:
    case FROZEN:
        bp.posted = createdTime.plusHours(hours * 7 / 10).toDate();
        bp.listedOn = createdTime.plusHours(hours * 4 / 10).toDate();
        if (bp.askedForFunding) {
            bp.closingOn = createdTime.plusHours(hours * 4 / 10).plusDays(30).toDate();
        }
        break;
    case WITHDRAWN:
        bp.posted = createdTime.plusHours(hours * 8 / 10).toDate();
        bp.listedOn = createdTime.plusHours(hours * 6 / 10).toDate();
        bp.closingOn = createdTime.plusHours(hours * 6 / 10).plusDays(30).toDate();
        break;
    case CLOSED:
        hours = new Random().nextInt(500) + 33 * 24;
        createdTime = new DateTime().minusHours(hours);
        bp.created = createdTime.toDate();
        bp.posted = createdTime.plusHours(24).toDate();
        bp.listedOn = createdTime.plusHours(48).toDate();
        bp.closingOn = createdTime.plusDays(32).toDate();
        break;
    }

    GeocodeLocation location = null;
    if (address != null) {
        location = getGeocodedLocation(address);
        location.randomize(0.1);
    }
    if (location == null) {
        location = getRandomLocation(lang);
        location.randomize(0.001);
    }

    bp.address = location.address;
    bp.city = location.city;
    bp.usState = "USA".equals(location.country) ? location.state : null;
    bp.country = location.country;
    DtoToVoConverter.updateBriefAddress(bp);
    bp.latitude = location.latitude;
    bp.longitude = location.longitude;

    bp.videoUrl = getVideo();

    bp.website = !StringUtils.isEmpty(companyUrl) ? companyUrl : getWebsite();

    bp.answer1 = hasBMC ? getQuote() : getQuoteWithNulls();
    bp.answer2 = hasBMC ? getQuote() : getQuoteWithNulls();
    bp.answer3 = hasBMC ? getQuote() : getQuoteWithNulls();
    bp.answer4 = hasBMC ? getQuote() : getQuoteWithNulls();
    bp.answer5 = hasBMC ? getQuote() : getQuoteWithNulls();
    bp.answer6 = hasBMC ? getQuote() : getQuoteWithNulls();
    bp.answer7 = hasBMC ? getQuote() : getQuoteWithNulls();
    bp.answer8 = hasBMC ? getQuote() : getQuoteWithNulls();
    bp.answer9 = hasBMC ? getQuote() : getQuoteWithNulls();
    bp.answer10 = hasIP ? getQuote() : getQuoteWithNulls();
    bp.answer11 = hasIP ? getQuote() : getQuoteWithNulls();
    bp.answer12 = hasIP ? getQuote() : getQuoteWithNulls();
    bp.answer13 = hasIP ? getQuote() : getQuoteWithNulls();
    bp.answer14 = hasIP ? getQuote() : getQuoteWithNulls();
    bp.answer15 = hasIP ? getQuote() : getQuoteWithNulls();
    bp.answer16 = hasIP ? getQuote() : getQuoteWithNulls();
    bp.answer17 = hasIP ? getQuote() : getQuoteWithNulls();
    bp.answer18 = hasIP ? getQuote() : getQuoteWithNulls();
    bp.answer19 = hasIP ? getQuote() : getQuoteWithNulls();
    bp.answer20 = hasIP ? getQuote() : getQuoteWithNulls();
    bp.answer21 = hasIP ? getQuote() : getQuoteWithNulls();
    bp.answer22 = hasIP ? getQuote() : getQuoteWithNulls();
    bp.answer23 = hasIP ? getQuote() : getQuoteWithNulls();
    bp.answer24 = hasIP ? getQuote() : getQuoteWithNulls();
    bp.answer25 = hasIP ? getQuote() : getQuoteWithNulls();
    bp.answer26 = hasIP ? getQuote() : getQuoteWithNulls();

    bp.hasBmc = hasBMC;
    bp.hasIp = hasIP;

    bp.valuationData = valuation;
    bp.cashflowData = cashflow;

    if (!StringUtils.isEmpty(logo_url)) {
        logo_url = logo_url.replaceAll("^https://", "http://");
        logoUrls.put(bp.id, logo_url);
    }

    return bp;
}

From source file:gr.cti.android.experimentation.controller.api.HistoryController.java

License:Open Source License

private void fillMissingIntervals(TreeSet<Long> treeSet, String rollup, long toLong) {

    //TODO: add non existing intervals
    if (rollup.endsWith("d")) {
        DateTime firstDate = new DateTime(treeSet.iterator().next());

        while (firstDate.isBefore(toLong)) {
            firstDate = firstDate.plusDays(1);
            if (!treeSet.contains(firstDate.getMillis())) {
                treeSet.add(firstDate.getMillis());
            }// w  ww  .  jav a2  s .  c  om
        }
    } else if (rollup.endsWith("h")) {
        DateTime firstDate = new DateTime(treeSet.iterator().next());

        while (firstDate.isBefore(toLong)) {
            firstDate = firstDate.plusHours(1);
            if (!treeSet.contains(firstDate.getMillis())) {
                treeSet.add(firstDate.getMillis());
            }
        }
    } else if (rollup.endsWith("m")) {
        DateTime firstDate = new DateTime(treeSet.iterator().next());

        while (firstDate.isBefore(toLong)) {
            firstDate = firstDate.plusMinutes(1);
            if (!treeSet.contains(firstDate.getMillis())) {
                treeSet.add(firstDate.getMillis());
            }
        }
    }
}

From source file:graph.inference.module.LaterThanWorker.java

License:Open Source License

private Interval parseDate(DAGNode date, DateTime now) {
    String dateStr = date.toString();
    if (dateStr.equals("Now") || dateStr.equals("Now-Generally"))
        return new Interval(now.getMillis(), now.getMillis() + 1);
    if (dateStr.equals("Today-Indexical"))
        return new Interval(now.dayOfYear().roundFloorCopy(), now.dayOfYear().roundCeilingCopy());
    if (dateStr.equals("Tomorrow-Indexical")) {
        return new Interval(now.plusDays(1).dayOfYear().roundFloorCopy(),
                now.plusDays(1).dayOfYear().roundCeilingCopy());
    }/*from   w  w  w. j a v a2s . c  o  m*/
    if (dateStr.equals("Yesterday-Indexical")) {
        return new Interval(now.minusDays(1).dayOfYear().roundFloorCopy(),
                now.minusDays(1).dayOfYear().roundCeilingCopy());
    }
    if (dateStr.equals("TheYear-Indexical")) {
        return new Interval(now.year().roundFloorCopy(), now.year().roundCeilingCopy());
    }

    // Parse the date from the DAGNode
    String parsePattern = null;
    for (int i = DATE_PARSE_INTERVALS.length - 1; i >= 0; i--) {
        StringBuilder newPattern = new StringBuilder("(" + DATE_PARSE_INTERVALS[i]);
        if (parsePattern != null)
            newPattern.append(" " + parsePattern);
        newPattern.append(")");
        parsePattern = newPattern.toString();

        DateTimeFormatter dtf = DateTimeFormat.forPattern(parsePattern);
        try {
            DateTime dateTime = dtf.parseDateTime(dateStr);
            if (dateTime != null) {
                switch (i) {
                case 0:
                    return new Interval(dateTime.getMillis(),
                            dateTime.plusSeconds(1).minusMillis(1).getMillis());
                case 1:
                    return new Interval(dateTime.getMillis(),
                            dateTime.plusMinutes(1).minusMillis(1).getMillis());
                case 2:
                    return new Interval(dateTime.getMillis(), dateTime.plusHours(1).minusMillis(1).getMillis());
                case 3:
                    return new Interval(dateTime.getMillis(), dateTime.plusDays(1).minusMillis(1).getMillis());
                case 4:
                    return new Interval(dateTime.getMillis(),
                            dateTime.plusMonths(1).minusMillis(1).getMillis());
                case 5:
                    return new Interval(dateTime.getMillis(), dateTime.plusYears(1).minusMillis(1).getMillis());
                }
            }
        } catch (Exception e) {
        }
    }
    return null;
}

From source file:influent.server.dataaccess.DataAccessHelper.java

License:MIT License

public static DateTime getExclusiveEndDate(FL_DateRange date) {

    if (date == null) {
        return null;
    }/*w w w. ja  v  a2  s .com*/

    DateTime d = new DateTime((long) date.getStartDate(), DateTimeZone.UTC);

    switch (date.getDurationPerBin().getInterval()) {
    case SECONDS:
        return d.plusSeconds(date.getNumBins().intValue());
    case HOURS:
        return d.plusHours(date.getNumBins().intValue());
    case DAYS:
        return d.plusDays(date.getNumBins().intValue());
    case WEEKS:
        return d.plusWeeks(date.getNumBins().intValue());
    case MONTHS:
        return d.plusMonths(date.getNumBins().intValue());
    case QUARTERS:
        return d.plusMonths(date.getNumBins().intValue() * 3);
    case YEARS:
        return d.plusYears(date.getNumBins().intValue());
    }

    return d;
}

From source file:io.renren.common.utils.DateUtils.java

License:Apache License

/**
 * ??/?//  w w  w. ja v  a 2  s . co m
 *
 * @param date 
 * @param hours ??
 * @return /???
 */
public static Date addDateHours(Date date, int hours) {
    DateTime dateTime = new DateTime(date);
    return dateTime.plusHours(hours).toDate();
}

From source file:io.spikex.core.helper.Variables.java

License:Apache License

public static DateTime createDateTimeNow(final String var) {

    DateTime dt;

    // #now/*from  w w w  .j  av  a2  s  .c o m*/
    // #now(UTC)
    // #now(UTC,0h,-10m,0s)
    // #now(0h,-10m,0s)
    // #now(30m)
    Matcher m = REGEXP_NOW.matcher(var);
    //
    // Timezone
    //
    String tz = null;
    boolean found = m.find();
    if (found) {
        tz = m.group(1);
    }
    //
    // Hours
    //
    int hours = 0;
    if (found) {
        String val = m.group(2);
        if (val != null) {
            hours = Integer.parseInt(val.substring(0, val.length() - 1));
        }
    }
    //
    // Minutes
    //
    int mins = 0;
    if (found) {
        String val = m.group(3);
        if (val != null) {
            mins = Integer.parseInt(val.substring(0, val.length() - 1));
        }
    }
    //
    // Seconds
    //
    int secs = 0;
    if (found) {
        String val = m.group(4);
        if (val != null) {
            secs = Integer.parseInt(val.substring(0, val.length() - 1));
        }
    }

    System.out.println("var: " + var + " tz: " + tz + " hours: " + hours + " mins: " + mins + " secs: " + secs);

    if (tz != null) {
        dt = new DateTime(DateTimeZone.forID(tz));
    } else {
        dt = new DateTime();
    }

    dt = dt.plusHours(hours);
    dt = dt.plusMinutes(mins);
    dt = dt.plusSeconds(secs);

    return dt;
}

From source file:kr.debop4j.timeperiod.timerange.DayTimeRange.java

License:Apache License

/** ?(Day) ? ? ?  ?   (<see cref="HourRange"/>)? ? . */
public List<HourRange> getHours() {
    DateTime startDay = getStartDayStart();

    List<HourRange> hours = Lists.newArrayListWithCapacity(dayCount * TimeSpec.HoursPerDay);
    for (int d = 0; d < dayCount; d++) {
        for (int h = 0; h < TimeSpec.HoursPerDay; h++) {
            HourRange hour = new HourRange(startDay.plusHours(d * TimeSpec.HoursPerDay + h), getTimeCalendar());
            hours.add(hour);/* w  w w . j a v a  2 s  .c om*/
        }
    }
    return hours;
}

From source file:kr.debop4j.timeperiod.timerange.HourRange.java

License:Apache License

/**
 * Add hours./*from  ww  w.j a v  a2s. c om*/
 *
 * @param hours the hours
 * @return the hour range
 */
public HourRange addHours(int hours) {
    DateTime startHour = Times.trimToHour(getStart(), getStartHourOfDay());
    return new HourRange(startHour.plusHours(hours), getTimeCalendar());
}