Example usage for org.joda.time DateTime hourOfDay

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

Introduction

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

Prototype

public Property hourOfDay() 

Source Link

Document

Get the hour of day field property which provides access to advanced functionality.

Usage

From source file:org.rhq.server.metrics.DateTimeService.java

License:Open Source License

public DateTime hour0() {
    DateTime rightNow = now();
    return rightNow.hourOfDay().roundFloorCopy()
            .minusHours(rightNow.hourOfDay().roundFloorCopy().hourOfDay().get());
}

From source file:org.shadowmask.core.mask.rules.generalizer.impl.TimestampGeneralizer.java

License:Apache License

@Override
public Long generalize(Long timestamp, int hierarchyLevel) {
    if (timestamp == null) {
        return null;
    }/*from  www .  ja v a 2 s .c  o  m*/

    if (hierarchyLevel > ROOT_HIERARCHY_LEVEL || hierarchyLevel < 0) {
        throw new MaskRuntimeException("Root hierarchy level of MobileGeneralizer is " + ROOT_HIERARCHY_LEVEL
                + ", invalid input hierarchy level[" + hierarchyLevel + "]");
    }

    if (hierarchyLevel == 0) {
        return timestamp;
    }

    try {
        DateTime dateTime = new DateTime(timestamp);
        switch (hierarchyLevel) {
        // mask ms.
        case 1:
            dateTime = new DateTime(dateTime.getYear(), dateTime.getMonthOfYear(), dateTime.getDayOfMonth(),
                    dateTime.getHourOfDay(), dateTime.getMinuteOfHour(), dateTime.getSecondOfMinute());
            break;
        // mask second.
        case 2:
            dateTime = new DateTime(dateTime.getYear(), dateTime.getMonthOfYear(), dateTime.getDayOfMonth(),
                    dateTime.getHourOfDay(), dateTime.getMinuteOfHour());
            break;
        // mask minute.
        case 3:
            dateTime = new DateTime(dateTime.getYear(), dateTime.getMonthOfYear(), dateTime.getDayOfMonth(),
                    dateTime.getHourOfDay(), dateTime.getMinuteOfHour());
            dateTime = dateTime.minuteOfHour().setCopy(0);
            break;
        // mask hour.
        case 4:
            dateTime = new DateTime(dateTime.getYear(), dateTime.getMonthOfYear(), dateTime.getDayOfMonth(),
                    dateTime.getHourOfDay(), dateTime.getMinuteOfHour());
            dateTime = dateTime.minuteOfHour().setCopy(0);
            dateTime = dateTime.hourOfDay().setCopy(0);
            break;
        // mask day.
        case 5:
            dateTime = new DateTime(dateTime.getYear(), dateTime.getMonthOfYear(), dateTime.getDayOfMonth(),
                    dateTime.getHourOfDay(), dateTime.getMinuteOfHour());
            dateTime = dateTime.minuteOfHour().setCopy(0);
            dateTime = dateTime.hourOfDay().setCopy(0);
            dateTime = dateTime.dayOfMonth().setCopy(1);
            break;
        // mask month.
        case 6:
            dateTime = new DateTime(dateTime.getYear(), dateTime.getMonthOfYear(), dateTime.getDayOfMonth(),
                    dateTime.getHourOfDay(), dateTime.getMinuteOfHour());
            dateTime = dateTime.minuteOfHour().setCopy(0);
            dateTime = dateTime.hourOfDay().setCopy(0);
            dateTime = dateTime.dayOfMonth().setCopy(1);
            dateTime = dateTime.monthOfYear().setCopy(1);
            break;
        // mask year.
        case 7:
            dateTime = new DateTime(dateTime.getYear(), dateTime.getMonthOfYear(), dateTime.getDayOfMonth(),
                    dateTime.getHourOfDay(), dateTime.getMinuteOfHour());
            dateTime = dateTime.minuteOfHour().setCopy(0);
            dateTime = dateTime.hourOfDay().setCopy(0);
            dateTime = dateTime.dayOfMonth().setCopy(1);
            dateTime = dateTime.monthOfYear().setCopy(1);
            dateTime = dateTime.year().setCopy(1901);
            break;
        }

        return dateTime.getMillis();
    } catch (Throwable e) {
        throw new MaskRuntimeException("Invalid timestamp to generalize:" + timestamp, e);
    }
}

From source file:rapternet.irc.bots.thetardis.listeners.TvSchedule.java

private DateTime roundDate(final DateTime dateTime, int minutes) {

    if (minutes < 1 || 60 % minutes != 0) {
        throw new IllegalArgumentException("minutes must be a factor of 60");
    }/*  ww w .  j av  a  2  s . co m*/

    final DateTime hour = dateTime.hourOfDay().roundFloorCopy();
    final long millisSinceHour = new Duration(hour, dateTime).getMillis();
    final int roundedMinutes = ((int) Math.round(millisSinceHour / 60000.0 / minutes)) * minutes;
    return hour.plusMinutes(roundedMinutes);
}

From source file:test.utilities.SemStoreLeakConverter.java

License:Apache License

void processLine(String line, PrintStream ps) throws Exception {

    if (line == null)
        return;/* w  w w  . ja  v  a2s. c o  m*/

    StringTokenizer tokens = new StringTokenizer(line);
    if (tokens.countTokens() == 0)
        return;

    String dstr = tokens.nextToken();
    String tstr = tokens.nextToken();

    String datestr = dstr + "T" + tstr;

    DateTime dtime = new DateTime(datestr);

    // peel off Info:
    String info = tokens.nextToken();
    // peel off [Event
    String event = tokens.nextToken();
    // grab hold of operation with trailing ]
    String operation = tokens.nextToken();
    int bracket = operation.indexOf(']');
    if (bracket > 0)
        operation = operation.substring(0, bracket);

    // type of TripleStore in hand
    String storeType = tokens.nextToken();

    // the operation again
    String op = tokens.nextToken();

    // the address
    String addrStr = tokens.nextToken();
    int eq = addrStr.indexOf('=');
    if (eq > 0)
        addrStr = addrStr.substring(eq + 1);

    String memsize = null;
    // if it's a created line, we might have a trailing , and a mem size out there
    if (op.equals("created:")) {
        int comma = addrStr.indexOf(',');
        if (comma > 0)
            addrStr = addrStr.substring(0, comma);
        try {
            memsize = tokens.nextToken();
            if (memsize != null) {
                eq = memsize.indexOf('=');
                if (eq > 0)
                    memsize = memsize.substring(eq + 1);
            }
        } catch (ArrayIndexOutOfBoundsException e) {
        }
    }

    int month = dtime.monthOfYear().get();
    int day = dtime.monthOfYear().get();
    int hour = dtime.hourOfDay().get();
    int minute = dtime.minuteOfHour().get();
    int seconds = dtime.secondOfMinute().get();
    int millis = dtime.millisOfSecond().get();

    // construct a key
    String subject = "tstore:" + dtime.year().getAsText() + (month < 10 ? "0" + month : month)
            + (day < 10 ? "0" + day : day) + (hour < 10 ? "0" + hour : hour)
            + (minute < 10 ? "0" + minute : minute) + (seconds < 10 ? "0" + seconds : seconds) + "."
            + (millis < 100 ? "0" : "") + (millis < 10 ? "0" + millis : millis) + "_" + operation;

    ps.println(subject + "\t" + "tstore:timestamp" + "\t\"" + dtime.toLocalDateTime() + "\"^^xsd:dateTime .");
    ps.println(subject + "\t" + "tstore:type" + "\t\"" + operation + "\" .");
    ps.println(subject + "\t" + "tstore:address" + "\t\"" + addrStr + "\" .");
    if (memsize != null)
        ps.println(subject + "\t" + "tstore:memsize" + "\t\"" + memsize + "\"^^xsd:integer .");
    ps.println("");

}

From source file:ums.GenerateTimetable.java

/**
 * Handles the HTTP <code>GET</code> method.
 *
 * @param request servlet request/*  w w  w. ja v a 2 s. co m*/
 * @param response servlet response
 * @throws ServletException if a servlet-specific error occurs
 * @throws IOException if an I/O error occurs
 */
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    //processRequest(request, response);
    response.setContentType("text/html");
    PrintWriter out = response.getWriter();
    Connection connection = null;
    Statement stmt = null;
    try {
        String queryString;
        Class.forName(JDBC_DRIVER);
        connection = DriverManager.getConnection(DB_URL, USER, PASS);
        System.out.println("Driver loaded");
        stmt = connection.createStatement();
        int totalRooms = 3;
        int room = 1;
        // double time = 9.15;
        // int dayCount = 0;
        //String days[] = {"Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"};
        String deletequeryString = "delete from courseschedule";
        ResultSet rset1 = stmt.executeQuery(deletequeryString);
        queryString = "select * from courses order by section asc";
        ResultSet rset = stmt.executeQuery(queryString);
        //rset.getMetaData().get
        DateTime startTime = new DateTime();
        startTime = startTime.dayOfWeek().setCopy(DateTimeConstants.MONDAY);
        startTime = startTime.hourOfDay().setCopy("9");
        startTime = startTime.minuteOfHour().setCopy("15");
        startTime = startTime.secondOfMinute().setCopy("0");

        DateTime endTime = new DateTime();
        endTime = endTime.dayOfWeek().setCopy(DateTimeConstants.MONDAY);
        endTime = endTime.hourOfDay().setCopy("21");
        endTime = endTime.minuteOfHour().setCopy("15");
        endTime = endTime.secondOfMinute().setCopy("0");

        DateTimeFormatter fmt = DateTimeFormat.forPattern("h:mm a");
        PreparedStatement pst = connection.prepareStatement(
                "insert into courseschedule(coursenum,section,day,time,location) values(?,?,?,?,?)");
        while (rset.next()) {
            int credit = rset.getInt("credit");
            String courseNum = rset.getString("coursenum");
            String section = rset.getString("section");

            if (room < totalRooms) {

                if (startTime.hourOfDay().addToCopy(credit).isAfter(endTime)) {
                    room++;
                    if (room == totalRooms) {
                        room = 1;
                        startTime = startTime.dayOfWeek().addToCopy(1);
                        endTime = endTime.dayOfWeek().addToCopy(1);
                    }
                    startTime = startTime.hourOfDay().setCopy("9");
                    startTime = startTime.minuteOfHour().setCopy("15");
                    startTime = startTime.secondOfMinute().setCopy("0");
                }
            }
            String location = "Room" + room;
            /* if (room < totalRooms) {
             if (time + credit > 21.15) {
             room++;
             if(room==totalRooms){
             room = 1;
             dayCount++;
             if(dayCount==7){
             dayCount = 0;
             }
             }
             time = 9.15;
             }
             }
             String location = "Room" + room;
                    
             String Time;
             if(time<12.15){
             Time = time + " AM";
             }else{
             Time = time + " PM";
             } */
            //stmt.executeUpdate("insert into courseschedule(coursenum,section,day,time,location) values('"+courseNum+"','"+section+"','"+days[dayCount]+"','"+time+"','"+location+"')");
            pst.setString(1, courseNum);
            pst.setString(2, section);
            pst.setString(3, startTime.dayOfWeek().getAsText());
            pst.setString(4, startTime.toString(fmt));
            pst.setString(5, location);
            pst.executeUpdate();
            startTime = startTime.hourOfDay().addToCopy(credit);
            //time = time + credit;
        }
        out.println("Inserted Successfully");
        RequestDispatcher dispatcher = getServletContext().getRequestDispatcher("/JSP/viewCourse.jsp");
        dispatcher.forward(request, response);
    } catch (ClassNotFoundException | SQLException ex) {
        Logger.getLogger(GenerateTimetable.class.getName()).log(Level.SEVERE, null, ex);
    } finally {
        try {
            stmt.close();
            connection.close();
        } catch (SQLException ex) {
            Logger.getLogger(GenerateTimetable.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
}

From source file:ums.GenerateTimetable.java

public static void main(String[] a) {
    DateTime startTime = new DateTime();
    startTime = startTime.dayOfWeek().setCopy(DateTimeConstants.MONDAY);
    startTime = startTime.hourOfDay().setCopy("9");
    startTime = startTime.minuteOfHour().setCopy("15");
    startTime = startTime.secondOfMinute().setCopy("0");
    DateTimeFormatter fmt = DateTimeFormat.forPattern("EEEE h:mm a");
    System.out.println(startTime.toString(fmt));

    startTime = startTime.dayOfWeek().addToCopy(1);

    System.out.println(startTime.toString(fmt));

    DateTime endTime = new DateTime();
    endTime = endTime.dayOfWeek().setCopy(DateTimeConstants.MONDAY);
    endTime = endTime.hourOfDay().setCopy("21");
    endTime = endTime.minuteOfHour().setCopy("15");
    endTime = endTime.secondOfMinute().setCopy("0");

    startTime.plusHours(3);//  w  w w.  j  a v  a 2s . co m

    if (startTime.equals(endTime)) {

    }

    System.out.println(startTime);
}