Example usage for java.util Calendar JANUARY

List of usage examples for java.util Calendar JANUARY

Introduction

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

Prototype

int JANUARY

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

Click Source Link

Document

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

Usage

From source file:org.mifos.reports.business.service.BranchReportServiceIntegrationTest.java

@Test
public void testServiceReturnsFalseIfBranchReportDataNotPresentForGivenDate() throws Exception {
    Assert.assertFalse(//from w  w  w.j  a  v  a 2s  . c om
            branchReportService.isReportDataPresentForRundate(DateUtils.getDate(2008, Calendar.JANUARY, 1)));
}

From source file:Time.java

/**
 * Create a new day, specifying the year and the day of year. The day is
 * lenient meaning that illegal day parameters can be specified and results in
 * a recomputed day with legal month/day values.
 * //from   w ww  .j a va2  s  .c  o  m
 * @param year
 *          Year of new day.
 * @param dayOfYear
 *          1=January 1, etc.
 */
public Day(int year, int dayOfYear) {
    initialize(year, Calendar.JANUARY, 1);
    calendar_.set(Calendar.DAY_OF_YEAR, dayOfYear);
}

From source file:com.datamountaineer.streamreactor.connect.json.SimpleJsonConverterTest.java

@Test
public void timestampToJson() throws IOException {
    GregorianCalendar calendar = new GregorianCalendar(1970, Calendar.JANUARY, 1, 0, 0, 0);
    calendar.setTimeZone(TimeZone.getTimeZone("UTC"));
    calendar.add(Calendar.MILLISECOND, 2000000000);
    calendar.add(Calendar.MILLISECOND, 2000000000);
    java.util.Date date = calendar.getTime();

    JsonNode converted = converter.fromConnectData(Timestamp.SCHEMA, date);
    assertTrue(converted.isLong());/*  www .  j a  v a 2s . c  o m*/
    assertEquals(4000000000L, converted.longValue());
}

From source file:myorg.relex.One2OneTest.java

/**
 * This test provides a demonstration of a one-to-one primary key join.
 * In this case, the child and parent tables using the same primary key value
 * and the child re-uses its PK-column as the FK-column. No separate FK-column
 * is created in the child -- unlike the one-to-one FK-join case above. However,
 * the provider does not automatically propagate the parent.PK to the dependent.PK
 * during the persist().  /*  w ww.  j av  a2  s  .co m*/
 */
@Test
public void testOne2OneUniPKJ() {
    log.info("*** testOne2OneUniPKJ ***");
    Person person = new Person();
    person.setName("Ozzie Newsome");
    em.persist(person);
    em.flush(); //generate the PK for the person

    Employee employee = new Employee(person);//set PK/FK -- provider will not auto propagate
    employee.setHireDate(new GregorianCalendar(1996, Calendar.JANUARY, 1).getTime());
    //em.persist(person);
    em.persist(employee);

    //clear the persistence context and get new instances
    em.flush();
    em.clear();
    Employee employee2 = em.find(Employee.class, employee.getPerson().getId());
    log.info("calling person...");
    assertEquals("unexpected name", employee.getPerson().getName(), employee2.getPerson().getName());

    //verify the contents of the database tables, columns, and relationships
    Object[] cols = (Object[]) em
            .createNativeQuery("select person.id person_id, person.name, " + "employee.id employee_id "
                    + "from RELATIONEX_EMPLOYEE employee "
                    + "join RELATIONEX_PERSON person on person.id = employee.id " + "where employee.id = ?1")
            .setParameter(1, employee.getId()).getSingleResult();
    log.info("row=" + Arrays.toString(cols));
    assertEquals("unexpected person_id", person.getId(), ((Number) cols[0]).intValue());
    assertEquals("unexpected person_name", person.getName(), (String) cols[1]);
    assertEquals("unexpected employee_id", employee.getId(), ((Number) cols[2]).intValue());

    //remove the objects and flush commands to the database
    em.remove(employee2);
    em.remove(employee2.getPerson());
    em.flush();
    assertNull("person not deleted", em.find(Person.class, person.getId()));
    assertNull("employee not deleted", em.find(Employee.class, employee.getId()));
}

From source file:org.mifos.application.reports.business.service.BranchReportServiceIntegrationTest.java

public void testServiceReturnsFalseIfBranchReportDataNotPresentForGivenDate() throws Exception {
    Assert.assertFalse(/*from   w ww .  j  a  v a2  s .c  o  m*/
            branchReportService.isReportDataPresentForRundate(DateUtils.getDate(2008, Calendar.JANUARY, 1)));
}

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

/**
 * Tests pagination of results.// www  . j  a v a 2  s  .co  m
 * @throws Exception
 */
@Test
public void testSetFirstResultAndMaxResults() throws Exception {
    Calendar begin = Calendar.getInstance();
    begin.set(1999, Calendar.JANUARY, 1);
    Calendar end = Calendar.getInstance();
    end.set(2001, Calendar.DECEMBER, 31);

    Criteria criteria = JCRCriteriaFactory.createCriteria().setWorkspace(RepositoryConstants.WEBSITE)
            .setBasePath("/pets").add(Restrictions.betweenDates("@birthDate", begin, end))
            .addOrder(Order.asc("@birthDate")).setFirstResult(5).setMaxResults(5);

    AdvancedResult result = criteria.execute();
    // first page:
    // --- 9 (title=Lucky, petType=bird, birthDate=1999-08-06)
    // --- 6 (title=George, petType=snake, birthDate=2000-01-20)
    // --- 4 (title=Jewel, petType=dog, birthDate=2000-03-07)
    // --- 11 (title=Freddy, petType=bird, birthDate=2000-03-09)
    // --- 12 (title=Lucky, petType=dog, birthDate=2000-06-24)
    // second page:
    // --- 1 (title=Leo, petType=cat, birthDate=2000-09-07)
    // --- 5 (title=Iggy, petType=lizard, birthDate=2000-11-30)
    // --- 3 (title=Rosy, petType=dog, birthDate=2001-04-17)
    Assert.assertEquals(result.getTotalSize(), 8);

    ResultIterator<? extends Node> iterator = result.getItems();
    Assert.assertEquals(iterator.getSize(), 3);
    Assert.assertEquals(CriteriaTestUtils.name(iterator.next()), "1");
    Assert.assertEquals(CriteriaTestUtils.name(iterator.next()), "5");
    Assert.assertEquals(CriteriaTestUtils.name(iterator.next()), "3");
}

From source file:com.enonic.cms.core.search.builder.ContentIndexDataFactoryTest.java

private ContentDocument createTestContent() throws Exception {
    final GregorianCalendar date = new GregorianCalendar(2011, Calendar.JANUARY, 10);

    ContentDocument content = new ContentDocument(new ContentKey(1));
    content.setCategoryKey(new CategoryKey(2));
    content.setCategoryName("MyCategory");
    content.setContentTypeKey(new ContentTypeKey(3));
    content.setContentTypeName("MyContentType");

    content.setCreated(date.getTime());//from   ww  w .  jav  a 2  s  . co m
    content.setTimestamp(date.getTime());
    content.setModified(date.getTime());

    content.setTitle("MyTitle");
    content.setStatus(2);
    content.setPriority(1);
    content.setLanguageCode("en");

    content.setModifierKey("10");
    content.setModifierName("ModifierName");
    content.setModifierQualifiedName("ModifierQName");

    content.setOwnerKey("11");
    content.setOwnerName("OwnerName");
    content.setOwnerQualifiedName("OwnerQName");

    content.setAssigneeKey("12");
    content.setAssigneeName("AssigneeName");
    content.setAssigneeQualifiedName("AssigneeQName");

    content.setAssignerKey("14");
    content.setAssignerName("AssignerName");
    content.setAssignerQualifiedName("AssignerQName");

    date.add(Calendar.MONTH, 1);
    content.setAssignmentDueDate(date.getTime());

    content.setPublishFrom(date.getTime());
    date.add(Calendar.MONTH, 1);
    content.setPublishTo(date.getTime());

    content.setContentLocations(new ContentLocations(new ContentEntity()));

    content.addUserDefinedField("data/person/age", "38");
    content.addUserDefinedField("data/person/gender", "male");
    content.addUserDefinedField("data/person/description", "description 38");

    content.addUserDefinedField("data/person/age", "28");
    content.addUserDefinedField("data/person/gender", "male");
    content.addUserDefinedField("data/person/description", "description 28");

    content.addUserDefinedField("data/person/age", "10");
    content.addUserDefinedField("data/person/gender", "male");
    content.addUserDefinedField("data/person/description", "description 10");

    return content;
}

From source file:se.technipelago.weather.chart.Generator.java

public String[] generateMonthlyCharts(final int year) {

    init();// w  ww .j  a va  2  s.c  o  m

    final List<String> files = new ArrayList<String>();
    final DateFormat fmt = new SimpleDateFormat("yyyy-MM");
    try {
        // Historical data.
        Calendar cal = Calendar.getInstance();
        long now = cal.getTimeInMillis();
        cal.set(Calendar.YEAR, year);
        cal.add(Calendar.MONTH, Calendar.JANUARY);
        cal.set(Calendar.DAY_OF_MONTH, 1);
        cal.set(Calendar.HOUR_OF_DAY, 0);
        cal.set(Calendar.MINUTE, 0);
        cal.set(Calendar.SECOND, 0);
        cal.set(Calendar.MILLISECOND, 0);
        for (int i = 0; i < 12 && cal.getTimeInMillis() < now; i++) {
            Date start = cal.getTime();
            cal.add(Calendar.MONTH, 1);
            cal.add(Calendar.MILLISECOND, -1);
            Date stop = cal.getTime();
            cal.add(Calendar.MILLISECOND, 1);
            Timespan period = new Timespan(start, stop);
            String month = fmt.format(start);
            createHistoryChart(period, "temp_out", "Temperatur", "\u00B0Celcius",
                    "temperature_" + month + ".png");
            files.add("temperature_" + month + ".png");
            createHistoryChart(period, "barometer", "Barometer", "Millibar", "barometer_" + month + ".png");
            files.add("barometer_" + month + ".png");
            createHistoryChart(period, "hum_out", "Luftfuktighet", "Procent", "humidity_" + month + ".png");
            files.add("humidity_" + month + ".png");
            createHistoryChart(period, "wind_avg", "Vindhastighet", "m/s", "wind_" + month + ".png");
            files.add("wind_" + month + ".png");
            createHistoryChart(period, "solar", "Solstr\u00e5lning", "W/m\u00B2", "solar_" + month + ".png");
            files.add("solar_" + month + ".png");
            createHistoryChart(period, "uv", "UV-index", "UV", "uv_" + month + ".png");
            files.add("uv_" + month + ".png");
            createRainHistoryChart(period, "rain_" + month + ".png");
            files.add("rain_" + month + ".png");
        }
    } catch (IOException e) {
        log.log(Level.SEVERE, "I/O Error", e);
    }

    return files.toArray(new String[files.size()]);
}

From source file:edu.umm.radonc.ca_dash.model.ActivityFacade.java

public TreeMap<String, SynchronizedDescriptiveStatistics> getWeeklySummaryStats(Date start, Date end,
        Long hospitalser, boolean imrtOnly, boolean includeWeekends) {
    Calendar cal = new GregorianCalendar();
    TreeMap<String, SynchronizedDescriptiveStatistics> retval = new TreeMap<>();

    List<Object[]> events;

    if (hospitalser < 0) {
        events = getDailyCounts(start, end, imrtOnly, includeWeekends);
    } else {//from w w w.  ja v  a2 s  .co  m
        events = getDailyCounts(start, end, hospitalser, imrtOnly, includeWeekends);
    }
    cal.setTime(start);
    int wk = cal.get(Calendar.WEEK_OF_YEAR);
    int mo = cal.get(Calendar.MONTH);
    int yr = cal.get(Calendar.YEAR);
    if (mo == Calendar.DECEMBER && wk == 1) {
        yr = yr + 1;
    } else if (mo == Calendar.JANUARY && wk == 52) {
        yr = yr - 1;
    }
    String currYrWk = yr + "-" + String.format("%02d", wk);
    String prevYrWk = "";
    SynchronizedDescriptiveStatistics currStats = new SynchronizedDescriptiveStatistics();
    int i = 0;
    while (cal.getTime().before(end) && i < events.size()) {

        Object[] event = events.get(i);
        Date d = (Date) event[0];
        Long count = (Long) event[1];

        prevYrWk = currYrWk;
        cal.setTime(d);
        wk = cal.get(Calendar.WEEK_OF_YEAR);
        mo = cal.get(Calendar.MONTH);
        yr = cal.get(Calendar.YEAR);
        if (mo == Calendar.DECEMBER && wk == 1) {
            yr = yr + 1;
        } else if (mo == Calendar.JANUARY && wk == 52) {
            yr = yr - 1;
        }
        currYrWk = yr + "-" + String.format("%02d", wk);

        if (!(prevYrWk.equals(currYrWk))) {
            retval.put(prevYrWk, currStats);
            currStats = new SynchronizedDescriptiveStatistics();
        }

        currStats.addValue(count);
        i++;
    }
    retval.put(prevYrWk, currStats);

    return retval;
}

From source file:com.gemstone.gemfire.rest.internal.web.controllers.RestAPIsWithSSLDUnitTest.java

public void doPutsInClientCache() {
    ClientCache cache = GemFireCacheImpl.getInstance();
    assertNotNull(cache);//from   www  .  j  av a 2  s  .c om
    Region<String, Object> region = cache.getRegion(PEOPLE_REGION_NAME);

    // put person object
    final Person person1 = new Person(101L, "Mithali", "Dorai", "Raj",
            DateTimeUtils.createDate(1982, Calendar.DECEMBER, 4), Gender.FEMALE);
    final Person person2 = new Person(102L, "Sachin", "Ramesh", "Tendulkar",
            DateTimeUtils.createDate(1975, Calendar.DECEMBER, 14), Gender.MALE);
    final Person person3 = new Person(103L, "Saurabh", "Baburav", "Ganguly",
            DateTimeUtils.createDate(1972, Calendar.AUGUST, 29), Gender.MALE);
    final Person person4 = new Person(104L, "Rahul", "subrymanyam", "Dravid",
            DateTimeUtils.createDate(1979, Calendar.MARCH, 17), Gender.MALE);
    final Person person5 = new Person(105L, "Jhulan", "Chidambaram", "Goswami",
            DateTimeUtils.createDate(1983, Calendar.NOVEMBER, 25), Gender.FEMALE);

    region.put("1", person1);
    region.put("2", person2);
    region.put("3", person3);
    region.put("4", person4);
    region.put("5", person5);

    final Person person6 = new Person(101L, "Rahul", "Rajiv", "Gndhi",
            DateTimeUtils.createDate(1970, Calendar.MAY, 14), Gender.MALE);
    final Person person7 = new Person(102L, "Narendra", "Damodar", "Modi",
            DateTimeUtils.createDate(1945, Calendar.DECEMBER, 24), Gender.MALE);
    final Person person8 = new Person(103L, "Atal", "Bihari", "Vajpayee",
            DateTimeUtils.createDate(1920, Calendar.AUGUST, 9), Gender.MALE);
    final Person person9 = new Person(104L, "Soniya", "Rajiv", "Gandhi",
            DateTimeUtils.createDate(1929, Calendar.MARCH, 27), Gender.FEMALE);
    final Person person10 = new Person(104L, "Priyanka", "Robert", "Gandhi",
            DateTimeUtils.createDate(1973, Calendar.APRIL, 15), Gender.FEMALE);

    final Person person11 = new Person(104L, "Murali", "Manohar", "Joshi",
            DateTimeUtils.createDate(1923, Calendar.APRIL, 25), Gender.MALE);
    final Person person12 = new Person(104L, "Lalkrishna", "Parmhansh", "Advani",
            DateTimeUtils.createDate(1910, Calendar.JANUARY, 01), Gender.MALE);
    final Person person13 = new Person(104L, "Shushma", "kumari", "Swaraj",
            DateTimeUtils.createDate(1943, Calendar.AUGUST, 10), Gender.FEMALE);
    final Person person14 = new Person(104L, "Arun", "raman", "jetly",
            DateTimeUtils.createDate(1942, Calendar.OCTOBER, 27), Gender.MALE);
    final Person person15 = new Person(104L, "Amit", "kumar", "shah",
            DateTimeUtils.createDate(1958, Calendar.DECEMBER, 21), Gender.MALE);
    final Person person16 = new Person(104L, "Shila", "kumari", "Dixit",
            DateTimeUtils.createDate(1927, Calendar.FEBRUARY, 15), Gender.FEMALE);

    Map<String, Object> userMap = new HashMap<String, Object>();
    userMap.put("6", person6);
    userMap.put("7", person7);
    userMap.put("8", person8);
    userMap.put("9", person9);
    userMap.put("10", person10);
    userMap.put("11", person11);
    userMap.put("12", person12);
    userMap.put("13", person13);
    userMap.put("14", person14);
    userMap.put("15", person15);
    userMap.put("16", person16);

    region.putAll(userMap);

    if (cache != null)
        cache.getLogger().info("Gemfire Cache Client: Puts successfully done");

}