Example usage for org.joda.time DateMidnight DateMidnight

List of usage examples for org.joda.time DateMidnight DateMidnight

Introduction

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

Prototype

public DateMidnight() 

Source Link

Document

Constructs an instance set to the current system millisecond time using ISOChronology in the default time zone.

Usage

From source file:dk.teachus.frontend.pages.calendar.TeacherCalendarPage.java

License:Apache License

public TeacherCalendarPage() {
    this(new DateMidnight());
}

From source file:dk.teachus.frontend.pages.periods.PeriodPage.java

License:Apache License

private WebMarkupContainer generatePreview(final Period period) {
    IModel<DateMidnight> dateModel = new Model<DateMidnight>() {
        private static final long serialVersionUID = 1L;

        private DateMidnight date;

        {/*  w  ww . ja  v a2 s . co  m*/
            DateMidnight beginDate = period.getBeginDate();
            if (beginDate == null) {
                beginDate = new DateMidnight();
            }
            this.date = beginDate;
        }

        @Override
        public DateMidnight getObject() {
            return date;
        }

        @Override
        public void setObject(DateMidnight date) {
            this.date = date;
        }
    };

    IModel<Periods> periodsModel = new LoadableDetachableModel<Periods>() {
        private static final long serialVersionUID = 1L;

        @Override
        protected Periods load() {
            final Periods periods = new PeriodsImpl();
            final ArrayList<Period> periodList = new ArrayList<Period>();
            periodList.add(period);
            periods.setPeriods(periodList);
            return periods;
        }
    };

    PeriodsCalendarPanel periodsCalendarPanel = new PeriodsCalendarPanel("calendar", dateModel, periodsModel) {
        private static final long serialVersionUID = 1L;

        @Override
        protected boolean isTimeSlotBookable(TimeSlot<PeriodBookingTimeSlotPayload> timeSlot) {
            return false;
        }

        @Override
        protected Teacher getTeacher() {
            return TeachUsSession.get().getTeacher();
        }
    };
    periodsCalendarPanel.setOutputMarkupId(true);
    return periodsCalendarPanel;
}

From source file:dk.teachus.frontend.pages.stats.teacher.IncomePerMonthPage.java

License:Apache License

public IncomePerMonthPage(PageParameters pageParameters) {
    int year = pageParameters.get(0).toInt(new DateMidnight().getYear());

    add(new Label("perMonth", TeachUsSession.get().getString("IncomePerMonthPage.perMonth"))); //$NON-NLS-1$ //$NON-NLS-2$

    BookingDAO bookingDAO = TeachUsApplication.get().getBookingDAO();

    List<Integer> yearsWithPaidBookings = bookingDAO.getYearsWithBookings(getPerson());

    // If the latest booking is not in the selected year, then select the latest year with bookings
    if (yearsWithPaidBookings.size() > 0 && yearsWithPaidBookings.contains(year) == false) {
        year = 0;//from   www  .j  a v  a 2 s  . com
        for (Integer y : yearsWithPaidBookings) {
            if (y > year) {
                year = y;
            }
        }
    }

    Form<Void> form = new Form<Void>("form"); //$NON-NLS-1$
    add(form);
    final IModel<Integer> yearModel = new Model<Integer>(year);
    final DropDownChoice<Integer> years = new DropDownChoice<Integer>("years", yearModel, //$NON-NLS-1$
            yearsWithPaidBookings);
    years.add(new AjaxFormComponentUpdatingBehavior("onchange") { //$NON-NLS-1$
        private static final long serialVersionUID = 1L;

        @Override
        protected void onUpdate(AjaxRequestTarget target) {
            int year = (Integer) yearModel.getObject();
            PageParameters pageParameters = new PageParameters();
            pageParameters.set(0, year);
            getRequestCycle().setResponsePage(IncomePerMonthPage.class, pageParameters);
        }
    });
    form.add(years);

    DateMidnight fromDate = new DateMidnight(year, 1, 1);
    DateMidnight toDate = new DateMidnight(year, 12, 31);

    List<PupilBooking> paidBookings = bookingDAO.getPaidBookings(getPerson(), fromDate, toDate);

    // Get the unpaid bookings
    List<PupilBooking> allUnPaidBookings = bookingDAO.getUnPaidBookings(getPerson(), fromDate, toDate);

    // Extract the unpaid bookings which is before now
    List<PupilBooking> unPaidBookings = new ArrayList<PupilBooking>();
    List<PupilBooking> futureBookings = new ArrayList<PupilBooking>();
    DateTime now = new DateTime();
    for (PupilBooking booking : allUnPaidBookings) {
        if (now.isAfter(booking.getDate())) {
            unPaidBookings.add(booking);
        } else {
            futureBookings.add(booking);
        }
    }

    final List<MonthIncome> data = new ArrayList<MonthIncome>();

    for (PupilBooking booking : paidBookings) {
        MonthIncome monthIncome = getMonthIncome(data, booking);

        monthIncome.addPaid(booking.getPeriod().getPrice());
        monthIncome.addPaidLesson();
    }

    for (PupilBooking booking : unPaidBookings) {
        MonthIncome monthIncome = getMonthIncome(data, booking);

        monthIncome.addUnpaid(booking.getPeriod().getPrice());
        monthIncome.addUnpaidLesson();
    }

    for (PupilBooking booking : futureBookings) {
        MonthIncome monthIncome = getMonthIncome(data, booking);

        monthIncome.addFuture(booking.getPeriod().getPrice());
        monthIncome.addFutureLesson();
    }

    WebComponent chart = new WebComponent("chart") {
        private static final long serialVersionUID = 1L;

        @Override
        public void renderHead(IHeaderResponse response) {
            response.renderJavaScriptReference("https://www.google.com/jsapi");
            StringBuilder b = new StringBuilder();
            b.append("google.load('visualization', '1', {packages:['corechart']});");
            b.append("google.setOnLoadCallback(drawChart);");
            b.append("function drawChart() {");
            b.append("var data = google.visualization.arrayToDataTable([");
            b.append("['").append(TeachUsSession.get().getString("General.month")).append("', ");
            b.append("'").append(TeachUsSession.get().getString("General.paid")).append("', ");
            b.append("'").append(TeachUsSession.get().getString("General.unpaid")).append("', ");
            b.append("'").append(TeachUsSession.get().getString("IncomePerMonthPage.future")).append("'],");
            StringBuilder d = new StringBuilder();
            for (MonthIncome monthIncome : data) {
                if (d.length() > 0) {
                    d.append(",");
                }
                d.append("[");
                d.append("'").append(new MonthChoiceRenderer().getDisplayValue(monthIncome.getMonth()))
                        .append("', ");
                d.append(monthIncome.getPaid()).append(", ");
                d.append(monthIncome.getUnpaid()).append(", ");
                d.append(monthIncome.getFuture());
                d.append("]");
            }
            b.append(d);
            b.append("]);");

            b.append("var options = {");
            b.append("isStacked: true,");
            b.append("series: {0:{color:'#46a546'},1:{color:'#9d261d'},2:{color:'#049cdb'}},");
            b.append("vAxis: {format:'#,##0.00'},");
            b.append("};");

            b.append("var chart = new google.visualization.ColumnChart(document.getElementById('")
                    .append(getMarkupId()).append("'));");
            b.append("chart.draw(data, options);");
            b.append("}");
            response.renderJavaScript(b, "chart");
        }
    };
    chart.setOutputMarkupId(true);
    add(chart);

    // Add list of data in static form
    List<IColumn<MonthIncome>> columns = new ArrayList<IColumn<MonthIncome>>();
    columns.add(new RendererPropertyColumn<MonthIncome, Integer>(
            new Model<String>(TeachUsSession.get().getString("General.month")), "month", //$NON-NLS-1$//$NON-NLS-2$
            new MonthChoiceRenderer()));
    columns.add(new RendererPropertyColumn<MonthIncome, Object>(
            new Model<String>(TeachUsSession.get().getString("General.paid")), "paid", //$NON-NLS-1$//$NON-NLS-2$
            new CurrencyChoiceRenderer()));
    columns.add(new PropertyColumn<MonthIncome>(
            new Model<String>(TeachUsSession.get().getString("IncomePerMonthPage.paidBookings")), //$NON-NLS-1$
            "paidLessonCount")); //$NON-NLS-1$
    columns.add(new RendererPropertyColumn<MonthIncome, Object>(
            new Model<String>(TeachUsSession.get().getString("General.unpaid")), "unpaid", //$NON-NLS-1$//$NON-NLS-2$
            new CurrencyChoiceRenderer()));
    columns.add(new PropertyColumn<MonthIncome>(
            new Model<String>(TeachUsSession.get().getString("IncomePerMonthPage.unPaidBookings")), //$NON-NLS-1$
            "unpaidLessonCount")); //$NON-NLS-1$
    columns.add(new RendererPropertyColumn<MonthIncome, Object>(
            new Model<String>(TeachUsSession.get().getString("IncomePerMonthPage.future")), "future", //$NON-NLS-1$//$NON-NLS-2$
            new CurrencyChoiceRenderer()));
    columns.add(new PropertyColumn<MonthIncome>(
            new Model<String>(TeachUsSession.get().getString("IncomePerMonthPage.futureLessons")), //$NON-NLS-1$
            "futureLessonCount")); //$NON-NLS-1$
    columns.add(new RendererPropertyColumn<MonthIncome, Object>(
            new Model<String>(TeachUsSession.get().getString("General.total")), "total", //$NON-NLS-1$//$NON-NLS-2$
            new CurrencyChoiceRenderer()));
    columns.add(new PropertyColumn<MonthIncome>(
            new Model<String>(TeachUsSession.get().getString("IncomePerMonthPage.totalLessons")), //$NON-NLS-1$
            "totalLessonCount")); //$NON-NLS-1$

    add(new ListPanel<MonthIncome>("list", columns, data)); //$NON-NLS-1$
}

From source file:dk.teachus.frontend.utils.MonthChoiceRenderer.java

License:Apache License

@Override
public Object getDisplayValue(Integer monthIndex) {
    String display = "";

    if (monthIndex != null) {
        DateMidnight month = new DateMidnight().withMonthOfYear(monthIndex);
        display = Formatters.getFormatOnlyMonth().print(month);
    }// w  ww  .ja  v  a 2  s  .  com

    return display;
}

From source file:dk.teachus.utils.PeriodComparator.java

License:Apache License

private DateTime convertAndReset(LocalTime date) {
    DateMidnight now = new DateMidnight();
    DateTime dateTime = date.toDateTime(now);
    dateTime = dateTime.withSecondOfMinute(0);
    dateTime = dateTime.withMillisOfSecond(0);

    return dateTime;
}

From source file:eds.entity.file.SecaFileEntity.java

/** ============= Methods inherited from EDS ============================
@Override/*from www.j  av  a2s. co  m*/
        
public Object key() {
return this.getFILENAME();
}
        
@Override*/
public void randInit() {
    DateMidnight dm = new DateMidnight();
    LocalDate ld = new LocalDate();
    java.sql.Date sqlDate = new java.sql.Date(ld.toDate().getTime());
    int user = (int) (Math.random() * 12345);
    if (Math.random() > 0.5)
        this.setUPLOAD_STATUS(FILE_STATUS.COMPLETED);
    else
        this.setUPLOAD_STATUS(FILE_STATUS.INCOMPLETE);
    int filename = (user + 6) / 7;

    this.setFILENAME("File " + filename);
    this.setCREATED_BY("User " + user);
}

From source file:edu.wisc.hr.demo.RandomTimeSheetDao.java

License:Apache License

@Override
public List<TimeSheet> getTimeSheets(String emplId) {

    if (emplIdToListOfTimeSheets.containsKey(emplId)) {
        return emplIdToListOfTimeSheets.get(emplId);
    }/* ww w  .j  a  v a2s  .  c o m*/

    List<TimeSheet> timesheets = new LinkedList<TimeSheet>();

    Job primaryJob = this.contactInfoDao.getPersonalData(emplId).getPrimaryJob();

    int howManyTimeSheets = random.nextInt(20);

    for (int i = 0; i < howManyTimeSheets; i++) {
        TimeSheet timeSheet = new TimeSheet();

        int randomNumberOfDaysAgo = random.nextInt(1000);
        DateMidnight midnightToday = new DateMidnight();
        DateMidnight midnightAWhileAgo = midnightToday.minusDays(randomNumberOfDaysAgo);

        timeSheet.setDate(midnightAWhileAgo);
        timeSheet.setJob(primaryJob);
        timeSheet.setStatus("Status?");

        int hours = 20 + random.nextInt(30);
        int quarterHours = random.nextInt(4);

        double total = hours + (0.25 * quarterHours);

        timeSheet.setTotal(new BigDecimal(total));
        timeSheet.setType("Type?");

        timesheets.add(timeSheet);

    }

    this.emplIdToListOfTimeSheets.put(emplId, timesheets);

    return timesheets;
}

From source file:models.Propal.java

License:Open Source License

@PreUpdate
@PrePersist/*  w  w w. j a va 2 s . c om*/
private void calculateExpirationDate() {
    if (creationDate == null) {
        // Set the creation Date to today for existing propals in DB
        creationDate = new DateMidnight().toDate();
    }
    DateMidnight dt = new DateMidnight(creationDate);
    this.expirationDate = dt.plusDays(nbDaysOfValidity).toDate();
}

From source file:models.Propal.java

License:Open Source License

/**
 * Returns all Propals that have expired.
 *
 * @return a list of Propal.//from   ww  w .j  ava  2  s . c om
 */
public static List<Propal> findDeprecated() {
    List<Propal> deprecatedPropals = find("expirationDate < :pnow").bind("pnow", new DateMidnight().toDate())
            .fetch();
    return deprecatedPropals;
}

From source file:net.bobgardner.cash.App.java

License:Open Source License

private static void makeFakeData() {
    Category c0 = Category.newCategory("Name0", "Desc0");
    Category c1 = Category.newCategory("Name1", "Desc1");
    Account account = Account.newAccount(Cashbox.INSTANCE, "WF Checking", "Wells Fargo", "123456789",
            Account.Type.CHECKING, "");
    Transaction t = Transaction.newTransaction(account, new DateMidnight(), "Albertsons", "101");
    LineItem.newLineItem(t, BigDecimal.TEN, c0, "Line Item 0");
    LineItem.newLineItem(t, BigDecimal.TEN, c1, "Line Item 1");
    t = Transaction.newTransaction(account, new DateMidnight(), "Sams Club", "");
    LineItem.newLineItem(t, new BigDecimal("-10.00"), c1, "Line Item 0");
    Account.newAccount(Cashbox.INSTANCE, "WF Savings", "Wells Fargo", "234567891", Account.Type.SAVINGS, "");
}