List of usage examples for java.util Calendar MARCH
int MARCH
To view the source code for java.util Calendar MARCH.
Click Source Link
From source file:com.mycompany.CRMFly.serviceLayer.ClientsServiceImpl.java
@Transactional public Map<Date, Double> getSumsFotDates(Clients client) { Long id = client.getId();/*from w w w .j a va2 s . co m*/ 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.set(Calendar.DAY_OF_MONTH, 1); calendar.set(Calendar.HOUR, 0); calendar.set(Calendar.MINUTE, 0); calendar.set(Calendar.SECOND, 0); calendar.set(Calendar.MILLISECOND, 0); // 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<Contracts> contracts = clientsDAO.getContractsForClient(id); HashMap<Date, Double> sums = new HashMap<Date, Double>(); for (Contracts contract : contracts) { Date date = contract.getBegin_date(); if (date.after(beginningOfQuarter)) thisQuarterSum += contract.getTotalSum(); else if (date.after(QuarterBackOne)) QuarterBackOneSum += contract.getTotalSum(); else if (date.after(QuarterBackTwo)) QuarterBackTwoSum += contract.getTotalSum(); else if (date.after(QuarterBackThree)) QuarterBackThreeSum += contract.getTotalSum(); } sums.put(beginningOfQuarter, thisQuarterSum); sums.put(QuarterBackOne, QuarterBackOneSum); sums.put(QuarterBackTwo, QuarterBackTwoSum); sums.put(QuarterBackThree, QuarterBackThreeSum); return sums; }
From source file:com.mycompany.CRMFly.serviceLayer.ProductsServiceImpl.java
@Transactional public Map<Date, Double> getSumsFotDates(Products product) { Long id = product.getId();/*w w w . jav a 2 s.c o m*/ 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:org.olat.core.util.Formatter.java
License:asdf
/** * Generate a simple date pattern that formats a date using the locale of the formatter * //w ww . j a v a2 s .c o m * @return */ public String getSimpleDatePatternForDate() { Calendar cal = new GregorianCalendar(); cal.set(1999, Calendar.MARCH, 1, 0, 0, 0); Date testDate = cal.getTime(); String formattedDate = formatDate(testDate); formattedDate = formattedDate.replace("1999", "%Y"); formattedDate = formattedDate.replace("99", "%Y"); formattedDate = formattedDate.replace("03", "%m"); formattedDate = formattedDate.replace("3", "%m"); formattedDate = formattedDate.replace("01", "%d"); formattedDate = formattedDate.replace("1", "%d"); return formattedDate; }
From source file:ch.cyberduck.core.ftp.parser.UnixFTPEntryParserTest.java
/** * http://trac.cyberduck.ch/ticket/1076// w ww . ja v a 2 s. c o m * * @ */ @Test public void testSizeWithIndicator() { FTPFileEntryParser parser = new FTPParserSelector().getParser("UNIX"); FTPFile parsed; parsed = parser.parseFTPEntry("-rw-rw-rw- 1 ftp operator 9.0M Mar 22 17:44 Cyberduck-2.7.3.dmg"); assertNotNull(parsed); assertTrue(parsed.isFile()); assertEquals("Cyberduck-2.7.3.dmg", parsed.getName()); assertEquals((long) (9.0 * 1048576), parsed.getSize()); assertEquals(parsed.getUser(), "ftp"); assertEquals(parsed.getGroup(), "operator"); assertNotNull(parsed.getTimestamp()); assertEquals(Calendar.MARCH, parsed.getTimestamp().get(Calendar.MONTH)); assertEquals(22, parsed.getTimestamp().get(Calendar.DAY_OF_MONTH)); parsed = parser.parseFTPEntry("-rw-rw-rw- 1 ftp operator 61.8M Mar 7 18:42 GC Wayfinding pics.zip "); assertNotNull(parsed); assertTrue(parsed.isFile()); assertEquals((long) (61.8 * 1048576), parsed.getSize()); assertEquals("ftp", parsed.getUser()); assertEquals("operator", parsed.getGroup()); assertNotNull(parsed.getTimestamp()); assertEquals(Calendar.MARCH, parsed.getTimestamp().get(Calendar.MONTH)); assertEquals(7, parsed.getTimestamp().get(Calendar.DAY_OF_MONTH)); parsed = parser.parseFTPEntry("-rw-rw-rw- 1 ftp operator 172.4k Mar 7 16:01 HEALY071.TXT "); assertNotNull(parsed); assertTrue(parsed.isFile()); assertEquals((long) (172.4 * 1024), parsed.getSize()); assertEquals(parsed.getUser(), "ftp"); assertEquals(parsed.getGroup(), "operator"); assertNotNull(parsed.getTimestamp()); assertEquals(Calendar.MARCH, parsed.getTimestamp().get(Calendar.MONTH)); assertEquals(7, parsed.getTimestamp().get(Calendar.DAY_OF_MONTH)); }
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 . j av a 2 s . c o m*/ dateJune = calendarJune.getTime(); dateJuly = calendarJuly.getTime(); dateAugust = calendarAugust.getTime(); dateSeptember = calendarSeptember.getTime(); dateOctober = calendarOctober.getTime(); dateNovember = calendarNovember.getTime(); dateDecember = calendarDecember.getTime(); }
From source file:org.olat.core.util.Formatter.java
License:asdf
/** * Generate a simple date pattern that formats a date with time using the locale of the formatter * /*from w w w . j av a2 s .co m*/ * @return */ public String getSimpleDatePatternForDateAndTime() { Calendar cal = new GregorianCalendar(); cal.set(1999, Calendar.MARCH, 1, 4, 5, 0); Date testDate = cal.getTime(); String formattedDate = formatDateAndTime(testDate); formattedDate = formattedDate.replace("1999", "%Y"); formattedDate = formattedDate.replace("99", "%Y"); formattedDate = formattedDate.replace("03", "%m"); formattedDate = formattedDate.replace("3", "%m"); formattedDate = formattedDate.replace("01", "%d"); formattedDate = formattedDate.replace("1", "%d"); formattedDate = formattedDate.replace("04", "%H"); formattedDate = formattedDate.replace("4", "%H"); formattedDate = formattedDate.replace("05", "%M"); formattedDate = formattedDate.replace("5", "%M"); if (formattedDate.endsWith("AM")) { formattedDate = formattedDate.replace("%H", "%I").replace("AM", "%p"); } return formattedDate; }
From source file:org.openmrs.module.radiology.test.RadiologyTestData.java
/** * Convenience method constructing a mock RadiologyOrder for the tests *//*from w w w .j av a 2 s .c om*/ public static RadiologyOrder getMockRadiologyOrder2() { RadiologyOrder mockRadiologyOrder = new RadiologyOrder(); mockRadiologyOrder.setOrderId(2); mockRadiologyOrder.setOrderType(getMockRadiologyOrderType()); mockRadiologyOrder.setPatient(getMockPatient2()); Calendar calendar = Calendar.getInstance(); calendar.set(2015, Calendar.MARCH, 4, 14, 35, 0); mockRadiologyOrder.setScheduledDate(calendar.getTime()); mockRadiologyOrder.setUrgency(Order.Urgency.ON_SCHEDULED_DATE); mockRadiologyOrder.setInstructions("CT ABDOMEN PANCREAS WITHOUT IV CONTRAST"); mockRadiologyOrder.setVoided(false); return mockRadiologyOrder; }
From source file:org.lieuofs.geo.territoire.biz.dao.EtatTerritoireFichierXmlDaoTest.java
@Test public void lireBerlinOuest() { EtatTerritoirePersistant berlinOuest = dao.lire(8209); assertEquals("N OFS Suisse", 8209, berlinOuest.getNumeroOFS()); InfosONUetISO3166 infos = berlinOuest.getInfosISO(); assertNull("Infos Onu Iso non nulles", infos); assertEquals("Forme courte allemande", "Westberlin", berlinOuest.getFormeCourte("de")); assertEquals("Forme courte franaise", "Berlin ouest", berlinOuest.getFormeCourte("fr")); assertEquals("Forme courte italienne", "Berlino Ovest", berlinOuest.getFormeCourte("it")); assertEquals("Forme courte anglaise", "West Berlin", berlinOuest.getFormeCourte("en")); assertNull("Dsignation allemande", berlinOuest.getDesignationOfficielle("de")); assertNull("Dsignation franaise", berlinOuest.getDesignationOfficielle("fr")); assertNull("Dsignation italienne", berlinOuest.getDesignationOfficielle("it")); assertEquals("Continent", 1, berlinOuest.getNumContinent()); assertEquals("Rgion", 3, berlinOuest.getNumRegion()); assertFalse("Est un tat", berlinOuest.isEtat()); assertEquals("Berlin ouest est rattach l'Allemagne", 8207, berlinOuest.getNumEtatRattachement()); assertFalse("Est membre de l'ONU", berlinOuest.isMembreONU()); assertNull("Pas de date d'entre car pas membre", berlinOuest.getDateEntreeONU()); assertFalse("Pas reconnu par la Suisse", berlinOuest.isReconnuSuisse()); assertNull("Date reconnaissance Suisse", berlinOuest.getDateReconnaissance()); assertNotNull("Remarque en allemand", berlinOuest.getRemarque("de")); assertNotNull("Remarque en franais", berlinOuest.getRemarque("fr")); assertNotNull("Remarque en italien", berlinOuest.getRemarque("it")); assertFalse("valide", berlinOuest.isValide()); Calendar cal = Calendar.getInstance(); cal.setTime(berlinOuest.getDateDernierChangement()); assertEquals("Jour dernier changement", 5, cal.get(Calendar.DATE)); assertEquals("mois dernier changement", Calendar.MARCH, cal.get(Calendar.MONTH)); assertEquals("anne dernier changement", 2008, cal.get(Calendar.YEAR)); }
From source file:edu.northwestern.bioinformatics.studycalendar.web.schedule.ScheduleActivityCommandTest.java
public void testEventSpecificModesForConditionalEvent() throws Exception { ScheduledActivity conditionalEvent = Fixtures.createConditionalEvent("ABC", 2003, Calendar.MARCH, 13); conditionalEvent.changeState(ScheduledActivityMode.SCHEDULED .createStateInstance(DateUtils.createDate(2003, Calendar.MARCH, 13), "Schedule")); command.setEvent(conditionalEvent);//from w w w . ja va 2s . c om command.setNewMode(ScheduledActivityMode.SCHEDULED); replayMocks(); Collection<ScheduledActivityMode> collection = command.getEventSpecificMode(); System.out.println("collection " + collection); assertEquals("Wrong number of modes", 4, collection.size()); assertNotContains("Wrong state available", collection, ScheduledActivityMode.CANCELED); assertNotContains("Wrong state available", collection, ScheduledActivityMode.CONDITIONAL); }
From source file:org.openmrs.module.reporting.common.DateUtilTest.java
@Test @Verifies(value = "should correctly handle daylight savings time", method = "getTimespan(Date,Date,null)") public void getTimespan_shouldCorrectlyHandleDaylightSavingsTime() throws Exception { // USA has daylight saving time. // in 2009 DST started March 8 and ended November 1 Calendar cal = new GregorianCalendar(Locale.US); cal.set(Calendar.YEAR, 2009); cal.set(Calendar.DAY_OF_MONTH, 25); cal.set(Calendar.MONTH, Calendar.FEBRUARY); Date feb25 = cal.getTime();//from w ww .j av a2 s . c o m cal.set(Calendar.MONTH, Calendar.MARCH); Date mar25 = cal.getTime(); cal.set(Calendar.MONTH, Calendar.APRIL); Date apr25 = cal.getTime(); cal.set(Calendar.MONTH, Calendar.OCTOBER); Date oct25 = cal.getTime(); cal.set(Calendar.MONTH, Calendar.NOVEMBER); Date nov25 = cal.getTime(); cal.set(Calendar.MONTH, Calendar.DECEMBER); Date dec25 = cal.getTime(); testMessage("reporting.dateUtil.oneMonth reporting.dateUtil.ago", DateUtil.getTimespan(mar25, feb25)); testMessage("reporting.dateUtil.oneMonth reporting.dateUtil.ago", DateUtil.getTimespan(apr25, mar25)); testMessage("reporting.dateUtil.oneMonth reporting.dateUtil.ago", DateUtil.getTimespan(nov25, oct25)); testMessage("reporting.dateUtil.oneMonth reporting.dateUtil.ago", DateUtil.getTimespan(dec25, nov25)); }