Example usage for java.util Calendar DECEMBER

List of usage examples for java.util Calendar DECEMBER

Introduction

In this page you can find the example usage for java.util Calendar DECEMBER.

Prototype

int DECEMBER

To view the source code for java.util Calendar DECEMBER.

Click Source Link

Document

Value of the #MONTH field indicating the twelfth month of the year in the Gregorian and Julian calendars.

Usage

From source file:com.mycompany.CRMFly.serviceLayer.ProductsServiceImpl.java

@Transactional
public Map<Date, Double> getSumsFotDates(Products product) {
    Long id = product.getId();// w w w  .j a v  a  2 s. c  om

    Calendar calendar = new GregorianCalendar();
    Integer monthDifference = 0;
    if (calendar.get(Calendar.MONTH) == Calendar.JANUARY || calendar.get(Calendar.MONTH) == Calendar.APRIL
            || calendar.get(Calendar.MONTH) == Calendar.JULY
            || calendar.get(Calendar.MONTH) == Calendar.OCTOBER) {
        monthDifference = 0;
    } else if (calendar.get(Calendar.MONTH) == Calendar.FEBRUARY || calendar.get(Calendar.MONTH) == Calendar.MAY
            || calendar.get(Calendar.MONTH) == Calendar.AUGUST
            || calendar.get(Calendar.MONTH) == Calendar.NOVEMBER) {
        monthDifference = -1;
    } else if (calendar.get(Calendar.MONTH) == Calendar.MARCH || calendar.get(Calendar.MONTH) == Calendar.JUNE
            || calendar.get(Calendar.MONTH) == Calendar.SEPTEMBER
            || calendar.get(Calendar.MONTH) == Calendar.DECEMBER)
        monthDifference = -2;
    Integer dayDifference = -calendar.get(Calendar.DAY_OF_MONTH);
    calendar.add(Calendar.MONTH, monthDifference);
    calendar.add(Calendar.DAY_OF_MONTH, dayDifference - 1);

    Date beginningOfQuarter = calendar.getTime();
    Double thisQuarterSum = 0.0;
    calendar.add(Calendar.MONTH, -3);
    Date QuarterBackOne = calendar.getTime();
    Double QuarterBackOneSum = 0.0;
    calendar.add(Calendar.MONTH, -3);
    Date QuarterBackTwo = calendar.getTime();
    Double QuarterBackTwoSum = 0.0;
    calendar.add(Calendar.MONTH, -3);
    Date QuarterBackThree = calendar.getTime();
    Double QuarterBackThreeSum = 0.0;

    List<PositionsInContract> positions = productsDAO.getContractPositionsForProduct(id);
    HashMap<Date, Double> sums = new HashMap<Date, Double>();
    for (PositionsInContract position : positions) {
        Long posID = position.getId();
        Contracts contract = productsDAO.getContractForPosition(posID);
        Date date = contract.getBegin_date();
        if (date.after(beginningOfQuarter))
            thisQuarterSum += position.getPrice() * position.getQuantity();
        else if (date.after(QuarterBackOne))
            QuarterBackOneSum += position.getPrice() * position.getQuantity();
        else if (date.after(QuarterBackTwo))
            QuarterBackTwoSum += position.getPrice() * position.getQuantity();
        else if (date.after(QuarterBackThree))
            QuarterBackThreeSum += position.getPrice() * position.getQuantity();
    }
    sums.put(beginningOfQuarter, thisQuarterSum);
    sums.put(QuarterBackOne, QuarterBackOneSum);
    sums.put(QuarterBackTwo, QuarterBackTwoSum);
    sums.put(QuarterBackThree, QuarterBackThreeSum);
    return sums;
}

From source file:net.sourceforge.openutils.mgnlcriteria.jcr.query.CriteriaTest.java

/**
 * Tests the xpath query statement produced by a Criteria instance.
 * @throws Exception//from www . j  a v  a 2s  .c o  m
 */
@Test
public void testToXpathExpression() throws Exception {
    Criteria criteria = toXpathExpressionJavadocExampleCriteria();

    Calendar begin = Calendar.getInstance();
    begin.set(1999, Calendar.JANUARY, 1);
    begin.set(Calendar.HOUR_OF_DAY, 0);
    begin.set(Calendar.MINUTE, 0);
    begin.set(Calendar.SECOND, 0);
    begin.set(Calendar.MILLISECOND, 0);
    Calendar end = Calendar.getInstance();
    end.set(2001, Calendar.DECEMBER, 31);
    end.set(Calendar.HOUR_OF_DAY, 0);
    end.set(Calendar.MINUTE, 0);
    end.set(Calendar.SECOND, 0);
    end.set(Calendar.MILLISECOND, 0);
    end.add(Calendar.MILLISECOND, -1);
    end.add(Calendar.DAY_OF_YEAR, 1);

    String expectedStmt = "//pets//*" + "[((jcr:contains(@title, 'Lucky')) and (@petType='dog')"
            + " and (@birthDate >=xs:dateTime('" + XPathTextUtils.toXsdDate(begin) + "')"
            + " and @birthDate <=xs:dateTime('" + XPathTextUtils.toXsdDate(end) + "')))]"
            + " order by @title descending";

    log.debug(expectedStmt);

    // @birthDate >=xs:dateTime('1999-01-01T00:00:00.000+01:00')
    // and
    // @birthDate <=xs:dateTime('2001-12-31T23:59:59.999+01:00')

    String actualStmt = criteria.toXpathExpression();

    Assert.assertEquals(StringUtils.remove(actualStmt, ' '), StringUtils.remove(expectedStmt, ' '));
}

From source file:com.mb.framework.util.DateTimeUtil.java

/**
 * This method is used for getting short description of month by the number
 * of month/*from w w  w .  j  a  v  a2 s.  c  o  m*/
 * 
 * @param mthNum
 * @return
 */
public static String getMonthShortDesc(int mthNum) {
    String mthShortDesc;

    switch (mthNum) {
    case Calendar.JANUARY: {
        mthShortDesc = DateTimeConstants.SHORT_JANUARY;
        break;
    }
    case Calendar.FEBRUARY: {
        mthShortDesc = DateTimeConstants.SHORT_FEBRUARY;
        break;
    }
    case Calendar.MARCH: {
        mthShortDesc = DateTimeConstants.SHORT_MARCH;
        break;
    }
    case Calendar.APRIL: {
        mthShortDesc = DateTimeConstants.SHORT_APRIL;
        break;
    }
    case Calendar.MAY: {
        mthShortDesc = DateTimeConstants.SHORT_MAY;
        break;
    }
    case Calendar.JUNE: {
        mthShortDesc = DateTimeConstants.SHORT_JUNE;
        break;
    }
    case Calendar.JULY: {
        mthShortDesc = DateTimeConstants.SHORT_JULY;
        break;
    }
    case Calendar.AUGUST: {
        mthShortDesc = DateTimeConstants.SHORT_AUGUST;
        break;
    }
    case Calendar.SEPTEMBER: {
        mthShortDesc = DateTimeConstants.SHORT_SEPTEMBER;
        break;
    }
    case Calendar.OCTOBER: {
        mthShortDesc = DateTimeConstants.SHORT_OCTOBER;
        break;
    }
    case Calendar.NOVEMBER: {
        mthShortDesc = DateTimeConstants.SHORT_NOVEMBER;
        break;
    }
    case Calendar.DECEMBER: {
        mthShortDesc = DateTimeConstants.SHORT_DECEMBER;
        break;
    }
    default: {
        mthShortDesc = "";
        break;
    }
    }

    return mthShortDesc;
}

From source file:one.GanttDemo1.java

/**
 * Creates a sample dataset for a Gantt chart.
 *
 * @return The dataset./* w  w w  . ja  v a2s . c o  m*/
 */
public static IntervalCategoryDataset createDataset() {

    final TaskSeries s1 = new TaskSeries("Scheduled");
    s1.add(new Task("Write Proposal",
            new SimpleTimePeriod(date(1, Calendar.APRIL, 2001), date(5, Calendar.APRIL, 2001))));
    s1.add(new Task("Obtain Approval",
            new SimpleTimePeriod(date(9, Calendar.APRIL, 2001), date(9, Calendar.APRIL, 2001))));
    s1.add(new Task("Requirements Analysis",
            new SimpleTimePeriod(date(10, Calendar.APRIL, 2001), date(5, Calendar.MAY, 2001))));
    s1.add(new Task("Design Phase",
            new SimpleTimePeriod(date(6, Calendar.MAY, 2001), date(30, Calendar.MAY, 2001))));
    s1.add(new Task("Design Signoff",
            new SimpleTimePeriod(date(2, Calendar.JUNE, 2001), date(2, Calendar.JUNE, 2001))));
    s1.add(new Task("Alpha Implementation",
            new SimpleTimePeriod(date(3, Calendar.JUNE, 2001), date(31, Calendar.JULY, 2001))));
    s1.add(new Task("Design Review",
            new SimpleTimePeriod(date(1, Calendar.AUGUST, 2001), date(8, Calendar.AUGUST, 2001))));
    s1.add(new Task("Revised Design Signoff",
            new SimpleTimePeriod(date(10, Calendar.AUGUST, 2001), date(10, Calendar.AUGUST, 2001))));
    s1.add(new Task("Beta Implementation",
            new SimpleTimePeriod(date(12, Calendar.AUGUST, 2001), date(12, Calendar.SEPTEMBER, 2001))));
    s1.add(new Task("Testing",
            new SimpleTimePeriod(date(13, Calendar.SEPTEMBER, 2001), date(31, Calendar.OCTOBER, 2001))));
    s1.add(new Task("Final Implementation",
            new SimpleTimePeriod(date(1, Calendar.NOVEMBER, 2001), date(15, Calendar.NOVEMBER, 2001))));
    s1.add(new Task("Signoff",
            new SimpleTimePeriod(date(28, Calendar.NOVEMBER, 2001), date(30, Calendar.NOVEMBER, 2001))));
    s1.add(new Task("Database set up",
            new SimpleTimePeriod(date(15, Calendar.OCTOBER, 2001), date(30, Calendar.OCTOBER, 2001))));

    final TaskSeries s2 = new TaskSeries("Actual");
    s2.add(new Task("Write Proposal",
            new SimpleTimePeriod(date(1, Calendar.APRIL, 2001), date(5, Calendar.APRIL, 2001))));
    s2.add(new Task("Obtain Approval",
            new SimpleTimePeriod(date(9, Calendar.APRIL, 2001), date(9, Calendar.APRIL, 2001))));
    s2.add(new Task("Requirements Analysis",
            new SimpleTimePeriod(date(10, Calendar.APRIL, 2001), date(15, Calendar.MAY, 2001))));
    s2.add(new Task("Design Phase",
            new SimpleTimePeriod(date(15, Calendar.MAY, 2001), date(17, Calendar.JUNE, 2001))));
    s2.add(new Task("Design Signoff",
            new SimpleTimePeriod(date(30, Calendar.JUNE, 2001), date(30, Calendar.JUNE, 2001))));
    s2.add(new Task("Alpha Implementation",
            new SimpleTimePeriod(date(1, Calendar.JULY, 2001), date(12, Calendar.SEPTEMBER, 2001))));
    s2.add(new Task("Design Review",
            new SimpleTimePeriod(date(12, Calendar.SEPTEMBER, 2001), date(22, Calendar.SEPTEMBER, 2001))));
    s2.add(new Task("Revised Design Signoff",
            new SimpleTimePeriod(date(25, Calendar.SEPTEMBER, 2001), date(27, Calendar.SEPTEMBER, 2001))));
    s2.add(new Task("Beta Implementation",
            new SimpleTimePeriod(date(27, Calendar.SEPTEMBER, 2001), date(30, Calendar.OCTOBER, 2001))));
    s2.add(new Task("Testing",
            new SimpleTimePeriod(date(31, Calendar.OCTOBER, 2001), date(17, Calendar.NOVEMBER, 2001))));
    s2.add(new Task("Final Implementation",
            new SimpleTimePeriod(date(18, Calendar.NOVEMBER, 2001), date(5, Calendar.DECEMBER, 2001))));
    s2.add(new Task("Signoff",
            new SimpleTimePeriod(date(10, Calendar.DECEMBER, 2001), date(11, Calendar.DECEMBER, 2001))));

    final TaskSeriesCollection collection = new TaskSeriesCollection();
    collection.add(s1);
    collection.add(s2);

    return collection;
}

From source file:it.scoppelletti.mobilepower.types.SimpleDate.java

/**
 * Restituisce la data corrispondente ad un codice giorno.
 * //from w  w w  . j a  va  2  s. co m
 * @param  dayCode Codice giorno.
 * @return         Data.
 * @see            #calcDayCode
 */
public static SimpleDate fromDayCode(long dayCode) {
    int year, month, day, delta, monthDays;
    Calendar cal;

    if (dayCode < 0) {
        throw new IllegalArgumentException("Argument dayCode is less than 0.");
    }
    if (dayCode == 0) {
        return SimpleDate.NIL;
    }

    // Calcolo l'anno year al quale appartiene la data ricercata per
    // approssimazioni successive basate sul concetto di codice anno: dato
    // infatti un numero di giorni, il minimo numero di anni che
    // intercorrono in quel periodo e' il rapporto tra quel numero di giorni
    // e 366 (durata massima in giorni di un anno).
    cal = Calendar.getInstance();
    year = (int) (dayCode / 366l);
    while (true) {
        delta = (int) (dayCode - SimpleDate.calcYearCode(year));
        if (delta < 366) {
            break;
        }

        year = year + delta / 366;
    }

    if (delta == 0) {
        // Definizione di codice anno
        year--;
        cal.set(Calendar.YEAR, year);
        cal.set(Calendar.MONTH, Calendar.DECEMBER);
        day = cal.getActualMaximum(Calendar.DAY_OF_MONTH);
        return new SimpleDate(year, Calendar.DECEMBER, day);
    }

    // delta corrisponde al numero progressivo del giorno ricercato
    // nell'anno:
    // Sottraendo progressivamente la durata in giorni dei mesi, si
    // determina il numero progressivo del mese nell'anno; il residuo finale
    // corrisponde al numero progressivo del giorno nel mese.
    cal.set(Calendar.YEAR, year);
    day = 0; // avoid warning
    for (month = 0; delta > 0; month++) {
        cal.set(Calendar.MONTH, month);
        monthDays = cal.getActualMaximum(Calendar.DAY_OF_MONTH);
        if (delta <= monthDays) {
            day = delta;
            break;
        }

        delta = delta - monthDays;
    }

    return new SimpleDate(year, month, day);
}

From source file:com.netflix.simianarmy.basic.BasicCalendar.java

/**
 * Load holidays.//w w w  .  j av  a  2 s. co  m
 *
 * @param year
 *            the year
 */
protected void loadHolidays(int year) {
    holidays.clear();
    // these aren't all strictly holidays, but days when engineers will likely
    // not be in the office to respond to rampaging monkeys

    // new years, or closest work day
    holidays.add(workDayInYear(year, Calendar.JANUARY, 1));

    // 3rd monday == MLK Day
    holidays.add(dayOfYear(year, Calendar.JANUARY, Calendar.MONDAY, 3));

    // 3rd monday == Presidents Day
    holidays.add(dayOfYear(year, Calendar.FEBRUARY, Calendar.MONDAY, 3));

    // last monday == Memorial Day
    holidays.add(dayOfYear(year, Calendar.MAY, Calendar.MONDAY, -1));

    // 4th of July, or closest work day
    holidays.add(workDayInYear(year, Calendar.JULY, 4));

    // first monday == Labor Day
    holidays.add(dayOfYear(year, Calendar.SEPTEMBER, Calendar.MONDAY, 1));

    // second monday == Columbus Day
    holidays.add(dayOfYear(year, Calendar.OCTOBER, Calendar.MONDAY, 2));

    // veterans day, Nov 11th, or closest work day
    holidays.add(workDayInYear(year, Calendar.NOVEMBER, 11));

    // 4th thursday == Thanksgiving
    holidays.add(dayOfYear(year, Calendar.NOVEMBER, Calendar.THURSDAY, 4));

    // 4th friday == "black friday", monkey goes shopping!
    holidays.add(dayOfYear(year, Calendar.NOVEMBER, Calendar.FRIDAY, 4));

    // christmas eve
    holidays.add(dayOfYear(year, Calendar.DECEMBER, 24));
    // christmas day
    holidays.add(dayOfYear(year, Calendar.DECEMBER, 25));
    // day after christmas
    holidays.add(dayOfYear(year, Calendar.DECEMBER, 26));

    // new years eve
    holidays.add(dayOfYear(year, Calendar.DECEMBER, 31));

    // mark the holiday set with the year, so on Jan 1 it will automatically
    // recalculate the holidays for next year
    holidays.add(year);
}

From source file:py.una.pol.karaku.test.test.dao.clauses.DateClausesTest.java

private Date date(int day) {

    return newTime(day, Calendar.DECEMBER, 2013, 0, 0);
}

From source file:py.una.pol.karaku.test.test.dao.clauses.DateClausesTest.java

private Date dateTime(int day, int hour, int minute) {

    return newTime(day, Calendar.DECEMBER, 2013, hour, minute);
}

From source file:org.sakaiproject.util.CalendarUtil.java

void initDates() {
    Calendar calendarSunday = Calendar.getInstance();
    Calendar calendarMonday = Calendar.getInstance();
    Calendar calendarTuesday = Calendar.getInstance();
    Calendar calendarWednesday = Calendar.getInstance();
    Calendar calendarThursday = Calendar.getInstance();
    Calendar calendarFriday = Calendar.getInstance();
    Calendar calendarSaturday = Calendar.getInstance();

    calendarSunday.set(Calendar.DAY_OF_WEEK, Calendar.SUNDAY);
    calendarMonday.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY);
    calendarTuesday.set(Calendar.DAY_OF_WEEK, Calendar.TUESDAY);
    calendarWednesday.set(Calendar.DAY_OF_WEEK, Calendar.WEDNESDAY);
    calendarThursday.set(Calendar.DAY_OF_WEEK, Calendar.THURSDAY);
    calendarFriday.set(Calendar.DAY_OF_WEEK, Calendar.FRIDAY);
    calendarSaturday.set(Calendar.DAY_OF_WEEK, Calendar.SATURDAY);

    dateSunday = calendarSunday.getTime();
    dateMonday = calendarMonday.getTime();
    dateTuesday = calendarTuesday.getTime();
    dateWednesday = calendarWednesday.getTime();
    dateThursday = calendarThursday.getTime();
    dateFriday = calendarFriday.getTime();
    dateSaturday = calendarSaturday.getTime();

    Calendar calendarJanuary = Calendar.getInstance();
    Calendar calendarFebruary = Calendar.getInstance();
    Calendar calendarMarch = Calendar.getInstance();
    Calendar calendarApril = Calendar.getInstance();
    Calendar calendarMay = Calendar.getInstance();
    Calendar calendarJune = Calendar.getInstance();
    Calendar calendarJuly = Calendar.getInstance();
    Calendar calendarAugust = Calendar.getInstance();
    Calendar calendarSeptember = Calendar.getInstance();
    Calendar calendarOctober = Calendar.getInstance();
    Calendar calendarNovember = Calendar.getInstance();
    Calendar calendarDecember = Calendar.getInstance();

    calendarJanuary.set(Calendar.MONTH, Calendar.JANUARY);
    calendarFebruary.set(Calendar.MONTH, Calendar.FEBRUARY);
    calendarMarch.set(Calendar.MONTH, Calendar.MARCH);
    calendarApril.set(Calendar.MONTH, Calendar.APRIL);
    calendarMay.set(Calendar.MONTH, Calendar.MAY);
    calendarJune.set(Calendar.MONTH, Calendar.JUNE);
    calendarJuly.set(Calendar.MONTH, Calendar.JULY);
    calendarAugust.set(Calendar.MONTH, Calendar.AUGUST);
    calendarSeptember.set(Calendar.MONTH, Calendar.SEPTEMBER);
    calendarOctober.set(Calendar.MONTH, Calendar.OCTOBER);
    calendarNovember.set(Calendar.MONTH, Calendar.NOVEMBER);
    calendarDecember.set(Calendar.MONTH, Calendar.DECEMBER);

    dateJanuary = calendarJanuary.getTime();
    dateFebruary = calendarFebruary.getTime();
    dateMarch = calendarMarch.getTime();
    dateApril = calendarApril.getTime();
    dateMay = calendarMay.getTime();//from w w w  . ja  v  a2 s .  c om
    dateJune = calendarJune.getTime();
    dateJuly = calendarJuly.getTime();
    dateAugust = calendarAugust.getTime();
    dateSeptember = calendarSeptember.getTime();
    dateOctober = calendarOctober.getTime();
    dateNovember = calendarNovember.getTime();
    dateDecember = calendarDecember.getTime();

}

From source file:com.jeans.iservlet.controller.impl.AssetsController.java

private Map<String, Object> parseFilters(String filters) {
    Map<String, Object> ret = new HashMap<String, Object>();
    String[] fs = filters.split("&");
    Set<String> vendors = new HashSet<String>();
    String[] vs = fs[0].split(",");
    for (String v : vs) {
        if (!StringUtils.isBlank(v)) {
            vendors.add(v);//from   w  w w. ja  va2s .  c o m
        }
    }
    ret.put("vendor", vendors);
    Calendar start = Calendar.getInstance();
    try {
        start.set(Calendar.YEAR, Integer.parseInt(fs[1]));
        start.set(Calendar.MONTH, Calendar.JANUARY);
        start.set(Calendar.DATE, 1);
        start.set(Calendar.HOUR_OF_DAY, 0);
        start.set(Calendar.MINUTE, 0);
        start.set(Calendar.SECOND, 0);
        start.set(Calendar.MILLISECOND, 0);
        ret.put("purchaseTimeStart", start.getTime());
    } catch (Exception e) {
        ret.put("purchaseTimeStart", null);
    }
    Calendar end = Calendar.getInstance();
    try {
        end.set(Calendar.YEAR, Integer.parseInt(fs[2]));
        end.set(Calendar.MONTH, Calendar.DECEMBER);
        end.set(Calendar.DATE, 31);
        end.set(Calendar.HOUR_OF_DAY, 23);
        end.set(Calendar.MINUTE, 59);
        end.set(Calendar.SECOND, 59);
        end.set(Calendar.MILLISECOND, 999);
        ret.put("purchaseTimeEnd", end.getTime());
    } catch (Exception e) {
        ret.put("purchaseTimeEnd", null);
    }
    try {
        ret.put("state", Byte.parseByte(fs[3]));
    } catch (Exception e) {
        ret.put("state", (byte) 9);
    }
    if (fs.length == 6) { // : warranty, importance
        try {
            ret.put("warranty", Byte.parseByte(fs[5]));
        } catch (Exception e) {
            ret.put("warranty", (byte) 9);
        }
        try {
            ret.put("importance", Byte.parseByte(fs[6]));
        } catch (Exception e) {
            ret.put("importance", (byte) 9);
        }
    } else if (fs.length == 5) { // : softwareType
        try {
            ret.put("softwareType", Byte.parseByte(fs[4]));
        } catch (Exception e) {
            ret.put("softwareType", (byte) 9);
        }
    }
    return ret;
}