List of usage examples for java.util Calendar JANUARY
int JANUARY
To view the source code for java.util Calendar JANUARY.
Click Source Link
From source file:org.opennms.web.rest.v1.AlarmStatsRestServiceIT.java
protected OnmsEvent createEvent() { final Calendar c = new GregorianCalendar(); c.set(2010, Calendar.JANUARY, 1, 0, 0, 0); long time = c.getTimeInMillis(); time = (time - (time % 1000));/* w ww . ja va 2 s . c o m*/ final Date date = new Date(time + (count * 60 * 60 * 1000)); final OnmsEvent event = new OnmsEvent(); event.setDistPoller(m_distPollerDao.whoami()); event.setEventUei("uei.opennms.org/test/" + count); event.setEventCreateTime(date); event.setEventTime(date); event.setEventDescr("Test event " + count); event.setEventDisplay("Y"); event.setEventLog("Y"); event.setEventHost("es-with-the-most-es"); event.setEventLogMsg("Test event " + count + " (log)"); event.setEventParms("test=parm(string,text)"); event.setEventSeverity(OnmsSeverity.MAJOR.getId()); event.setEventSource("AlarmStatsRestServiceTest"); event.setIpAddr(InetAddressUtils.UNPINGABLE_ADDRESS); event.setNode(m_databasePopulator.getNode1()); event.setServiceType(m_databasePopulator.getServiceTypeDao().findByName("ICMP")); m_eventDao.save(event); m_eventDao.flush(); count++; return event; }
From source file:br.msf.commons.util.AbstractDateUtils.java
public static Integer getLastDayOfMonth(final Integer month, final Integer year) { ArgumentUtils.rejectIfAnyNull(month, year); ArgumentUtils.rejectIfOutOfBounds(month, Calendar.JANUARY, Calendar.DECEMBER); return getLastDayOfMonth(new GregorianCalendar(year, month, 1)); }
From source file:org.opennms.web.rest.AlarmStatsRestServiceTest.java
protected OnmsEvent createEvent() { final Calendar c = new GregorianCalendar(); c.set(2010, Calendar.JANUARY, 1, 0, 0, 0); long time = c.getTimeInMillis(); time = (time - (time % 1000));/* w ww . j ava 2 s . co m*/ final Date date = new Date(time + (count * 60 * 60 * 1000)); final OnmsEvent event = new OnmsEvent(); event.setDistPoller(getDistPollerDao().load("localhost")); event.setEventUei("uei.opennms.org/test/" + count); event.setEventCreateTime(date); event.setEventTime(date); event.setEventDescr("Test event " + count); event.setEventDisplay("Y"); event.setEventLog("Y"); event.setEventHost("es-with-the-most-es"); event.setEventLogMsg("Test event " + count + " (log)"); event.setEventParms("test=parm(string,text)"); event.setEventSeverity(OnmsSeverity.MAJOR.getId()); event.setEventSource("AlarmStatsRestServiceTest"); event.setIpAddr(InetAddressUtils.UNPINGABLE_ADDRESS); event.setNode(m_databasePopulator.getNode1()); event.setServiceType(m_databasePopulator.getServiceTypeDao().findByName("ICMP")); getEventDao().save(event); getEventDao().flush(); count++; return event; }
From source file:myorg.relex.One2OneTest.java
/** * This test provides a demonstration of creating a one-to-one, uni-directional * relationship to a parent class that uses a composite primary key mapped thru an @IdClass *//*from w w w .j a va2 s .co m*/ @Test public void testOne2OneUniIdClass() { log.info("*** testOne2OneUniIdClass ***"); Date showDate = new GregorianCalendar(1975 + new Random().nextInt(100), Calendar.JANUARY, 1).getTime(); Date showTime = new GregorianCalendar(0, 0, 0, 0, 0, 0).getTime(); ShowEvent show = new ShowEvent(showDate, showTime); show.setName("Rocky Horror"); ShowTickets tickets = new ShowTickets(show); //parent already has natural PK by this point tickets.setTicketsLeft(300); em.persist(show); em.persist(tickets); //flush commands to database, clear cache, and pull back new instance em.flush(); em.clear(); ShowTickets tickets2 = em.find(ShowTickets.class, new ShowEventPK(tickets.getDate(), tickets.getTime())); log.info("calling parent..."); assertEquals("unexpected name", tickets.getShow().getName(), tickets2.getShow().getName()); //verify the contents of the database tables, columns, and relationships Object[] cols = (Object[]) em.createNativeQuery("select show.date show_date, show.time show_time, " + "tickets.ticket_date ticket_date, tickets.ticket_time ticket_time, tickets.tickets " + "from RELATIONEX_SHOWEVENT show " + "join RELATIONEX_SHOWTICKETS tickets on show.date = tickets.ticket_date and show.time = tickets.ticket_time " + "where tickets.ticket_date = ?1 and tickets.ticket_time = ?2") .setParameter(1, tickets.getShow().getDate(), TemporalType.DATE) .setParameter(2, tickets.getShow().getTime(), TemporalType.TIME).getSingleResult(); log.info("row=" + Arrays.toString(cols)); assertEquals("unexpected show_date", tickets2.getShow().getDate(), (Date) cols[0]); assertEquals("unexpected show_time", tickets2.getShow().getTime(), (Date) cols[1]); assertEquals("unexpected ticket_date", tickets2.getDate(), (Date) cols[2]); assertEquals("unexpected ticket_time", tickets2.getTime(), (Date) cols[3]); assertEquals("unexpected ticketsLeft", tickets2.getTicketsLeft(), ((Number) cols[4]).intValue()); //remove the objects and flush commands to the database em.remove(tickets2); em.remove(tickets2.getShow()); em.flush(); assertNull("tickets not deleted", em.find(ShowEvent.class, new ShowEventPK(show.getDate(), show.getTime()))); assertNull("show not deleted", em.find(ShowTickets.class, new ShowEventPK(tickets.getDate(), tickets.getTime()))); }
From source file:org.jfree.data.time.HourTest.java
/** * Some checks for the getEnd() method.//from w w w . ja v a 2 s. co m */ @Test public void testGetEnd() { Locale saved = Locale.getDefault(); Locale.setDefault(Locale.ITALY); Calendar cal = Calendar.getInstance(Locale.ITALY); cal.set(2006, Calendar.JANUARY, 8, 1, 59, 59); cal.set(Calendar.MILLISECOND, 999); Hour h = new Hour(1, 8, 1, 2006); assertEquals(cal.getTime(), h.getEnd()); Locale.setDefault(saved); }
From source file:org.jfree.data.time.junit.SecondTest.java
/** * Some checks for the getEnd() method./*from w w w .j av a 2s . co m*/ */ public void testGetEnd() { Locale saved = Locale.getDefault(); Locale.setDefault(Locale.ITALY); Calendar cal = Calendar.getInstance(Locale.ITALY); cal.set(2006, Calendar.JANUARY, 16, 3, 47, 55); cal.set(Calendar.MILLISECOND, 999); Second s = new Second(55, 47, 3, 16, 1, 2006); assertEquals(cal.getTime(), s.getEnd()); Locale.setDefault(saved); }
From source file:eionet.util.Util.java
/** * A method for calculating time difference in MILLISECONDS, between a date-time specified in input parameters and the current * date-time. <BR>/*from w ww .j a v a 2s . com*/ * This should be useful for calculating sleep time for code that has a certain schedule for execution. * * @param hour * An integer from 0 to 23. If less than 0 or more than 23, then the closest next hour to current hour is taken. * @param date * An integer from 1 to 31. If less than 1 or more than 31, then the closest next date to current date is taken. * @param month * An integer from Calendar.JANUARY to Calendar.DECEMBER. If out of those bounds, the closest next month to current * month is taken. * @param wday * An integer from 1 to 7. If out of those bounds, the closest next weekday to weekday month is taken. * @param zone * A String specifying the time-zone in which the calculations should be done. Please see Java documentation an * allowable time-zones and formats. * @return Time difference in milliseconds. */ public static long timeDiff(int hour, int date, int month, int wday, String zone) { GregorianCalendar cal = new GregorianCalendar(TimeZone.getTimeZone(zone)); cal.set(Calendar.MINUTE, 0); cal.set(Calendar.SECOND, 0); cal.set(Calendar.MILLISECOND, 0); cal.setFirstDayOfWeek(Calendar.MONDAY); /* * here we force the hour to be one of the defualts if (hour < 0) hour = 0; if (hour > 23) hour = 23; */ int cur_hour = cal.get(Calendar.HOUR); if (cal.get(Calendar.AM_PM) == Calendar.PM) { cur_hour = 12 + cur_hour; } // here we assume that every full hour is accepted /* * if (hour < 0 || hour > 23) { hour = cur_hour>=23 ? 0 : cur_hour + 1; } */ if (wday >= 1 && wday <= 7) { int cur_wday = cal.get(Calendar.DAY_OF_WEEK); if (hour < 0 || hour > 23) { if (cur_wday != wday) { hour = 0; } else { hour = cur_hour >= 23 ? 0 : cur_hour + 1; } } int amount = wday - cur_wday; if (amount < 0) { amount = 7 + amount; } if (amount == 0 && cur_hour >= hour) { amount = 7; } cal.add(Calendar.DAY_OF_WEEK, amount); } else if (month >= Calendar.JANUARY && month <= Calendar.DECEMBER) { // do something about when every date is accepted if (date < 1) { date = 1; } if (date > 31) { date = 31; } int cur_month = cal.get(Calendar.MONTH); int amount = month - cur_month; if (amount < 0) { amount = 12 + amount; } if (amount == 0) { if (cal.get(Calendar.DATE) > date) { amount = 12; } else if (cal.get(Calendar.DATE) == date) { if (cur_hour >= hour) { amount = 12; } } } // cal.set(Calendar.DATE, date); cal.add(Calendar.MONTH, amount); if (date > cal.getActualMaximum(Calendar.DATE)) { date = cal.getActualMaximum(Calendar.DATE); } cal.set(Calendar.DATE, date); } else if (date >= 1 && date <= 31) { int cur_date = cal.get(Calendar.DATE); if (cur_date > date) { cal.add(Calendar.MONTH, 1); } else if (cur_date == date) { if (cur_hour >= hour) { cal.add(Calendar.MONTH, 1); } } cal.set(Calendar.DATE, date); } else { if (hour < 0 || hour > 23) { hour = cur_hour >= 23 ? 0 : cur_hour + 1; } if (cur_hour >= hour) { cal.add(Calendar.DATE, 1); } } if (hour >= 12) { cal.set(Calendar.HOUR, hour - 12); cal.set(Calendar.AM_PM, Calendar.PM); } else { cal.set(Calendar.HOUR, hour); cal.set(Calendar.AM_PM, Calendar.AM); } Date nextDate = cal.getTime(); Date currDate = new Date(); long nextTime = cal.getTime().getTime(); long currTime = (new Date()).getTime(); return nextTime - currTime; }
From source file:org.mifos.customers.client.persistence.ClientPersistenceIntegrationTest.java
public void testShouldNotThrowExceptionWhenTryingToUpdateClientGovtIdToGovtIdOfAClosedClient() throws Exception { setUpClients();// www.j a v a 2s . c o m localTestClient = createClosedClientWithGovtId(); clientWithSameGovtId = TestObjectFactory.createClient(this.getClass().getSimpleName() + " Duplicate Client", CustomerStatus.CLIENT_ACTIVE, group); try { clientWithSameGovtId.updatePersonalInfo(this.getClass().getSimpleName() + " Duplicate Client", GOVT_ID, DateUtils.getDate(1980, Calendar.JANUARY, 1)); StaticHibernateUtil.commitTransaction(); } catch (RuntimeException e) { Assert.fail("Should not throw error when updating to a government id of closed client"); } }
From source file:org.jfree.data.time.junit.MinuteTest.java
/** * Some checks for the getEnd() method.//from ww w . ja v a 2 s . co m */ public void testGetEnd() { Locale saved = Locale.getDefault(); Locale.setDefault(Locale.ITALY); TimeZone savedZone = TimeZone.getDefault(); TimeZone.setDefault(TimeZone.getTimeZone("Europe/Rome")); Calendar cal = Calendar.getInstance(Locale.ITALY); cal.set(2006, Calendar.JANUARY, 16, 3, 47, 59); cal.set(Calendar.MILLISECOND, 999); Minute m = new Minute(47, 3, 16, 1, 2006); assertEquals(cal.getTime(), m.getEnd()); Locale.setDefault(saved); TimeZone.setDefault(savedZone); }
From source file:org.openlmis.core.repository.mapper.FacilityMapperIT.java
@Test public void shouldUpdateFacilityWithSuppliedModifiedTime() throws Exception { Facility facility = make(a(defaultFacility)); mapper.insert(facility);/*from ww w . j a v a 2 s .c o m*/ facility.setCode("NewTestCode"); Calendar calendar = Calendar.getInstance(); calendar.set(Calendar.MONTH, Calendar.JANUARY); facility.setModifiedDate(calendar.getTime()); mapper.update(facility); Facility updatedFacility = mapper.getById(facility.getId()); assertThat(updatedFacility.getCode(), is(facility.getCode())); assertThat(updatedFacility.getModifiedDate(), is(calendar.getTime())); }