Example usage for org.joda.time MutableDateTime getDayOfWeek

List of usage examples for org.joda.time MutableDateTime getDayOfWeek

Introduction

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

Prototype

public int getDayOfWeek() 

Source Link

Document

Get the day of week field value.

Usage

From source file:com.alliander.osgp.adapter.protocol.oslp.elster.application.mapping.OslpGetConfigurationResponseToConfigurationConverter.java

License:Open Source License

/**
 * Loop backwards through the days of the month until we find {@link day} of
 * the month. For example the last Sunday of the month March of this year.
 */// w w  w .  j a  va 2s  .  c  om
private MutableDateTime findLastDayOfOfMonth(final int day, final MutableDateTime x) {
    final int yodaTimeDay = day + 1;
    while (true) {
        if (yodaTimeDay == x.getDayOfWeek()) {
            break;
        } else {
            final int dayOfMonth = x.getDayOfMonth() - 1;
            x.set(DateTimeFieldType.dayOfMonth(), dayOfMonth);
        }
    }
    return x;
}

From source file:com.foundationdb.server.types.mcompat.mfuncs.MWeek.java

License:Open Source License

private static int getMode1346(MutableDateTime cal, int yr, int mo, int da, int firstDay, int lowestVal) {
    cal.setYear(yr);//from   w  ww  .j  a  v a  2 s  . c o  m
    cal.setMonthOfYear(1);
    cal.setDayOfMonth(1);

    int firstD = 1;

    while (cal.getDayOfWeek() != firstDay)
        cal.setDayOfMonth(++firstD);

    cal.setYear(yr);
    cal.setMonthOfYear(mo);
    cal.setDayOfMonth(da);

    int week = cal.getDayOfYear() - (firstD + 1); // Sun/Mon
    if (firstD < 4) {
        if (week < 0)
            return modes[lowestVal].getWeek(cal, yr - 1, 12, 31);
        else
            return week / 7 + 1;
    } else {
        if (week < 0)
            return 1;
        else
            return week / 7 + 2;
    }
}

From source file:com.foundationdb.server.types.mcompat.mfuncs.MWeek.java

License:Open Source License

private static int getMode0257(MutableDateTime cal, int yr, int mo, int da, int firstDay, int lowestVal) {
    cal.setYear(yr);/*from   ww w.  j  ava  2s  . co  m*/
    cal.setMonthOfYear(1);
    cal.setDayOfMonth(1);
    int firstD = 1;

    while (cal.getDayOfWeek() != firstDay)
        cal.setDayOfMonth(++firstD);

    cal.setYear(yr);
    cal.setMonthOfYear(mo);
    cal.setDayOfMonth(da);

    int dayOfYear = cal.getDayOfYear();

    if (dayOfYear < firstD)
        return modes[lowestVal].getWeek(cal, yr - 1, 12, 31);
    else
        return (dayOfYear - firstD) / 7 + 1;
}

From source file:com.foundationdb.server.types.mcompat.mfuncs.MYearWeek.java

License:Open Source License

private static int getMode1346(MutableDateTime cal, int yr, int mo, int da, int firstDay, int lowestVal) {
    cal.setYear(yr);//  w  ww.  j av  a  2  s .c  o m
    cal.setMonthOfYear(1);
    cal.setDayOfMonth(1);

    int firstD = 1;

    while (cal.getDayOfWeek() != firstDay)
        cal.setDayOfMonth(++firstD);

    cal.setYear(yr);
    cal.setMonthOfYear(mo);
    cal.setDayOfMonth(da);

    int week = cal.getDayOfYear() - (firstD + 1); // Sun/Mon
    if (firstD < 4) {
        if (week < 0)
            return modes[lowestVal].getYearWeek(cal, yr - 1, 12, 31);
        else
            return yr * 100 + week / 7 + 1;
    } else {
        if (week < 0)
            return yr * 100 + 1;
        else
            return yr * 100 + week / 7 + 2;
    }
}

From source file:com.foundationdb.server.types.mcompat.mfuncs.MYearWeek.java

License:Open Source License

private static int getMode0257(MutableDateTime cal, int yr, int mo, int da, int firstDay, int lowestVal) {
    cal.setYear(yr);//  ww w.  j  av  a  2  s  .  c om
    cal.setMonthOfYear(1);
    cal.setDayOfMonth(1);
    int firstD = 1;

    while (cal.getDayOfWeek() != firstDay)
        cal.setDayOfMonth(++firstD);

    cal.setYear(yr);
    cal.setMonthOfYear(mo);
    cal.setDayOfMonth(da);

    int dayOfYear = cal.getDayOfYear();

    if (dayOfYear < firstD)
        return modes[lowestVal].getYearWeek(cal, yr - 1, 12, 31);
    else
        return yr * 100 + (dayOfYear - firstD) / 7 + 1;
}

From source file:com.foundationdb.server.types.texpressions.DateTimeField.java

License:Open Source License

/**
 * to be used in X and x/*www. j  a v a2  s  . com*/
 * @param cal
 * @param yr
 * @param mo
 * @param da
 * @param firstDay: the first day of week
 * @return the year for this week, could be the same as yr or different
 *        , depending on the first day of year
 */
private static int getYear(MutableDateTime cal, int yr, int mo, int da, int firstDay) {
    if (mo > 1 || da > 7)
        return yr;

    cal.setYear(yr);
    cal.setMonthOfYear(1);
    cal.setDayOfMonth(1);
    int firstD = 1;

    while (cal.getDayOfWeek() != firstDay)
        cal.setDayOfMonth(++firstD);

    // reset cal
    cal.setYear(yr);
    cal.setMonthOfYear(mo);
    cal.setDayOfMonth(da);

    if (da < firstD)
        return yr - 1;
    else
        return yr;
}

From source file:com.foundationdb.server.types.texpressions.DateTimeField.java

License:Open Source License

/**
 * to be used in V, v, U and u//from www  . j a  va2s.c  o  m
 * @param cal
 * @param yr
 * @param mo
 * @param da
 * @param firstDay
 * @param lowestIs0: whether the lowest value could be zero or not
 * @return the week for this date, if the lowest value is not supposed to be zero, then it returns that
 *          the number of the last week in the previous year
 */
private static int getWeek(MutableDateTime cal, int yr, int mo, int da, int firstDay, boolean lowestIs0) {
    cal.setYear(yr);
    cal.setMonthOfYear(1);
    cal.setDayOfMonth(1);
    int firstD = 1;

    while (cal.getDayOfWeek() != firstDay)
        cal.setDayOfMonth(++firstD);

    cal.setYear(yr);
    cal.setMonthOfYear(mo);
    cal.setDayOfMonth(da);

    int dayOfYear = cal.getDayOfYear();
    int result;

    if (dayOfYear < firstD)
        result = (lowestIs0 ? 0 : getWeek(cal, yr - 1, 12, 31, firstDay, lowestIs0));
    else
        result = (dayOfYear - firstD) / 7 + 1;

    // reset cal
    cal.setYear(yr);
    cal.setMonthOfYear(mo);
    cal.setDayOfMonth(da);
    return result;
}

From source file:com.tmathmeyer.sentinel.ui.navigation.MiniMonth.java

License:Open Source License

public MiniMonth(DateTime time, final MiniCalendarHostIface mc, boolean monthOnly) {
    this.setLayout(new GridLayout(7, 7));
    MutableDateTime prevMonth = new MutableDateTime(time);
    prevMonth.setDayOfMonth(1);//from   w  w w  .  j av a  2s . c om
    prevMonth.addMonths(-1); // What is prevMonth for?
    String[] dayLabel = { "S", "M", "T", "W", "R", "F", "S" };

    MouseListener monthChanger = new MouseListener() {
        @Override
        public void mouseClicked(MouseEvent me) {
        }

        @Override
        public void mouseEntered(MouseEvent me) {
        }

        @Override
        public void mouseExited(MouseEvent me) {
        }

        @Override
        public void mousePressed(MouseEvent me) {
        }

        @Override
        public void mouseReleased(MouseEvent me) {
            DayLabel d = (DayLabel) (me.getSource());
            if (!(d instanceof DescriptiveDayLabel)) {
                mc.display(d.getMonth());
            }
        }
    };

    MutableDateTime referenceDay = new MutableDateTime(time);
    // reset to the first of the month at midnight, then find Sunday
    referenceDay.setDayOfMonth(1);
    referenceDay.setMillisOfDay(0);
    int first = referenceDay.getDayOfWeek();
    referenceDay.addDays(-first);
    boolean flipFlop = false;

    // add day labels
    for (int i = 0; i < 7; i++) {
        DayLabel day = new DescriptiveDayLabel(dayLabel[i], time);
        day.borderize((i % 7) == 0, i >= 5 * 7, (i % 7) == 6);
        add(day);
        day.addMouseListener(monthChanger);
    }

    // generate days, 6*7 covers all possible months, so we just loop
    // through and add each day
    for (int i = 0; i < (6 * 7); i++) {
        DayLabel day;
        if (monthOnly || MainPanel.getInstance().getView() == ViewSize.Month) {
            if (referenceDay.getDayOfMonth() == 1)
                flipFlop ^= true; // flops the flip flop flappity flip
        } else if (MainPanel.getInstance().getView() == ViewSize.Day)
            flipFlop = referenceDay.getDayOfYear() == time.getDayOfYear()
                    && referenceDay.getYear() == time.getYear();
        else if (MainPanel.getInstance().getView() == ViewSize.Week) {
            if (Months.getWeekStart(time).getMonthOfYear() == 12
                    && Months.getWeekStart(time).getDayOfMonth() >= 26) // Exception
                // case
                // for
                // weeks
                // between
                // years
                flipFlop = time.getMonthOfYear() == 12 ? i >= 35 : i <= 6;
            else
                flipFlop = referenceDay.getDayOfYear() >= Months.getWeekStart(time).getDayOfYear()
                        && referenceDay.getDayOfYear() <= Months.getWeekStart(time).getDayOfYear() + 6;
        }

        if (flipFlop)
            day = new ActiveDayLabel(referenceDay.toDateTime());
        else
            day = new InactiveDayLabel(referenceDay.toDateTime());

        day.borderize((i % 7) == 0, i >= 5 * 7, (i % 7) == 6);
        add(day);
        day.addMouseListener(monthChanger);
        referenceDay.addDays(1); // go to next day
    }
}

From source file:com.tmathmeyer.sentinel.ui.views.month.MonthCalendar.java

License:Open Source License

/**
 * //from   w  w w . jav  a 2 s.  c o m
 * @param fom the mutable date time
 */
public void generateHeaders(MutableDateTime fom) {
    // Set up label for month title
    monthLabel.setHorizontalAlignment(JLabel.CENTER);
    monthLabel.setFont(new java.awt.Font("DejaVu Sans", Font.BOLD, 25));

    // Set up the container title panel (only holds monthLabel for now)
    calendarTitlePanel.setLayout(new BorderLayout());
    calendarTitlePanel.add(monthLabel, BorderLayout.CENTER);

    // layout code
    mainCalendarView.setBackground(Colors.TABLE_BACKGROUND);
    mainCalendarView.setLayout(new BorderLayout());
    top.setLayout(new GridLayout(1, 7));

    mainCalendarView.add(top, BorderLayout.NORTH);
    mainCalendarView.add(inside, BorderLayout.CENTER);

    this.add(mainCalendarView, BorderLayout.CENTER);
    this.add(calendarTitlePanel, BorderLayout.NORTH);
    // end layout code

    fom.setDayOfMonth(1);
    fom.setMillisOfDay(0);
    int first = (fom.getDayOfWeek() % 7);
    fom.addDays(-first);

    // generate days on top
    for (int i = 0; i < 7; i++) {
        JLabel jl = new JLabel(fom.dayOfWeek().getAsText());
        jl.setHorizontalAlignment(SwingConstants.CENTER);
        fom.addDays(1);
        top.add(jl);
    }
}

From source file:com.tmathmeyer.sentinel.ui.views.month.MonthCalendar.java

License:Open Source License

/**
 * Fill calendar with month in referenceDay
 * /*  www  . j  a v a 2  s. co m*/
 * @param referenceDay what month should we display
 */
protected void generateDays(MutableDateTime referenceDay) {
    // reset to the first of the month at midnight, then find Sunday
    referenceDay.setDayOfMonth(1);
    referenceDay.setMillisOfDay(0);
    int first = (referenceDay.getDayOfWeek() % 7);
    int daysInView = first + referenceDay.dayOfMonth().getMaximumValue();
    int weeks = (int) Math.ceil(daysInView / 7.0);

    inside.setLayout(new java.awt.GridLayout(weeks, 7));
    referenceDay.addDays(-first);

    firstOnMonth = new DateTime(referenceDay);

    // remove all old days
    inside.removeAll();

    DateTime from = referenceDay.toDateTime();

    // generate days, weeks*7 covers all possible months, so we just loop
    // through and add each day
    for (int i = 0; i < (weeks * 7); i++) {
        MonthDay md = new MonthDay(referenceDay.toDateTime(), getMarker(referenceDay), this);
        inside.add(md);
        md.reBorder(i < 7, (i % 7) == 0, i >= (weeks - 1) * 7);
        this.days.put(referenceDay.getDayOfYear(), md);
        referenceDay.addDays(1); // go to next day
    }

    referenceDay.addDays(-1);// go back one to counteract last add one

    lastOnMonth = new DateTime(referenceDay);
    setDisplayables(getVisibleItems(from, referenceDay.toDateTime()));

    monthLabel.setText(this.getTime().toString(Months.monthLblFormat));

    // notify mini-calendar to change
    mainPanel.miniMove(time);

    // repaint when changed
    mainPanel.revalidate();
}