Java Code Examples for org.joda.time.MutableDateTime#setYear()

The following examples show how to use org.joda.time.MutableDateTime#setYear() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MYearWeek.java    From sql-layer with GNU Affero General Public License v3.0 6 votes vote down vote up
private static int getMode0257(MutableDateTime cal, int yr, int mo, int da, int firstDay, int lowestVal)
{
    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();

    if (dayOfYear < firstD) return modes[lowestVal].getYearWeek(cal, yr - 1, 12, 31);
    else return yr * 100 + (dayOfYear - firstD) / 7 +1;
}
 
Example 2
Source File: MWeek.java    From sql-layer with GNU Affero General Public License v3.0 6 votes vote down vote up
private static int getMode0257(MutableDateTime cal, int yr, int mo, int da, int firstDay, int lowestVal)
{
    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(); 

    if (dayOfYear < firstD) return modes[lowestVal].getWeek(cal, yr-1, 12, 31);
    else return (dayOfYear - firstD) / 7 +1;
}
 
Example 3
Source File: XMLGregorianCalendarToDateTimeConverter.java    From components with Apache License 2.0 6 votes vote down vote up
@Override
public Object convertToAvro(XMLGregorianCalendar xts) {
    if (xts == null) {
        return null;
    }

    MutableDateTime dateTime = new MutableDateTime();
    try {
        dateTime.setYear(xts.getYear());
        dateTime.setMonthOfYear(xts.getMonth());
        dateTime.setDayOfMonth(xts.getDay());
        dateTime.setHourOfDay(xts.getHour());
        dateTime.setMinuteOfHour(xts.getMinute());
        dateTime.setSecondOfMinute(xts.getSecond());
        dateTime.setMillisOfSecond(xts.getMillisecond());

        DateTimeZone tz = DateTimeZone.forOffsetMillis(xts.getTimezone() * 60000);
        if (tz != null) {
            dateTime.setZoneRetainFields(tz);
        }

        return Long.valueOf(dateTime.getMillis());
    } catch (IllegalArgumentException e) {
        throw new ComponentException(e);
    }
}
 
Example 4
Source File: MYearWeek.java    From sql-layer with GNU Affero General Public License v3.0 5 votes vote down vote up
private static int getMode1346(MutableDateTime cal, int yr, int mo, int da, int firstDay, int lowestVal)
{
    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 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;
    }
}
 
Example 5
Source File: MWeek.java    From sql-layer with GNU Affero General Public License v3.0 5 votes vote down vote up
private static int getMode1346(MutableDateTime cal, int yr, int mo, int da, int firstDay, int lowestVal)
{
    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 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;
    }
}
 
Example 6
Source File: DateTimePerformance.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
private void checkJodaSetYear() {
    int COUNT = COUNT_FAST;
    // Is it fair to use only MutableDateTime here? You decide.
    MutableDateTime dt = new MutableDateTime(GJChronology.getInstance());
    for (int i = 0; i < AVERAGE; i++) {
        start("Joda", "setYear");
        for (int j = 0; j < COUNT; j++) {
            dt.setYear(1972);
            if (dt == null) {System.out.println("Anti optimise");}
        }
        end(COUNT);
    }
}
 
Example 7
Source File: DateTimePerformance.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
private void checkJISOSetYear() {
    int COUNT = COUNT_FAST;
    // Is it fair to use only MutableDateTime here? You decide.
    MutableDateTime dt = new MutableDateTime();
    for (int i = 0; i < AVERAGE; i++) {
        start("JISO", "setYear");
        for (int j = 0; j < COUNT; j++) {
            dt.setYear(1972);
            if (dt == null) {System.out.println("Anti optimise");}
        }
        end(COUNT);
    }
}
 
Example 8
Source File: DateTimePerformance.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
private void checkJodaSetYear() {
    int COUNT = COUNT_FAST;
    // Is it fair to use only MutableDateTime here? You decide.
    MutableDateTime dt = new MutableDateTime(GJChronology.getInstance());
    for (int i = 0; i < AVERAGE; i++) {
        start("Joda", "setYear");
        for (int j = 0; j < COUNT; j++) {
            dt.setYear(1972);
            if (dt == null) {System.out.println("Anti optimise");}
        }
        end(COUNT);
    }
}
 
Example 9
Source File: DateTimePerformance.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
private void checkJISOSetYear() {
    int COUNT = COUNT_FAST;
    // Is it fair to use only MutableDateTime here? You decide.
    MutableDateTime dt = new MutableDateTime();
    for (int i = 0; i < AVERAGE; i++) {
        start("JISO", "setYear");
        for (int j = 0; j < COUNT; j++) {
            dt.setYear(1972);
            if (dt == null) {System.out.println("Anti optimise");}
        }
        end(COUNT);
    }
}