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:com.yukthi.validators.LessThanEqualsValidator.java
@Override public boolean isValid(Object bean, Object fieldValue) { //fetch other field value Object otherValue = null;//from w w w. j a v a 2 s .co m 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 value is null or of different data type if (fieldValue == null || otherValue == null || !fieldValue.getClass().equals(otherValue.getClass())) { return true; } //number comparison if (otherValue instanceof Number) { return (((Number) fieldValue).doubleValue() <= ((Number) otherValue).doubleValue()); } //date comparison 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:org.openmrs.module.kenyaemr.calculation.library.hiv.NeedsCd4TestCalculationTest.java
/** * @see NeedsCd4TestCalculation#evaluate(java.util.Collection, java.util.Map, org.openmrs.calculation.patient.PatientCalculationContext) * @verifies determine whether patients need a CD4 */// ww w .j av a 2 s .co m @Test public void evaluate_shouldDetermineWhetherPatientsNeedsCD4() 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(2), hivProgram, new Date()); 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 patient #7 a recent CD4 result obs Concept cd4 = Dictionary.getConcept(Dictionary.CD4_COUNT); TestUtils.saveObs(TestUtils.getPatient(7), cd4, 123d, new Date()); // Give patient #8 a CD4 result obs from a year ago Calendar calendar = Calendar.getInstance(); calendar.add(Calendar.DATE, -360); TestUtils.saveObs(TestUtils.getPatient(8), cd4, 123d, calendar.getTime()); //give patient #2 a recent CD4% result obs Concept cd4Percent = Dictionary.getConcept(Dictionary.CD4_PERCENT); TestUtils.saveObs(TestUtils.getPatient(2), cd4Percent, 80d, new Date()); // Give patient #6 a CD4% result obs from a year ago Calendar calendarP = Calendar.getInstance(); calendarP.add(Calendar.DATE, -200); TestUtils.saveObs(TestUtils.getPatient(6), cd4Percent, 89d, calendarP.getTime()); List<Integer> ptIds = Arrays.asList(2, 6, 7, 8, 999); CalculationResultMap resultMap = new NeedsCd4TestCalculation().evaluate(ptIds, null, Context.getService(PatientCalculationService.class).createCalculationContext()); Assert.assertFalse((Boolean) resultMap.get(2).getValue()); // has recent CD4% Assert.assertTrue((Boolean) resultMap.get(6).getValue()); // has old CD4% Assert.assertFalse((Boolean) resultMap.get(7).getValue()); // has recent CD4 Assert.assertTrue((Boolean) resultMap.get(8).getValue()); // has old CD4 Assert.assertFalse((Boolean) resultMap.get(999).getValue()); // not in HIV Program }
From source file:CalendarUtilsTest.java
/** * Tests various values with the round method *//*w w w . j ava 2 s . co m*/ public void testRound() throws Exception { assertEquals("round year-1 failed", new Date("2002 January 1"), CalendarUtils.round(date1, Calendar.YEAR)); assertEquals("round year-2 failed", new Date("2002 January 1"), CalendarUtils.round(date2, Calendar.YEAR)); assertEquals("round month-1 failed", new Date("2002 February 1"), CalendarUtils.round(date1, Calendar.MONTH)); assertEquals("round month-2 failed", new Date("2001 December 1"), CalendarUtils.round(date2, Calendar.MONTH)); assertEquals("round semimonth-1 failed", new Date("2002 February 16"), CalendarUtils.round(date1, CalendarUtils.SEMI_MONTH)); assertEquals("round semimonth-2 failed", new Date("2001 November 16"), CalendarUtils.round(date2, CalendarUtils.SEMI_MONTH)); assertEquals("round date-1 failed", new Date("2002 February 13"), CalendarUtils.round(date1, Calendar.DATE)); assertEquals("round date-2 failed", new Date("2001 November 18"), CalendarUtils.round(date2, Calendar.DATE)); assertEquals("round hour-1 failed", parser.parse("February 12, 2002 13:00:00.000"), CalendarUtils.round(date1, Calendar.HOUR)); assertEquals("round hour-2 failed", parser.parse("November 18, 2001 1:00:00.000"), CalendarUtils.round(date2, Calendar.HOUR)); assertEquals("round minute-1 failed", parser.parse("February 12, 2002 12:35:00.000"), CalendarUtils.round(date1, Calendar.MINUTE)); assertEquals("round minute-2 failed", parser.parse("November 18, 2001 1:23:00.000"), CalendarUtils.round(date2, Calendar.MINUTE)); assertEquals("round second-1 failed", parser.parse("February 12, 2002 12:34:57.000"), CalendarUtils.round(date1, Calendar.SECOND)); assertEquals("round second-2 failed", parser.parse("November 18, 2001 1:23:11.000"), CalendarUtils.round(date2, Calendar.SECOND)); }
From source file:com.yukthi.validators.GreaterThanValidator.java
@Override public boolean isValid(Object bean, Object fieldValue) { //obtain field value to be compared Object otherValue = null;/*ww w . j a v a 2s .c o m*/ try { otherValue = PropertyUtils.getSimpleProperty(bean, greaterThanField); } catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException ex) { throw new IllegalStateException("Invalid/inaccessible property \"" + greaterThanField + "\" specified with matchWith validator in bean: " + bean.getClass().getName()); } //if other value is null or of different type if (fieldValue == null || otherValue == null || !fieldValue.getClass().equals(otherValue.getClass())) { return true; } //number comparison if (otherValue instanceof Number) { return (((Number) fieldValue).doubleValue() > ((Number) otherValue).doubleValue()); } //date comparison 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:nz.co.jsrsolutions.ds3.command.UpdateExchangeQuotesCommand.java
public boolean execute(Context context) throws Exception { logger.info("Executing: updateexchangequotes"); final String exchange = (String) context.get(CommandContext.EXCHANGE_KEY); if (exchange == null) { throw new CommandException("Must supply --exchange [exchangecode]"); }/*from w ww . ja v a 2 s . c om*/ long nQuotesWritten = 0; final int availableMonths = _eodDataProvider.getExchangeMonths(exchange); final String[] symbols = _eodDataSink.readExchangeSymbols(exchange); if (symbols == null) { logger.info("No symbols associated with this exchange..."); return false; } final Collection<Future<Long>> futures = new LinkedList<Future<Long>>(); for (String symbol : symbols) { final Calendar firstAvailableDateTime = Calendar.getInstance(); if (availableMonths > 0) { firstAvailableDateTime.add(Calendar.MONTH, -1 * availableMonths); firstAvailableDateTime.add(Calendar.DATE, 1); } final Calendar today = Calendar.getInstance(); final Range<Calendar> sinkRange = _eodDataSink.readExchangeSymbolDateRange(exchange, symbol); final ArrayList<Range<Calendar>> requestRangesList = new ArrayList<Range<Calendar>>(2); if (sinkRange != null) { if (firstAvailableDateTime.compareTo(sinkRange.getLower()) < 0) { // In this implementation we can't ask for this! /* final Calendar upper = (Calendar) sinkRange.getLower().clone(); upper.add(Calendar.DATE, -1); final Calendar lower = (firstAvailableDateTime.compareTo(upper) < 0) ? firstAvailableDateTime : upper; requestRangesList.add(new Range<Calendar>(firstAvailableDateTime, upper)); // TODO: implement prepend in Hd5 Sink */ } if (today.compareTo(sinkRange.getUpper()) > 0) { final Calendar lower = (Calendar) sinkRange.getUpper().clone(); lower.add(Calendar.DATE, 1); // TODO: fix this by observing timezones final Calendar upper = (Calendar) today.clone(); // cheat for now with upper bound on today (anywhere in the world!) upper.add(Calendar.DATE, 1); requestRangesList.add(new Range<Calendar>(lower, upper)); } } else { requestRangesList.add(new Range<Calendar>(firstAvailableDateTime, today)); } for (Range<Calendar> requestRange : requestRangesList) { if (logger.isInfoEnabled()) { StringBuffer logMessageBuffer = new StringBuffer(); logMessageBuffer.setLength(0); logMessageBuffer.append(" Attempting to retrieve quotes on [ "); logMessageBuffer.append(exchange); logMessageBuffer.append(" ] for [ "); logMessageBuffer.append(symbol); logMessageBuffer.append(" ] between [ "); logMessageBuffer.append(requestRange.getLower().getTime().toString()); logMessageBuffer.append(" ] and [ "); logMessageBuffer.append(requestRange.getUpper().getTime().toString()); logMessageBuffer.append(" ] "); logger.info(logMessageBuffer.toString()); } try { futures.add(_executorService.submit(new ReadWriteQuotesTask(_eodDataProvider, _eodDataSink, exchange, symbol, requestRange.getLower(), requestRange.getUpper()))); } catch (Exception e) { logger.error("Task submission failed", e); } } } for (Future<Long> future : futures) { try { nQuotesWritten += future.get(); } catch (ExecutionException e) { logger.error("Execution exception: ", e); } catch (InterruptedException e) { logger.error("Interrupted exception: ", e); } } if (_emailService != null) { final StringBuffer subjectBuffer = new StringBuffer(); subjectBuffer.append("Updated quotes on "); subjectBuffer.append(exchange); final StringBuffer messageBuffer = new StringBuffer(); messageBuffer.append("Wrote "); messageBuffer.append(nQuotesWritten); messageBuffer.append(" quotes over "); messageBuffer.append(symbols.length); messageBuffer.append(" symbols "); _emailService.send(subjectBuffer.toString(), messageBuffer.toString()); } return false; }
From source file:com.controlj.experiment.bulktrend.trendclient.TrendClient.java
public static Calendar getYesterday() { Calendar today = new GregorianCalendar(); today.add(Calendar.DATE, -1); Calendar result = new GregorianCalendar(today.get(Calendar.YEAR), today.get(Calendar.MONTH), today.get(Calendar.DAY_OF_MONTH)); return result; }
From source file:uta.ak.TestNodejsInterface.java
private void testFromDB() throws Exception { Connection con = null; //MYSQL Class.forName("com.mysql.jdbc.Driver").newInstance(); //MYSQL con = DriverManager.getConnection("jdbc:mysql://127.0.0.1:3306/USTTMP", "root", "root.123"); //MYSQL System.out.println("connection yes"); System.out.println("query records..."); String querySQL = "SELECT" + " * " + "FROM " + " c_rawtext " + "WHERE " + "tag like 'function%'"; PreparedStatement preparedStmt = con.prepareStatement(querySQL); ResultSet rs = preparedStmt.executeQuery(); Set<String> filterDupSet = new HashSet<>(); Calendar cal = Calendar.getInstance(); cal.add(Calendar.DATE, 1); SimpleDateFormat format1 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); while (rs.next()) { System.out.println(rs.getString("title") + " " + rs.getString("text") + " " + rs.getString("tag")); String formattedDate = format1.format(new Date()); String interfaceMsg = "<message> " + " <title> " + rs.getString("title") + " </title> " + " <text> " + StringEscapeUtils.escapeXml10(rs.getString("text")) + " </text> " + " <textCreatetime> " + formattedDate + " </textCreatetime> " + " <tag> " + rs.getString("tag") + " </tag> " + "</message>"; // String restUrl="http://192.168.0.103:8991/usttmp_textreceiver/rest/addText"; String restUrl = "http://127.0.0.1:8991/usttmp_textreceiver/rest/addText"; RestTemplate restTemplate = new RestTemplate(); HttpHeaders headers = new HttpHeaders(); headers.setContentType(MediaType.TEXT_XML); headers.setAccept(Arrays.asList(MediaType.TEXT_XML)); // headers.setContentLength(); HttpEntity<String> entity = new HttpEntity<String>(interfaceMsg, headers); ResponseEntity<String> result = restTemplate.exchange(restUrl, HttpMethod.POST, entity, String.class); System.out.println(result.getBody()); }// w w w.j ava2 s . co m }
From source file:com.esd.ps.RegListController.java
/** * ?/* w ww . jav a2s.c o m*/ * * @param session * @param page * @param beginDateate * @param endDateate * @return */ @RequestMapping(value = "/regList", method = RequestMethod.POST) @ResponseBody public Map<String, Object> regListPost(HttpSession session, int page, String beginDate, String endDate) { logger.debug("beginDateate:{},endDateate:{}", beginDate, endDate); Map<String, Object> map = new HashMap<String, Object>(); int districtId = Integer.parseInt(session.getAttribute(Constants.ID).toString()); List<RegistrationTrans> list = new ArrayList<RegistrationTrans>(); if (endDate.trim().length() > 0 || !endDate.isEmpty()) { try { SimpleDateFormat sdf1 = new SimpleDateFormat(Constants.DATE_FORMAT); SimpleDateFormat formatter = new SimpleDateFormat(Constants.DATE_FORMAT_HAVE_LINE); Date myDate = formatter.parse(endDate); Calendar c = Calendar.getInstance(); c.setTime(myDate); c.add(Calendar.DATE, 1); myDate = c.getTime(); endDate = sdf1.format(myDate); } catch (ParseException e) { e.printStackTrace(); } } int totle = registrationService.getCountByTimeAndDistrictId(districtId, beginDate, endDate); if (totle == 0) { map.clear(); map.put(Constants.TOTLE, totle); map.put(Constants.TOTLE_PAGE, Math.ceil((double) totle / (double) Constants.ROW)); map.put(Constants.LIST, list); return map; } List<Registration> regList = registrationService.getByTimeAndDistrictId(districtId, beginDate, endDate, page, Constants.ROW); SimpleDateFormat sdf = new SimpleDateFormat(Constants.DATETIME_FORMAT); for (Iterator<Registration> iterator = regList.iterator(); iterator.hasNext();) { Registration registration = (Registration) iterator.next(); RegistrationTrans rt = new RegistrationTrans(); rt.setAddress(registration.getAddress()); rt.setCard(registration.getCard()); rt.setCreateTime(sdf.format(registration.getCreateTime())); rt.setDes(registration.getDes()); rt.setName(registration.getName()); rt.setPhone(registration.getPhone()); rt.setQq(registration.getQq()); list.add(rt); } map.clear(); map.put(Constants.TOTLE, totle); map.put(Constants.TOTLE_PAGE, Math.ceil((double) totle / (double) Constants.ROW)); map.put(Constants.LIST, list); return map; }
From source file:helper.util.DateHelper.java
/** * Take a local time calendar and represent it as a UTC day * (truncate to day, retain yy/mm/dd from original date) **//*from w w w . ja v a 2s .com*/ public static Calendar asUtcDay(Calendar localTimeCalendar) { Calendar utcDate = Calendar.getInstance(DateUtils.UTC_TIME_ZONE); utcDate.clear(); utcDate.set(localTimeCalendar.get(Calendar.YEAR), localTimeCalendar.get(Calendar.MONTH), localTimeCalendar.get(Calendar.DATE), 0, 0, 0); utcDate.set(Calendar.AM_PM, Calendar.AM); utcDate.set(Calendar.MILLISECOND, 0); utcDate.set(Calendar.HOUR, 0); return utcDate; }
From source file:helper.lang.DateHelperTest.java
@Test public void testGetRangeDaysBeforeTodayUtc() { int days = 1; Calendar nowUtc = DateHelper.nowUtc(); CalendarRange range = DateHelper.getRangeFullDaysBefore(nowUtc, days); Calendar start = range.getStart(); Calendar end = range.getEnd(); System.out.println(DateFormatUtils.SMTP_DATETIME_FORMAT.format(start)); System.out.println(DateFormatUtils.SMTP_DATETIME_FORMAT.format(end)); // end date is midnight of date passed in assertEquals(nowUtc.get(Calendar.YEAR), end.get(Calendar.YEAR)); assertEquals(nowUtc.get(Calendar.MONTH), end.get(Calendar.MONTH)); assertEquals(nowUtc.get(Calendar.DATE), end.get(Calendar.DATE)); assertEquals(0, end.get(Calendar.HOUR)); assertEquals(0, end.get(Calendar.MINUTE)); assertEquals(0, end.get(Calendar.SECOND)); assertEquals(0, end.get(Calendar.MILLISECOND)); assertEquals(0, end.get(Calendar.HOUR_OF_DAY)); assertEquals(DateHelper.UTC_TIME_ZONE, end.getTimeZone()); // start date is 11:59:59 or 'days' time nowUtc.add(Calendar.DATE, -(days + 2)); assertEquals(nowUtc.get(Calendar.YEAR), start.get(Calendar.YEAR)); assertEquals(nowUtc.get(Calendar.MONTH), start.get(Calendar.MONTH)); assertEquals(nowUtc.get(Calendar.DATE), start.get(Calendar.DATE)); assertEquals(11, start.get(Calendar.HOUR)); assertEquals(23, start.get(Calendar.HOUR_OF_DAY)); assertEquals(59, start.get(Calendar.MINUTE)); assertEquals(59, start.get(Calendar.SECOND)); assertEquals(999, start.get(Calendar.MILLISECOND)); assertEquals(DateHelper.UTC_TIME_ZONE, start.getTimeZone()); }