List of usage examples for java.util Calendar APRIL
int APRIL
To view the source code for java.util Calendar APRIL.
Click Source Link
From source file:myorg.relex.One2OneTest.java
/** * This test demonstrates use of cascades in a one-to-one * bi-directional relationship where all cascades come * from the inverse/parent side of the relationship. *//*from w w w.j a v a2s . c o m*/ @Test public void testOne2OneCascadeFromInverse() { log.info("*** testOne2OneCascadeFromInverse ***"); Ticket ticket = new Ticket(); ticket.setDate(new GregorianCalendar(2013, Calendar.MARCH, 16).getTime()); Passenger passenger = new Passenger(ticket, "Fred"); //set inverse side ticket.setPassenger(passenger); //set the owning side em.persist(ticket); //persist from inverse side em.flush(); assertTrue("ticket not managed", em.contains(ticket)); assertTrue("passenger not managed", em.contains(passenger)); log.debug("detach both instances from the persistence context"); em.detach(ticket); assertFalse("ticket managed", em.contains(ticket)); assertFalse("passenger managed", em.contains(passenger)); log.debug("perform a bulk update to both objects"); ticket = em.find(Ticket.class, ticket.getId()); Date newDate = new GregorianCalendar(2013, Calendar.APRIL, 1).getTime(); String newName = "Frederick"; em.createQuery("update Ticket t set t.date=:date").setParameter("date", newDate, TemporalType.DATE) .executeUpdate(); em.createQuery("update Passenger p set p.name=:name where p.name='Fred'").setParameter("name", newName) .executeUpdate(); assertFalse("unexpected date", newDate.equals(ticket.getDate())); assertFalse("unexpected name", newName.equals(ticket.getPassenger().getName())); em.refresh(ticket); assertTrue("date not refreshed", newDate.equals(ticket.getDate())); assertTrue("name not refreshed", newName.equals(ticket.getPassenger().getName())); log.debug("merging changes from inverse side"); Ticket ticket2 = new Ticket(ticket.getId()); ticket2.setDate(new GregorianCalendar(2014, Calendar.APRIL, 1).getTime()); Passenger passenger2 = new Passenger(passenger.getId()); passenger2.setName("Rick"); ticket2.setPassenger(passenger2); passenger2.setTicket(ticket2); assertFalse("unexpected date", ticket2.getDate().equals(ticket.getDate())); assertFalse("unexpected name", ticket2.getPassenger().getName().equals(ticket.getPassenger().getName())); ticket = em.merge(ticket2); em.flush(); assertTrue("date not merged", ticket2.getDate().equals(ticket.getDate())); assertTrue("name not merged", ticket2.getPassenger().getName().equals(ticket.getPassenger().getName())); log.debug("delete the entities from the inverse side"); assertNotNull("ticket not found", em.find(Ticket.class, ticket.getId())); assertNotNull("passenger not found", em.find(Passenger.class, ticket.getPassenger().getId())); em.remove(ticket); em.flush(); assertNull("ticket not removed", em.find(Ticket.class, ticket.getId())); assertNull("passenger not removed", em.find(Passenger.class, ticket.getPassenger().getId())); }
From source file:org.kuali.kfs.module.endow.document.service.impl.CurrentTaxLotServiceImpl.java
/** * This method will check the current month and set the calendar to that month * //w w w . j a v a 2 s. c o m * @param month, dayOfMonth month to set the calendar, dayOfMonth day of the month to set to * @return calendar calendar is set to the month selected */ protected void setCalendarWithDays(Calendar calendar, String dayOfMonth) { int dayInMonthToSet; int calendarMonth = calendar.get(Calendar.MONTH); if (StringUtils.equalsIgnoreCase(dayOfMonth, EndowConstants.FrequencyMonthly.MONTH_END)) { // month end for the month so // need to get max days... dayInMonthToSet = checkMaximumDaysInMonth(calendar.get(Calendar.MONTH)); } else { dayInMonthToSet = Integer.parseInt(dayOfMonth); if (dayInMonthToSet > 29 && calendarMonth == Calendar.FEBRUARY) { dayInMonthToSet = checkMaximumDaysInFebruary(); } else if (dayInMonthToSet > 30 && (calendarMonth == Calendar.APRIL || calendarMonth == Calendar.JUNE || calendarMonth == Calendar.SEPTEMBER || calendarMonth == Calendar.NOVEMBER)) { dayInMonthToSet = 30; dayInMonthToSet = checkMaximumDaysInMonth(calendarMonth); } } calendar.set(Calendar.DAY_OF_MONTH, dayInMonthToSet); }
From source file:com.frey.repo.DateUtil.java
/** * ?/*from www . ja v a 2s. co m*/ */ public static int getPassDayOfSeason(Date date) { int day = 0; Date[] seasonDates = getSeasonDate(date); Calendar c = Calendar.getInstance(); c.setTime(date); int month = c.get(Calendar.MONTH); if (month == Calendar.JANUARY || month == Calendar.APRIL || month == Calendar.JULY || month == Calendar.OCTOBER) {// day = getPassDayOfMonth(seasonDates[0]); } else if (month == Calendar.FEBRUARY || month == Calendar.MAY || month == Calendar.AUGUST || month == Calendar.NOVEMBER) {// day = getDayOfMonth(seasonDates[0]) + getPassDayOfMonth(seasonDates[1]); } else if (month == Calendar.MARCH || month == Calendar.JUNE || month == Calendar.SEPTEMBER || month == Calendar.DECEMBER) {// day = getDayOfMonth(seasonDates[0]) + getDayOfMonth(seasonDates[1]) + getPassDayOfMonth(seasonDates[2]); } return day; }
From source file:com.frey.repo.DateUtil.java
/** * ?/*from w w w . j a v a 2 s .c om*/ */ public static Date[] getSeasonDate(Date date) { Date[] season = new Date[3]; Calendar c = Calendar.getInstance(); c.setTime(date); int nSeason = getSeason(date); if (nSeason == 1) {// c.set(Calendar.MONTH, Calendar.JANUARY); season[0] = c.getTime(); c.set(Calendar.MONTH, Calendar.FEBRUARY); season[1] = c.getTime(); c.set(Calendar.MONTH, Calendar.MARCH); season[2] = c.getTime(); } else if (nSeason == 2) {// c.set(Calendar.MONTH, Calendar.APRIL); season[0] = c.getTime(); c.set(Calendar.MONTH, Calendar.MAY); season[1] = c.getTime(); c.set(Calendar.MONTH, Calendar.JUNE); season[2] = c.getTime(); } else if (nSeason == 3) {// c.set(Calendar.MONTH, Calendar.JULY); season[0] = c.getTime(); c.set(Calendar.MONTH, Calendar.AUGUST); season[1] = c.getTime(); c.set(Calendar.MONTH, Calendar.SEPTEMBER); season[2] = c.getTime(); } else if (nSeason == 4) {// c.set(Calendar.MONTH, Calendar.OCTOBER); season[0] = c.getTime(); c.set(Calendar.MONTH, Calendar.NOVEMBER); season[1] = c.getTime(); c.set(Calendar.MONTH, Calendar.DECEMBER); season[2] = c.getTime(); } return season; }
From source file:org.apache.jena.graph.test.TestTypedLiterals.java
public void testDateTime_18() { SimpleTimeZone pdt = new SimpleTimeZone(-8 * 60 * 60 * 1000, "America/Los_Angeles"); // set up rules for daylight savings time pdt.setStartRule(Calendar.APRIL, 1, Calendar.SUNDAY, 2 * 60 * 60 * 1000); pdt.setEndRule(Calendar.OCTOBER, -1, Calendar.SUNDAY, 2 * 60 * 60 * 1000); // create a GregorianCalendar with the Pacific Daylight time zone Calendar ncal = new GregorianCalendar(pdt); ncal.set(2004, 02, 21, 12, 50, 42);//before daylight savings time ncal.set(Calendar.MILLISECOND, 0); //System.err.println("cal is: "+ncal); Literal l1 = m.createTypedLiteral(ncal); assertEquals("DateTime from date", XSDDatatype.XSDdateTime, l1.getDatatype()); assertEquals("DateTime from date", XSDDateTime.class, l1.getValue().getClass()); assertEquals("DateTime from date", "2004-03-21T20:50:42Z", l1.getValue().toString()); //System.err.println("date is: "+ncal.getTime()); ncal = new GregorianCalendar(pdt); ncal.set(2004, 03, 21, 12, 50, 42);//within daylight savings time ncal.set(Calendar.MILLISECOND, 0); //System.err.println("cal is: "+ncal); l1 = m.createTypedLiteral(ncal);//from w w w .j av a 2s .co m assertEquals("DateTime from date", XSDDatatype.XSDdateTime, l1.getDatatype()); assertEquals("DateTime from date", XSDDateTime.class, l1.getValue().getClass()); assertEquals("DateTime from date", "2004-04-21T19:50:42Z", l1.getValue().toString()); //System.err.println("date is: "+ncal.getTime()); }
From source file:org.exist.xquery.modules.mail.SendEmailFunction.java
/** * Returns the current date and time in an RFC822 format, suitable for an email Date Header * * @return RFC822 formated date and time as a String *///from ww w . j av a 2 s . com private String getDateRFC822() { String dateString = new String(); final Calendar rightNow = Calendar.getInstance(); //Day of the week switch (rightNow.get(Calendar.DAY_OF_WEEK)) { case Calendar.MONDAY: dateString = "Mon"; break; case Calendar.TUESDAY: dateString = "Tue"; break; case Calendar.WEDNESDAY: dateString = "Wed"; break; case Calendar.THURSDAY: dateString = "Thu"; break; case Calendar.FRIDAY: dateString = "Fri"; break; case Calendar.SATURDAY: dateString = "Sat"; break; case Calendar.SUNDAY: dateString = "Sun"; break; } dateString += ", "; //Date dateString += rightNow.get(Calendar.DAY_OF_MONTH); dateString += " "; //Month switch (rightNow.get(Calendar.MONTH)) { case Calendar.JANUARY: dateString += "Jan"; break; case Calendar.FEBRUARY: dateString += "Feb"; break; case Calendar.MARCH: dateString += "Mar"; break; case Calendar.APRIL: dateString += "Apr"; break; case Calendar.MAY: dateString += "May"; break; case Calendar.JUNE: dateString += "Jun"; break; case Calendar.JULY: dateString += "Jul"; break; case Calendar.AUGUST: dateString += "Aug"; break; case Calendar.SEPTEMBER: dateString += "Sep"; break; case Calendar.OCTOBER: dateString += "Oct"; break; case Calendar.NOVEMBER: dateString += "Nov"; break; case Calendar.DECEMBER: dateString += "Dec"; break; } dateString += " "; //Year dateString += rightNow.get(Calendar.YEAR); dateString += " "; //Time String tHour = Integer.toString(rightNow.get(Calendar.HOUR_OF_DAY)); if (tHour.length() == 1) { tHour = "0" + tHour; } String tMinute = Integer.toString(rightNow.get(Calendar.MINUTE)); if (tMinute.length() == 1) { tMinute = "0" + tMinute; } String tSecond = Integer.toString(rightNow.get(Calendar.SECOND)); if (tSecond.length() == 1) { tSecond = "0" + tSecond; } dateString += tHour + ":" + tMinute + ":" + tSecond + " "; //TimeZone Correction String tzSign = new String(); String tzHours = new String(); String tzMinutes = new String(); final TimeZone thisTZ = rightNow.getTimeZone(); int tzOffset = thisTZ.getOffset(rightNow.getTime().getTime()); //get timezone offset in milliseconds tzOffset = (tzOffset / 1000); //convert to seconds tzOffset = (tzOffset / 60); //convert to minutes //Sign if (tzOffset > 1) { tzSign = "+"; } else { tzSign = "-"; tzOffset *= -1; } //Calc Hours and Minutes? if (tzOffset >= 60) { //Minutes and Hours tzHours += (tzOffset / 60); //hours // do we need to prepend a 0 if (tzHours.length() == 1) { tzHours = "0" + tzHours; } tzMinutes += (tzOffset % 60); //minutes // do we need to prepend a 0 if (tzMinutes.length() == 1) { tzMinutes = "0" + tzMinutes; } } else { //Just Minutes tzHours = "00"; tzMinutes += tzOffset; // do we need to prepend a 0 if (tzMinutes.length() == 1) { tzMinutes = "0" + tzMinutes; } } dateString += tzSign + tzHours + tzMinutes; return dateString; }
From source file:org.sakaiproject.sitestats.impl.chart.ChartServiceImpl.java
private Map<Integer, String> getMonthNamesMap() { monthNamesMap = new HashMap<Integer, String>(); monthNamesMap.put(Calendar.JANUARY, msgs.getString("mo_jan")); monthNamesMap.put(Calendar.FEBRUARY, msgs.getString("mo_feb")); monthNamesMap.put(Calendar.MARCH, msgs.getString("mo_mar")); monthNamesMap.put(Calendar.APRIL, msgs.getString("mo_apr")); monthNamesMap.put(Calendar.MAY, msgs.getString("mo_may")); monthNamesMap.put(Calendar.JUNE, msgs.getString("mo_jun")); monthNamesMap.put(Calendar.JULY, msgs.getString("mo_jul")); monthNamesMap.put(Calendar.AUGUST, msgs.getString("mo_ago")); monthNamesMap.put(Calendar.SEPTEMBER, msgs.getString("mo_sep")); monthNamesMap.put(Calendar.OCTOBER, msgs.getString("mo_oct")); monthNamesMap.put(Calendar.NOVEMBER, msgs.getString("mo_nov")); monthNamesMap.put(Calendar.DECEMBER, msgs.getString("mo_dec")); return monthNamesMap; }
From source file:org.apache.myfaces.custom.calendar.HtmlCalendarRenderer.java
public static String[] mapMonths(DateFormatSymbols symbols) { String[] months = new String[12]; String[] localeMonths = symbols.getMonths(); months[0] = localeMonths[Calendar.JANUARY]; months[1] = localeMonths[Calendar.FEBRUARY]; months[2] = localeMonths[Calendar.MARCH]; months[3] = localeMonths[Calendar.APRIL]; months[4] = localeMonths[Calendar.MAY]; months[5] = localeMonths[Calendar.JUNE]; months[6] = localeMonths[Calendar.JULY]; months[7] = localeMonths[Calendar.AUGUST]; months[8] = localeMonths[Calendar.SEPTEMBER]; months[9] = localeMonths[Calendar.OCTOBER]; months[10] = localeMonths[Calendar.NOVEMBER]; months[11] = localeMonths[Calendar.DECEMBER]; return months; }
From source file:org.jfree.chart.demo.JFreeChartDemoBase.java
/** * Creates a sample dataset for a Gantt chart. * * @return The dataset.//from www.j a v a 2 s .c om * * @deprecated Moved to the demo applications that require it. */ private static IntervalCategoryDataset createGanttDataset1() { 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)))); 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:org.apache.myfaces.custom.calendar.HtmlCalendarRenderer.java
public static String[] mapShortMonths(DateFormatSymbols symbols) { String[] months = new String[12]; String[] localeMonths = symbols.getShortMonths(); months[0] = localeMonths[Calendar.JANUARY]; months[1] = localeMonths[Calendar.FEBRUARY]; months[2] = localeMonths[Calendar.MARCH]; months[3] = localeMonths[Calendar.APRIL]; months[4] = localeMonths[Calendar.MAY]; months[5] = localeMonths[Calendar.JUNE]; months[6] = localeMonths[Calendar.JULY]; months[7] = localeMonths[Calendar.AUGUST]; months[8] = localeMonths[Calendar.SEPTEMBER]; months[9] = localeMonths[Calendar.OCTOBER]; months[10] = localeMonths[Calendar.NOVEMBER]; months[11] = localeMonths[Calendar.DECEMBER]; return months; }