Example usage for org.joda.time DateTime minusHours

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

Introduction

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

Prototype

public DateTime minusHours(int hours) 

Source Link

Document

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

Usage

From source file:gobblin.source.extractor.utils.Utils.java

License:Apache License

/**
 * Helper method for getting a value containing CURRENTDAY-1 or CURRENTHOUR-1 in the form yyyyMMddHHmmss
 * @param value/*from ww w  .  ja  v a 2 s  .co m*/
 * @param timezone
 * @return
 */
public static long getLongWithCurrentDate(String value, String timezone) {
    if (Strings.isNullOrEmpty(value)) {
        return 0;
    }

    DateTime time = getCurrentTime(timezone);
    DateTimeFormatter dtFormatter = DateTimeFormat.forPattern(CURRENT_DATE_FORMAT).withZone(time.getZone());
    if (value.toUpperCase().startsWith(CURRENT_DAY)) {
        return Long.parseLong(
                dtFormatter.print(time.minusDays(Integer.parseInt(value.substring(CURRENT_DAY.length() + 1)))));
    }
    if (value.toUpperCase().startsWith(CURRENT_HOUR)) {
        return Long.parseLong(dtFormatter
                .print(time.minusHours(Integer.parseInt(value.substring(CURRENT_HOUR.length() + 1)))));
    }
    return Long.parseLong(value);
}

From source file:google.registry.flows.domain.DomainFlowUtils.java

License:Open Source License

/** Validate the notice from a launch create extension, allowing null as a valid notice. */
static void validateLaunchCreateNotice(@Nullable LaunchNotice notice, String domainLabel, boolean isSuperuser,
        DateTime now) throws EppException {
    if (notice == null) {
        return;// w  w w  .  j  a va2  s  . co  m
    }
    if (!notice.getNoticeId().getValidatorId().equals("tmch")) {
        throw new InvalidTrademarkValidatorException();
    }
    // Superuser can force domain creations regardless of the current date.
    if (!isSuperuser) {
        if (notice.getExpirationTime().isBefore(now)) {
            throw new ExpiredClaimException();
        }
        // An acceptance within the past 48 hours is mandated by the TMCH Functional Spec.
        if (notice.getAcceptedTime().isBefore(now.minusHours(48))) {
            throw new AcceptedTooLongAgoException();
        }
    }
    try {
        notice.validate(domainLabel);
    } catch (IllegalArgumentException e) {
        throw new MalformedTcnIdException();
    } catch (InvalidChecksumException e) {
        throw new InvalidTcnIdChecksumException();
    }
}

From source file:io.manasobi.license.LicenseController.java

private String convertISODateToDate(Date isoDate) {

    DateTime dateTime = new DateTime(isoDate);

    String simpleDate = DateUtils.convertDateToString(dateTime.minusHours(9).toDate(),
            "yyyy-MM-dd'T'HH:mm:ss.SSS'Z");

    simpleDate = StringUtils.replace(simpleDate, "T", " ");
    simpleDate = StringUtils.remove(simpleDate, "Z");

    return StringUtils.substring(simpleDate, 0, 19);
}

From source file:kr.debop4j.timeperiod.tools.Times.java

License:Apache License

/**  ? (Hour)  . */
public static List<ITimePeriod> foreachHours(ITimePeriod period) {
    shouldNotBeNull(period, "period");

    if (isTraceEnabled)
        log.trace("[{}]?  (Hour)  ...", period);

    List<ITimePeriod> hours = Lists.newArrayList();
    if (period.isAnytime())
        return hours;

    assertHasPeriod(period);/*  w w  w  .  j  av  a 2 s .c o m*/

    if (Times.isSameHour(period.getStart(), period.getEnd())) {
        hours.add(new TimeRange(period));
        return hours;
    }

    hours.add(new TimeRange(period.getStart(), Times.endTimeOfHour(period.getStart())));

    DateTime endHour = period.getEnd();
    DateTime current = Times.trimToHour(period.getStart(), period.getStart().getHourOfDay() + 1);
    ITimeCalendar calendar = TimeCalendar.getDefault();

    DateTime maxHour = endHour.minusHours(1);
    while (current.compareTo(maxHour) <= 0) {
        hours.add(Times.getHourRange(current, calendar));
        current = current.plusHours(1);
    }

    if (endHour.minusHours(endHour.getHourOfDay()).getMillisOfDay() > 0) {
        hours.add(new TimeRange(Times.startTimeOfHour(endHour), endHour));
    }

    return hours;
}

From source file:metadata.etl.dataset.druid.DruidMetadataExtractor.java

License:Open Source License

public JSONArray getSegmentMetadata(String datasource, String maxTime, String minTime) throws Exception {
    log.info("Extract metadata of segment from " + maxTime + " to " + minTime);
    DateTime max_datetime = DATETIME_FORMAT.parseDateTime(maxTime);
    String interval = DATETIME_FORMAT.print(max_datetime.minusHours(1)) + "/" + maxTime;
    String query = SEGMENT_QUERY.replace("$DATASOURCE", datasource).replace("$INTERVAL", interval);
    URL url = new URL(druid_host);
    HttpURLConnection con = (HttpURLConnection) url.openConnection();
    con.setConnectTimeout(TIMEOUT);
    con.setRequestMethod("POST");
    con.setDoOutput(true);/* ww  w .  j a  va2s  . com*/
    con.setRequestProperty("Content-Type", "application/json");
    DataOutputStream out = new DataOutputStream(con.getOutputStream());
    out.writeBytes(query);
    out.flush();
    out.close();
    int response_code = con.getResponseCode();

    if (response_code == 200) {
        BufferedReader br = new BufferedReader(new InputStreamReader(con.getInputStream()));
        String line = "";
        StringBuffer response = new StringBuffer();
        while ((line = br.readLine()) != null) {
            response.append(line);
        }
        br.close();
        con.disconnect();
        JSONArray seg_metadata = new JSONArray(response.toString());
        if (seg_metadata.length() > 0) {
            return seg_metadata;
        } else {
            log.info("No Segment Metadata for Data Source: " + datasource);
            return null;
        }
    } else {
        con.disconnect();
        throw new Exception("Fail to get response from " + druid_host + ", Response Code: " + response_code);
    }
}

From source file:net.solarnetwork.central.dras.dao.ibatis.test.AbstractIbatisDaoTestSupport.java

License:Open Source License

/**
 * Insert a test event into the solardras.event table.
 *///from   www.ja  va 2 s .  c om
protected void setupTestEvent(Long eventId, Long programId) {
    DateTime eventDate = new DateTime(TEST_PROGRAM_DATE);
    simpleJdbcTemplate.update(
            "insert into solardras.program_event (id,creator,pro_id,notif_date,start_date,end_date,test) "
                    + "values (?,?,?,?,?,?,?)",
            eventId, TEST_USER_ID, programId, new java.sql.Timestamp(eventDate.minusHours(2).getMillis()),
            new java.sql.Timestamp(eventDate.getMillis()),
            new java.sql.Timestamp(eventDate.plusHours(1).getMillis()), Boolean.TRUE);
}

From source file:net.sourceforge.fenixedu.domain.WrittenEvaluation.java

License:Open Source License

protected List<EvaluationEventBean> getAllEvents(String description, Registration registration) {
    List<EvaluationEventBean> result = new ArrayList<EvaluationEventBean>();
    String url = CoreConfiguration.getConfiguration().applicationUrl();

    Set<ExecutionCourse> executionCourses = new HashSet<ExecutionCourse>();
    executionCourses.addAll(this.getAttendingExecutionCoursesFor(registration));

    if (this.getEnrollmentBeginDayDateYearMonthDay() != null) {
        DateTime enrollmentBegin = convertTimes(this.getEnrollmentBeginDayDateYearMonthDay(),
                this.getEnrollmentBeginTimeDateHourMinuteSecond());
        DateTime enrollmentEnd = convertTimes(this.getEnrollmentEndDayDateYearMonthDay(),
                this.getEnrollmentEndTimeDateHourMinuteSecond());

        result.add(new EvaluationEventBean("Inicio das inscries para " + description, enrollmentBegin,
                enrollmentBegin.plusHours(1), false, null, url + "/login", null, executionCourses));

        result.add(/*w  w  w .  j  ava2s  .  com*/
                new EvaluationEventBean("Fim das inscries para " + description, enrollmentEnd.minusHours(1),
                        enrollmentEnd, false, null, url + "/login", null, executionCourses));
    }

    Set<Space> rooms = new HashSet<>();

    if (registration.getRoomFor(this) != null) {
        rooms.add(registration.getRoomFor(this));
    } else {
        for (WrittenEvaluationSpaceOccupation weSpaceOcupation : this
                .getWrittenEvaluationSpaceOccupationsSet()) {
            rooms.add(weSpaceOcupation.getRoom());
        }
    }

    result.add(new EvaluationEventBean(description, this.getBeginningDateTime(), this.getEndDateTime(), false,
            rooms, url + executionCourses.iterator().next().getSite().getReversePath(), null,
            executionCourses));

    return result;
}

From source file:net.sourceforge.fenixedu.presentationTier.Action.messaging.AnnouncementsStartPageHandler.java

License:Open Source License

private DateTime getStartDate(HttpServletRequest request) {

    final String selectedTimeSpanString = request.getParameter("recentBoardsTimeSpanSelection");
    final RecentBoardsTimeSpanSelection selectedTimeSpan = (selectedTimeSpanString != null)
            ? RecentBoardsTimeSpanSelection.valueOf(selectedTimeSpanString)
            : RecentBoardsTimeSpanSelection.TS_LAST_WEEK;

    final DateTime now = new DateTime();
    DateTime startDate = null;/* www . ja  v a2  s. com*/

    switch (selectedTimeSpan) {
    case TS_ALL_ACTIVE:
        break;
    case TS_LAST_WEEK:
        startDate = now.minusDays(7);
        break;
    case TS_ONE_MONTH:
        startDate = now.minusDays(30);
        break;
    case TS_TWO_MONTHS:
        startDate = now.minusDays(60);
        break;
    case TS_TODAY:
        startDate = now.minusHours(now.hourOfDay().get());
        startDate = startDate.minusMinutes(now.minuteOfHour().get());
        startDate = startDate.minusSeconds(now.secondOfMinute().get());
        break;
    case TS_TWO_WEEKS:
        startDate = now.minusDays(15);
        break;
    case TS_YESTERDAY:
        startDate = now.minusDays(1);
        break;
    }
    return startDate;
}

From source file:niche.newres.timedevents2owl.randomizer.TimedEvents2OWLRandomizer.java

public static DateTime minusRandomHours(DateTime dateTime, int minRange, int maxRange) {
    int randomHours = TimedEvents2OWLRandomizer.randInt(minRange, maxRange);

    return dateTime.minusHours(randomHours);
}

From source file:niche.newres.timedevents2owl.randomizer.TimedEvents2OWLRandomizer.java

public static DateTime shiftToPreviousDayTimeDateTime(DateTime dateTime) {
    //int currentHours = dateTime.getHourOfDay();
    if (dateTime.getHourOfDay() > 8 && dateTime.getHourOfDay() < 22) {
        return dateTime;
    } else {/*w w w.ja  v  a 2 s .  c om*/
        return dateTime.minusHours(11);

    }
}