List of usage examples for java.util Calendar DATE
int DATE
To view the source code for java.util Calendar DATE.
Click Source Link
get
and set
indicating the day of the month. From source file:org.openmrs.module.kenyaemr.calculation.library.hiv.DecliningCd4CalculationTest.java
/** * @see DecliningCd4Calculation#evaluate(java.util.Collection, java.util.Map, org.openmrs.calculation.patient.PatientCalculationContext) * @verifies determine whether patients have a decline in CD4 *///from www . ja va 2 s .c o m @Test public void evaluate_shouldDetermineWhetherPatientsHasDeclinedCD4() throws Exception { Program hivProgram = MetadataUtils.existing(Program.class, HivMetadata._Program.HIV); // Enroll patients #6, #7 and #8 in the HIV Program TestUtils.enrollInProgram(TestUtils.getPatient(6), hivProgram, new Date()); TestUtils.enrollInProgram(TestUtils.getPatient(7), hivProgram, new Date()); TestUtils.enrollInProgram(TestUtils.getPatient(8), hivProgram, new Date()); // Give patients #7 and #8 a CD4 count 180 days ago Concept cd4 = Dictionary.getConcept(Dictionary.CD4_COUNT); Calendar calendar = Calendar.getInstance(); calendar.add(Calendar.DATE, -180); TestUtils.saveObs(TestUtils.getPatient(7), cd4, 123d, calendar.getTime()); TestUtils.saveObs(TestUtils.getPatient(8), cd4, 123d, calendar.getTime()); // Give patient #7 a lower CD4 count today TestUtils.saveObs(TestUtils.getPatient(7), cd4, 120d, new Date()); // Give patient #8 a higher CD4 count today TestUtils.saveObs(TestUtils.getPatient(8), cd4, 126d, new Date()); List<Integer> ptIds = Arrays.asList(6, 7, 8, 999); CalculationResultMap resultMap = new DecliningCd4Calculation().evaluate(ptIds, null, Context.getService(PatientCalculationService.class).createCalculationContext()); Assert.assertFalse((Boolean) resultMap.get(6).getValue()); //in Hiv program but without cd4 i.e needs cd4 Assert.assertTrue((Boolean) resultMap.get(7).getValue()); // has decline in CD4 Assert.assertFalse((Boolean) resultMap.get(8).getValue()); // has increase in CD4 Assert.assertFalse((Boolean) resultMap.get(999).getValue()); // not in HIV Program }
From source file:Main.java
/** * Check if the given date represents the given date and month. * * @param cal// w ww . j a va 2s . co m * The Calendar object representing date to check. * @param date * The date. * @param month * The month. * @return true if they match, false otherwise. */ private static boolean checkDate(Calendar cal, int date, int month) { return cal.get(Calendar.DATE) == date && cal.get(Calendar.MONTH) == month; }
From source file:com.yukthi.validators.LessThanValidator.java
@Override public boolean isValid(Object bean, Object fieldValue) { Object otherValue = null;//ww w . j av a 2 s. com try { otherValue = PropertyUtils.getSimpleProperty(bean, lessThanField); } catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException ex) { throw new IllegalStateException("Invalid/inaccessible property \"" + lessThanField + "\" specified with matchWith validator in bean: " + bean.getClass().getName()); } if (fieldValue == null || otherValue == null || !fieldValue.getClass().equals(otherValue.getClass())) { return true; } if (otherValue instanceof Number) { return (((Number) fieldValue).doubleValue() < ((Number) otherValue).doubleValue()); } if (otherValue instanceof Date) { Date dateValue = DateUtils.truncate((Date) fieldValue, Calendar.DATE); Date otherDateValue = DateUtils.truncate((Date) otherValue, Calendar.DATE); return (dateValue.compareTo(otherDateValue) < 0); } return true; }
From source file:com.seajas.search.attender.service.feed.FeedService.java
/** * Create a feed from the given profile and base URL. * /* w w w . j a va 2 s . c o m*/ * @param profile * @param notificationType * @param totalResults * @param baseUrl * @param locale * @return SyndFeed */ public SyndFeed createFeed(final Profile profile, final NotificationType notificationType, final Integer totalResults, final String baseUrl, final Locale locale) { // Round up the search parameters and taxonomies into a concise parameter list Map<String, String> searchParameters = InterfaceQueryUtils.combineParametersAndTaxonomies( profile.getSearchParametersMap(), profile.getTaxonomyIdentifierNumbers()); // Determine the start date on the notification type Calendar calendar = new GregorianCalendar(); Date endDate = calendar.getTime(); calendar.add(Calendar.DATE, notificationType.equals(NotificationType.Weekly) ? -7 : -1); Date startDate = calendar.getTime(); // Determine the start date depending on the user's last notification date, and retrieve the results Integer actualResults = totalResults != null ? (maximumResults == 0 ? totalResults : Math.min(totalResults, maximumResults)) : defaultResults; List<SearchResult> searchResults = searchService.performSearch(profile.getQuery(), startDate, endDate, searchParameters, actualResults, locale.getLanguage()); // Create the actual feed SyndFeed feed = new SyndFeedImpl(); feed.setAuthor(messageSource.getMessage("feed.author", new String[] {}, locale)); feed.setTitle(messageSource.getMessage("feed.title", new String[] {}, locale)); feed.setDescription( messageSource.getMessage("feed.description", new String[] { String.valueOf(searchResults.size()), profile.getQuery() != null ? profile.getQuery() : "" }, locale)); feed.setLink(baseUrl); // Add the actual entries List<SyndEntry> entries = new ArrayList<SyndEntry>(searchResults.size()); for (SearchResult searchResult : searchResults) entries.add(searchResult.toSyndEntry()); feed.setEntries(entries); return feed; }
From source file:org.lieuofs.commune.biz.GestionCommuneTest.java
@Test public void rechercheLaTourDeTreme() { // numro OFS 2154 : la Tour de Trme a t incluse dans Bulle le 1er janvier 2006 CommuneCritere critere = new CommuneCritere(); critere.setCodeCanton("FR"); Calendar cal = Calendar.getInstance(); cal.setTimeZone(TimeZone.getTimeZone("Europe/Zurich")); cal.set(2005, Calendar.DECEMBER, 31); critere.setDateValidite(cal.getTime()); List<ICommuneSuisse> communes = gestionnaire.rechercher(critere); boolean trouve = false; for (ICommuneSuisse commune : communes) { if (2154 == commune.getNumeroOFS()) { trouve = true;// w w w .ja va2 s . c o m break; } } assertTrue("Le 31 dcembre 2005 la Tour-de-Trme est une commune fribourgeoise", trouve); cal.add(Calendar.DATE, 1); critere.setDateValidite(cal.getTime()); communes = gestionnaire.rechercher(critere); trouve = false; for (ICommuneSuisse commune : communes) { if (2154 == commune.getNumeroOFS()) { trouve = true; break; } } assertTrue("Le 1er janvier 2006 la Tour-de-Trme n'est plus une commune fribourgeoise", !trouve); }
From source file:org.openmrs.module.accessmonitor.web.controller.AccessMonitorOrderController.java
@RequestMapping(value = "/module/accessmonitor/order", method = RequestMethod.GET) public void person(ModelMap model, HttpServletRequest request) { offset = 0;//from w ww . j a v a 2 s. c om // parse them to Date, null is acceptable DateFormat format = new SimpleDateFormat("MM/dd/yyyy"); // Get the from date and to date Date to = null; Date from = null; try { from = format.parse(request.getParameter("datepickerFrom")); } catch (Exception e) { //System.out.println("======From Date Empty======="); } try { to = format.parse(request.getParameter("datepickerTo")); } catch (Exception e) { //System.out.println("======To Date Empty======="); } // get all the records in the date range orderAccessData = ((OrderAccessService) Context.getService(OrderAccessService.class)) .getOrderAccessesByAccessDateOrderByPatientId(from, to); if (orderAccessData == null) { orderAccessData = new ArrayList<OrderServiceAccess>(); } // get date for small graph Date toSmall = to; Date fromSmall = null; Calendar calendar = Calendar.getInstance(); calendar.add(Calendar.DATE, 1); if (toSmall == null) { toSmall = calendar.getTime(); } else { calendar.setTime(toSmall); } calendar.add(Calendar.DATE, -DAYNUM); fromSmall = calendar.getTime(); List<String> dateStrings = new ArrayList<String>(); for (int i = 0; i < DAYNUM; i++) { if (i == DAYNUM - 1) { dateStrings.add(format.format(toSmall)); } else if (i == 0) { dateStrings.add(format.format(fromSmall)); } else { dateStrings.add(""); } } ArrayList<ArrayList<Integer>> tooltip = new ArrayList<ArrayList<Integer>>(); tooltip.add(new ArrayList<Integer>()); for (int j = 0; j < SHOWNUM + 1; j++) { tooltip.get(0).add(1000 + j); } for (int i = 1; i < DAYNUM + 1; i++) { tooltip.add(new ArrayList<Integer>()); tooltip.get(i).add(i); for (int j = 0; j < SHOWNUM; j++) { tooltip.get(i).add(0); } } ArrayList<String> patientIds = new ArrayList<String>(); ArrayList<Integer> patientCounts = new ArrayList<Integer>(); for (OrderServiceAccess oa : orderAccessData) { // data for big graph String idString = (oa.getPatientId() == null) ? "No ID" : oa.getPatientId().toString(); int index = patientIds.indexOf(idString); if (index < 0) { if (patientIds.size() >= SHOWNUM) break; patientIds.add(idString); patientCounts.add(1); index = patientIds.size() - 1;//index = personIds.indexOf(idString); } else { patientCounts.set(index, patientCounts.get(index) + 1); } // data for small graph if (oa.getAccessDate().after(fromSmall) && oa.getAccessDate().before(toSmall)) { int index2 = (int) ((oa.getAccessDate().getTime() - fromSmall.getTime()) / (1000 * 60 * 60 * 24)); if (index2 < DAYNUM && index2 >= 0) tooltip.get(index2 + 1).set(index + 1, tooltip.get(index2 + 1).get(index + 1) + 1); } } String patientIdString = JSONValue.toJSONString(patientIds); String patientCountString = JSONValue.toJSONString(patientCounts); String dateSmallString = JSONValue.toJSONString(dateStrings); String tooltipdata = JSONValue.toJSONString(tooltip); model.addAttribute("patientIds", patientIdString); model.addAttribute("patientCounts", patientCountString); model.addAttribute("dateSmallString", dateSmallString); model.addAttribute("tooltipdata", tooltipdata); model.addAttribute("user", Context.getAuthenticatedUser()); //model.addAttribute("tables1", orderAccessData); //model.addAttribute("dateSmall", dateStrings); model.addAttribute("currentoffset", String.valueOf(offset)); }
From source file:org.openmrs.module.accessmonitor.web.controller.AccessMonitorPersonController.java
@RequestMapping(value = "/module/accessmonitor/person", method = RequestMethod.GET) public void person(ModelMap model, HttpServletRequest request) { offset = 0;//from w w w .j a v a 2 s .c o m // parse them to Date, null is acceptabl DateFormat format = new SimpleDateFormat("MM/dd/yyyy"); // Get the from date and to date Date to = null; Date from = null; try { from = format.parse(request.getParameter("datepickerFrom")); } catch (Exception e) { //System.out.println("======From Date Empty======="); } try { to = format.parse(request.getParameter("datepickerTo")); } catch (Exception e) { //System.out.println("======To Date Empty======="); } // get all the records in the date range personAccessData = ((PersonAccessService) Context.getService(PersonAccessService.class)) .getPersonAccessesByAccessDateOrderByPersonId(from, to); if (personAccessData == null) { personAccessData = new ArrayList<PersonServiceAccess>(); } // get date for small graph Date toSmall = to; Date fromSmall = null; Calendar calendar = Calendar.getInstance(); calendar.add(Calendar.DATE, 1); if (toSmall == null) { toSmall = calendar.getTime(); } else { calendar.setTime(toSmall); } calendar.add(Calendar.DATE, -DAYNUM); fromSmall = calendar.getTime(); List<String> dateStrings = new ArrayList<String>(); for (int i = 0; i < DAYNUM; i++) { if (i == DAYNUM - 1) { dateStrings.add(format.format(toSmall)); } else if (i == 0) { dateStrings.add(format.format(fromSmall)); } else { dateStrings.add(""); } } ArrayList<ArrayList<Integer>> tooltip = new ArrayList<ArrayList<Integer>>(); tooltip.add(new ArrayList<Integer>()); for (int j = 0; j < SHOWNUM + 1; j++) { tooltip.get(0).add(1000 + j); } for (int i = 1; i < DAYNUM + 1; i++) { tooltip.add(new ArrayList<Integer>()); tooltip.get(i).add(i); for (int j = 0; j < SHOWNUM; j++) { tooltip.get(i).add(0); } } ArrayList<String> personIds = new ArrayList<String>(); ArrayList<Integer> personCounts = new ArrayList<Integer>(); for (PersonServiceAccess pa : personAccessData) { // data for big graph String idString = (pa.getPersonId() == null) ? "No ID" : pa.getPersonId().toString(); int index = personIds.indexOf(idString); if (index < 0) { if (personIds.size() >= SHOWNUM) break; personIds.add(idString); personCounts.add(1); index = personIds.size() - 1;//index = personIds.indexOf(idString); } else { personCounts.set(index, personCounts.get(index) + 1); } // data for small graph if (pa.getAccessDate().after(fromSmall) && pa.getAccessDate().before(toSmall)) { int index2 = (int) ((pa.getAccessDate().getTime() - fromSmall.getTime()) / (1000 * 60 * 60 * 24)); if (index2 < DAYNUM && index2 >= 0) tooltip.get(index2 + 1).set(index + 1, tooltip.get(index2 + 1).get(index + 1) + 1); } } String personIdString = JSONValue.toJSONString(personIds); String personCountString = JSONValue.toJSONString(personCounts); String dateSmallString = JSONValue.toJSONString(dateStrings); String tooltipdata = JSONValue.toJSONString(tooltip); model.addAttribute("personIds", personIdString); model.addAttribute("personCounts", personCountString); model.addAttribute("dateSmallString", dateSmallString); model.addAttribute("tooltipdata", tooltipdata); model.addAttribute("user", Context.getAuthenticatedUser()); //model.addAttribute("tables1", personAccessData); //model.addAttribute("dateSmall", dateStrings); model.addAttribute("currentoffset", String.valueOf(offset)); }
From source file:org.lieuofs.geo.territoire.biz.dao.EtatTerritoireFichierXmlDaoTest.java
@Test public void lireSuisse() { EtatTerritoirePersistant suisse = dao.lire(8100); assertEquals("N OFS Suisse", 8100, suisse.getNumeroOFS()); InfosONUetISO3166 infos = suisse.getInfosISO(); assertNotNull("Infos Onu Iso non nulles", infos); assertEquals("Info Onu numrique", 756, infos.getCodeNumeriqueONU()); assertEquals("Info ISO alpha 2", "CH", infos.getCodeIsoAlpha2()); assertEquals("Info ISO alpha 3", "CHE", infos.getCodeIsoAlpha3()); assertEquals("Forme courte allemande", "Schweiz", suisse.getFormeCourte("de")); assertEquals("Forme courte franaise", "Suisse", suisse.getFormeCourte("fr")); assertEquals("Forme courte italienne", "Svizzera", suisse.getFormeCourte("it")); assertEquals("Forme courte anglaise", "Switzerland", suisse.getFormeCourte("en")); assertEquals("Dsignation allemande", "Schweizerische Eidgenossenschaft", suisse.getDesignationOfficielle("de")); assertEquals("Dsignation franaise", "Confdration suisse", suisse.getDesignationOfficielle("fr")); assertEquals("Dsignation italienne", "Confederazione svizzera", suisse.getDesignationOfficielle("it")); assertEquals("Continent", 1, suisse.getNumContinent()); assertEquals("Rgion", 3, suisse.getNumRegion()); assertTrue("Est un tat", suisse.isEtat()); assertEquals("La Suisse est un tat : pas de rattachement", 0, suisse.getNumEtatRattachement()); assertTrue("Est membre de l'ONU", suisse.isMembreONU()); Calendar cal = Calendar.getInstance(); cal.setTime(suisse.getDateEntreeONU()); assertEquals("Jour entre ONU", 10, cal.get(Calendar.DATE)); assertEquals("mois entre ONU", Calendar.SEPTEMBER, cal.get(Calendar.MONTH)); assertEquals("anne entre ONU", 2002, cal.get(Calendar.YEAR)); assertFalse("Non reconnu par la Suisse", suisse.isReconnuSuisse()); assertNull("Date reconnaissance Suisse", suisse.getDateReconnaissance()); assertNull("Remarque en allemand", suisse.getRemarque("de")); assertNull("Remarque en franais", suisse.getRemarque("fr")); assertNull("Remarque en italien", suisse.getRemarque("it")); assertTrue("valide", suisse.isValide()); cal.setTime(suisse.getDateDernierChangement()); assertEquals("Jour dernier changement", 1, cal.get(Calendar.DATE)); assertEquals("mois dernier changement", Calendar.JANUARY, cal.get(Calendar.MONTH)); assertEquals("anne dernier changement", 2008, cal.get(Calendar.YEAR)); }
From source file:com.reizes.shiva.utils.CommonUtil.java
/** * ? .//w w w . j av a 2 s.c o m */ public static Date getMinus1Day(Date date) { if (date == null) { return null; } Calendar cal = Calendar.getInstance(); cal.setTime(date); cal.add(Calendar.DATE, -1); return cal.getTime(); }
From source file:com.sesnu.orion.web.controller.DuLicenseController.java
private DuLicense setExpireDate(DuLicense lic) { Integer licDays = Integer.parseInt(miscDao.getByName("License validity duration(days-#)").getValue()); Calendar c = Calendar.getInstance(); c.setTime(lic.getIssueDate());/* w w w .j a v a 2 s . com*/ c.add(Calendar.DATE, licDays); lic.setExpireDate(c.getTime()); return lic; }