Example usage for org.joda.time DateTime dayOfWeek

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

Introduction

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

Prototype

public Property dayOfWeek() 

Source Link

Document

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

Usage

From source file:org.sonar.plugins.scmstats.measures.CommitsPerWeekDayMeasure.java

License:Open Source License

@Override
protected void init() {
    for (int i = 1; i <= 7; i++) {
        DateTime dt = new DateTime(2012, 1, i, 0, 0);
        getDataMap().put(dt.dayOfWeek().getAsString(), 0);
    }/* w  w w .j a va  2  s. c  o  m*/
}

From source file:org.thymeleaf.stripes.expression.JodaDates.java

License:Apache License

/**
 * dayOfWeek methods/*ww  w  .  j  av  a  2 s.c o  m*/
 * Defaults to Long Style
 */
public String dayOfWeekName(final DateTime target) {
    if (target == null)
        return null;
    return target.dayOfWeek().getAsText(locale);
}

From source file:org.thymeleaf.stripes.expression.JodaDates.java

License:Apache License

public String dayOfWeekNameShort(final DateTime target) {
    if (target == null)
        return null;
    return target.dayOfWeek().getAsShortText(locale);
}

From source file:se.frikod.payday.Holidays.java

License:Open Source License

boolean isHoliday(DateTime date) {

    return (weekend.contains(date.dayOfWeek().get()) || holidays.containsKey(date));
}

From source file:ums.GenerateTimetable.java

/**
 * Handles the HTTP <code>GET</code> method.
 *
 * @param request servlet request// ww  w  .  j a  va2s.c om
 * @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);//from w w w .j av  a2s  .c  om

    if (startTime.equals(endTime)) {

    }

    System.out.println(startTime);
}

From source file:updaters.FeedStatsCalculator.java

License:Open Source License

/**
 * Apply not just the feed stats, but also the 
 *//*from   w w w.  j a v a  2  s. c  o m*/

private void calculateStartAndEnd() throws Exception {
    // First, read feed_info.txt
    // TODO is 1 ever not the correct value?
    FeedInfo feedInfo = store.getFeedInfoForId(1);
    if (feedInfo != null) {
        ServiceDate d;
        d = feedInfo.getStartDate();
        if (d != null) {
            Calendar c = d.getAsCalendar(timezone);
            // move to GTFS noon, which will always be during the day. This accounts for both
            // multitimezone feeds and for daylight savings time 
            c.add(Calendar.HOUR_OF_DAY, 12);
            startDate = c.getTime();
        }

        d = feedInfo.getEndDate();
        if (d != null) {
            Calendar c = d.getAsCalendar(timezone);
            c.add(Calendar.HOUR_OF_DAY, 12);
            endDate = c.getTime();
        }
    }

    // we have an authoritative answer
    if (startDate != null && endDate != null)
        return;

    // let OBA deal with the complexities of interactions between
    // calendar.txt and
    // calendar_dates.txt
    // This code is lifted and slightly modified from
    // https://github.com/demory/otp_gtfs/blob/master/java/gtfsmetrics/src/main/java/org/openplans/gtfsmetrics/CalendarStatus.java
    Map<AgencyAndId, Set<ServiceDate>> addExceptions = new HashMap<AgencyAndId, Set<ServiceDate>>();
    Map<AgencyAndId, Set<String>> removeExceptions = new HashMap<AgencyAndId, Set<String>>();
    for (ServiceCalendarDate date : store.getAllCalendarDates()) {
        if (date.getExceptionType() == ServiceCalendarDate.EXCEPTION_TYPE_ADD) {
            Set<ServiceDate> dateSet = addExceptions.get(date.getServiceId());
            if (dateSet == null) {
                dateSet = new HashSet<ServiceDate>();
                addExceptions.put(date.getServiceId(), dateSet);
            }
            dateSet.add(date.getDate());
        } else if (date.getExceptionType() == ServiceCalendarDate.EXCEPTION_TYPE_REMOVE) {
            Set<String> dateSet = removeExceptions.get(date.getServiceId());
            if (dateSet == null) {
                dateSet = new HashSet<String>();
                removeExceptions.put(date.getServiceId(), dateSet);
            }
            dateSet.add(constructMDYString(date.getDate()));
        }
    }

    DateTime latestEnd = new DateTime(0);
    DateTime earliestStart = null;

    for (ServiceCalendar svcCal : store.getAllCalendars()) {

        Calendar c;
        c = svcCal.getStartDate().getAsCalendar(timezone);
        c.add(Calendar.HOUR_OF_DAY, 12);
        DateTime start = new DateTime(c.getTime());

        c = svcCal.getEndDate().getAsCalendar(timezone);
        c.add(Calendar.HOUR_OF_DAY, 12);
        DateTime end = new DateTime(c.getTime());

        int totalDays = Days.daysBetween(start, end).getDays();
        for (int d = 0; d < totalDays; d++) {
            int gd = getDay(svcCal, end.dayOfWeek().get());// dateCal.get(Calendar.DAY_OF_WEEK));
            boolean removeException = false;
            Set<String> dateSet = removeExceptions.get(svcCal.getServiceId());
            if (dateSet != null) {
                removeException = dateSet.contains(constructMDYString(end));
            }
            if (gd == 1 && !removeException)
                break;
            end = end.minusDays(1);
        }
        if (end.isAfter(latestEnd))
            latestEnd = end;

        totalDays = Days.daysBetween(start, end).getDays();
        for (int d = 0; d < totalDays; d++) {
            int gd = getDay(svcCal, start.dayOfWeek().get());// dateCal.get(Calendar.DAY_OF_WEEK));
            boolean removeException = false;
            Set<String> dateSet = removeExceptions.get(svcCal.getServiceId());
            if (dateSet != null) {
                removeException = dateSet.contains(constructMDYString(start));
            }
            if (gd == 1 && !removeException)
                break;
            start = start.plusDays(1);
        }
        if (earliestStart == null || start.isBefore(earliestStart))
            earliestStart = start;

    }

    // now, expand based on calendar_dates.txt
    for (Set<ServiceDate> dateSet : addExceptions.values()) {
        for (ServiceDate sd : dateSet) {
            DateTime dt = new DateTime(sd.getAsDate(timezone).getTime());
            if (dt.isAfter(latestEnd))
                latestEnd = dt;
            if (dt.isBefore(earliestStart))
                earliestStart = dt;
        }
    }

    this.startDate = earliestStart.toDate();
    this.endDate = latestEnd.toDate();
}