List of usage examples for java.util GregorianCalendar setTime
public final void setTime(Date date)
Date
. From source file:com.collabnet.ccf.core.ga.GenericArtifactHelper.java
/** * Convert the string value/* www .j av a 2 s .c o m*/ * * @param genericArtifactField * field for which to set the new value * @param fieldValueIsNull * if true, the field's value should be null * @param fieldValueType * type of the field's value * @param value * String encoded value out of XML element * @throws ParseException */ private static void convertFieldValue(GenericArtifactField genericArtifactField, Boolean fieldValueIsNull, FieldValueTypeValue fieldValueType, String value) throws ParseException { // TODO Think carefully about all type conversions if (value.length() == 0 && fieldValueIsNull) { genericArtifactField.setFieldValue(null); } else switch (fieldValueType) { case BASE64STRING: { // TODO Better conversion? genericArtifactField.setFieldValue(value); break; } case BOOLEAN: { genericArtifactField.setFieldValue(Boolean.valueOf(value)); break; } case DATE: { GregorianCalendar cal = new GregorianCalendar(); synchronized (df) { cal.setTime(df.parse(value)); } genericArtifactField.setFieldValue(cal); break; } case DATETIME: { synchronized (df) { genericArtifactField.setFieldValue(df.parse(value)); } break; } case DOUBLE: { genericArtifactField.setFieldValue(new Double(value)); break; } case HTMLSTRING: { // TODO Better conversion? genericArtifactField.setFieldValue(value); break; } case INTEGER: { // TODO Better conversion? genericArtifactField.setFieldValue(value); break; } case STRING: { genericArtifactField.setFieldValue(value); break; } case USER: { genericArtifactField.setFieldValue(value); break; } // case LIST: { // genericArtifactField.setFieldValue(value); // break; // } // case MULTI_SELECT_LIST: { // genericArtifactField.setFieldValue(value); // break; // } } }
From source file:com.headstrong.npi.raas.Utils.java
public static CmAttributeDate getCmAttrDate(String dateStr) { if (null != dateStr && !dateStr.trim().isEmpty()) { Date date = DateConversion.getDateFromString(dateStr); if (null != date) { GregorianCalendar cal = new GregorianCalendar(); cal.setTime(date); XMLGregorianCalendar xmlGregorianCalendar; try { xmlGregorianCalendar = DatatypeFactory.newInstance().newXMLGregorianCalendar(cal); } catch (DatatypeConfigurationException e) { e.printStackTrace();//from www . j a v a 2 s . c o m return null; } CmAttributeDate cmAttributeDate = new CmAttributeDate(); cmAttributeDate.setValue(xmlGregorianCalendar); return cmAttributeDate; } } return null; }
From source file:com.headstrong.npi.raas.Utils.java
public static CmAttributeDateMonthDay getCmAttrDateMonthDay(String monthDayStr) { if (null != monthDayStr && !monthDayStr.trim().isEmpty()) { Date date = DateConversion.getDateFromMmDString(monthDayStr); if (null != date) { GregorianCalendar cal = new GregorianCalendar(); cal.setTime(date); XMLGregorianCalendar xmlGregorianCalendar; try { xmlGregorianCalendar = DatatypeFactory.newInstance().newXMLGregorianCalendar(); xmlGregorianCalendar.setMonth(cal.get(Calendar.MONTH) + 1); xmlGregorianCalendar.setDay(cal.get(Calendar.DAY_OF_MONTH)); } catch (DatatypeConfigurationException e) { e.printStackTrace();//w ww . j a v a 2s .c om return null; } CmAttributeDateMonthDay cmAttributeDateMonthDay = new CmAttributeDateMonthDay(); cmAttributeDateMonthDay.setValue(xmlGregorianCalendar); return cmAttributeDateMonthDay; } } return null; }
From source file:org.sakaiproject.content.impl.serialize.impl.test.GMTDateformatterTest.java
/** * Test method for/* ww w. j ava 2 s . c om*/ * {@link org.sakaiproject.content.impl.util.GMTDateformatter#parse(java.lang.String)}. */ @Test public final void testParse() { // String format = "yyyyMMddHHmmssSSS"; String[] testPattern = new String[20000]; Date[] result = new Date[testPattern.length]; String[] formatPattern = new String[20000]; for (int i = 0; i < testPattern.length; i++) { int year = 1980 + (i % 200); int month = 1 + (i % 12); int day = 1 + (i % 28); int hour = (i % 24); int minute = (i % 60); int second = 59 - (i % 60); int millis = (i % 1000); StringBuilder sb = new StringBuilder(); sb.append(pad(year, 4)); sb.append(pad(month, 2)); sb.append(pad(day, 2)); sb.append(pad(hour, 2)); sb.append(pad(minute, 2)); sb.append(pad(second, 2)); sb.append(pad(millis, 3)); testPattern[i] = sb.toString(); } { long start = System.currentTimeMillis(); for (int i = 0; i < testPattern.length; i++) { result[i] = GMTDateformatter.parse(testPattern[i]); } long end = System.currentTimeMillis(); double ms = 1.0 * (end - start) / (1.0 * testPattern.length); log.info(" Took " + (end - start) + " ms " + ms + " per parse"); } { long start = System.currentTimeMillis(); for (int i = 0; i < testPattern.length; i++) { formatPattern[i] = GMTDateformatter.format(result[i]); } long end = System.currentTimeMillis(); double ms = 1.0 * (end - start) / (1.0 * testPattern.length); log.info(" Took " + (end - start) + " ms " + ms + " per format"); } for (int i = 0; i < testPattern.length; i++) { int year = 1980 + (i % 200); int month = 1 + (i % 12); int day = 1 + (i % 28); int hour = (i % 24); int minute = (i % 60); int second = 59 - (i % 60); int millis = (i % 1000); GregorianCalendar gc = new GregorianCalendar(TimeZone.getTimeZone("GMT")); gc.setTime(result[i]); Assert.assertEquals(testPattern[i] + " year", year, gc.get(Calendar.YEAR)); Assert.assertEquals(testPattern[i] + " month", month, gc.get(Calendar.MONTH) + 1); Assert.assertEquals(testPattern[i] + " day", day, gc.get(Calendar.DATE)); Assert.assertEquals(testPattern[i] + " hour", hour, gc.get(Calendar.HOUR_OF_DAY)); Assert.assertEquals(testPattern[i] + " minute", minute, gc.get(Calendar.MINUTE)); Assert.assertEquals(testPattern[i] + " second", second, gc.get(Calendar.SECOND)); Assert.assertEquals(testPattern[i] + " millis", millis, gc.get(Calendar.MILLISECOND)); Assert.assertEquals("Format Check ", testPattern[i], GMTDateformatter.format(result[i])); } }
From source file:cz.zcu.kiv.eegdatabase.logic.controller.group.BookingRoomAjaxController.java
@Override public Map referenceData(HttpServletRequest request, Object command, Errors errors) throws Exception { Map map = new HashMap<String, Object>(); GroupMultiController.setPermissionToRequestGroupRole(map, personDao.getLoggedPerson()); if (request.getParameter("type").compareTo("info") == 0) { int id = Integer.parseInt(request.getParameter("id")); Reservation reservation = reservationDao.getReservationById(id); GregorianCalendar created = new GregorianCalendar(); created.setTime(reservation.getCreationTime()); GregorianCalendar startTime = new GregorianCalendar(); startTime.setTime(reservation.getStartTime()); GregorianCalendar endTime = new GregorianCalendar(); endTime.setTime(reservation.getEndTime()); Map data = new HashMap<String, Object>(); data.put("id", id); data.put("person", reservation.getPerson()); data.put("created", BookingRoomUtils.getDate(created) + ", " + BookingRoomUtils.getTime(created)); data.put("date", BookingRoomUtils.getDate(startTime)); data.put("start", BookingRoomUtils.getHoursAndMinutes(startTime)); data.put("end", BookingRoomUtils.getHoursAndMinutes(endTime)); map.put("data", data); return map; }// ww w . ja v a2 s. com if (request.getParameter("type").compareTo("delete") == 0) { int id = Integer.parseInt(request.getParameter("id")); if (reservationDao.deleteReservation(id)) { map.put("status", messageSource.getMessage("bookRoom.delete.success", null, RequestContextUtils.getLocale(request))); } else { map.put("status", messageSource.getMessage("bookRoom.delete.error", null, RequestContextUtils.getLocale(request))); } return map; } if (request.getParameter("type").compareTo("timeline") == 0) { String date = request.getParameter("date") + " 00:00:00"; log.debug("XML DATE=" + date); GregorianCalendar monthStart = BookingRoomUtils.getCalendar(date); monthStart.set(Calendar.DAY_OF_MONTH, 1); GregorianCalendar monthEnd = (GregorianCalendar) monthStart.clone(); monthEnd.add(Calendar.MONTH, 1); monthEnd.add(Calendar.SECOND, -1); String xml = BookingRoomXmlUtils.formatReservationsList( reservationDao.getReservationsBetween(monthStart, monthEnd), personDao.getLoggedPerson()); map.put("xmlContent", xml); return map; } throw new InvalidAttributeValueException( "Attribute '" + request.getParameter("type") + "' is not allowed!"); }
From source file:edu.umm.radonc.ca_dash.controllers.D3PieChartController.java
public D3PieChartController() { endDate = new Date(); GregorianCalendar gc = new GregorianCalendar(); gc.setTime(endDate); gc.add(Calendar.MONTH, -1);//from ww w . ja va 2s .c o m startDate = gc.getTime(); interval = "1m"; this.df = new SimpleDateFormat("MM/dd/YYYY"); this.selectedFacility = new Long(-1); this.dstats = new SynchronizedDescriptiveStatistics(); this.interval = ""; selectedFilters = new ArrayList<>(); jsonData = new JSONArray(); }
From source file:org.enotron.simulator.SimulatorRestController.java
@RequestMapping("/getData") public GetDataResponse getData(@RequestParam(value = "simulatorId", required = true) String simulatorId, @RequestParam(value = "startTime", required = false) Date startTime, @RequestParam(value = "endTime", required = false) Date endTime, @RequestParam(value = "valuesMode", required = false, defaultValue = "MIN_MEAN_MAX_STDDEV") String valuesMode, @RequestParam(value = "groupBy", required = true, defaultValue = "TENMINUTE") String groupBy) throws GetDataFault { GetDataRequest getDataPayload = new GetDataRequest(); getDataPayload.setSimulatorid(ByteArrayHelper.fromHexString(simulatorId)); GregorianCalendar startCal = new GregorianCalendar(); startCal.setTime(startTime); getDataPayload.setStartTime(factory.newXMLGregorianCalendar(startCal)); GregorianCalendar endCal = new GregorianCalendar(); endCal.setTime(startTime);//from ww w. j a va2 s .c o m getDataPayload.setEndTime(factory.newXMLGregorianCalendar(endCal)); getDataPayload.setGroupBy(TimeScope.valueOf(groupBy)); getDataPayload.setValuesMode(ValuesMode.fromValue(valuesMode)); return wsEndpoint.getData(getDataPayload); }
From source file:org.grails.datastore.mapping.model.types.BasicTypeConverterRegistrar.java
public void register(ConverterRegistry registry) { registry.addConverter(new Converter<Date, String>() { public String convert(Date date) { return String.valueOf(date.getTime()); }/* w ww . j a v a 2s. com*/ }); registry.addConverter(new Converter<Date, Calendar>() { public Calendar convert(Date date) { final GregorianCalendar calendar = new GregorianCalendar(); calendar.setTime(date); return calendar; } }); registry.addConverter(new Converter<Integer, Long>() { public Long convert(Integer integer) { return integer.longValue(); } }); registry.addConverter(new Converter<Long, Integer>() { public Integer convert(Long longValue) { return longValue.intValue(); } }); registry.addConverter(new Converter<Integer, Double>() { public Double convert(Integer integer) { return integer.doubleValue(); } }); registry.addConverter(new Converter<CharSequence, Date>() { public Date convert(CharSequence s) { try { final Long time = Long.valueOf(s.toString()); return new Date(time); } catch (NumberFormatException e) { throw new IllegalArgumentException(e); } } }); registry.addConverter(new Converter<CharSequence, Double>() { public Double convert(CharSequence s) { try { return Double.valueOf(s.toString()); } catch (NumberFormatException e) { throw new IllegalArgumentException(e); } } }); registry.addConverter(new Converter<CharSequence, Integer>() { public Integer convert(CharSequence s) { try { return Integer.valueOf(s.toString()); } catch (NumberFormatException e) { throw new IllegalArgumentException(e); } } }); registry.addConverter(new Converter<CharSequence, Long>() { public Long convert(CharSequence s) { try { return Long.valueOf(s.toString()); } catch (NumberFormatException e) { throw new IllegalArgumentException(e); } } }); registry.addConverter(new Converter<Object, String>() { public String convert(Object o) { return o.toString(); } }); registry.addConverter(new Converter<Calendar, String>() { public String convert(Calendar calendar) { return String.valueOf(calendar.getTime().getTime()); } }); registry.addConverter(new Converter<CharSequence, Calendar>() { public Calendar convert(CharSequence s) { try { Date date = new Date(Long.valueOf(s.toString())); Calendar c = new GregorianCalendar(); c.setTime(date); return c; } catch (NumberFormatException e) { throw new IllegalArgumentException(e); } } }); }
From source file:edu.jhuapl.openessence.web.util.Filters.java
public List<Filter> getFilters(final Map<String, String[]> parameterValues, final OeDataSource ds, final String prePullArg, final int prePullInc, final String resolution, int calWeekStartDay, final boolean adjustDate) throws ErrorMessageException { final List<Filter> filters = new ArrayList<Filter>(); for (final FilterDimension fd : ds.getFilterDimensions()) { final FieldType type = fd.getSqlType(); for (final String sfx : parmSfx.keySet()) { final String key = fd.getId() + sfx; if (!reservedParameters.contains(key)) { final String[] values = parameterValues.get(key); // No values for a filter dimension is ok if (!ArrayUtils.isEmpty(values)) { if (values.length == 1) { Object argument = ControllerUtils.formatData(key, values[0], type, false).get(key); final Relation rel = type == FieldType.TEXT ? Relation.LIKE : parmSfx.get(sfx); try { if (fd.getId().equals(prePullArg) && (rel == Relation.GTEQ)) { argument = muckDate((Date) argument, prePullInc, resolution, calWeekStartDay); }/*from w w w . j a v a2s. com*/ // if end date, account for hours 00:00:00 to 23:59:59 if ((type == FieldType.DATE_TIME || type == FieldType.DATE) && (rel == Relation.LTEQ)) { GregorianCalendar x = new GregorianCalendar(); x.setTime((Date) argument); // Only perform this operation if it hasn't already been handled in a previous call. // When generating a Chart, it will go to the end of the day and adjust the filter // to be 23:59:59.999 (5/1/13 becomes 5/1/13-23:59:59.999). But, when the user // would click-through on a bar/slice, it would accidently perform this action again. // This resulted in adding another day to the query; now becoming 5/2/13 23:59:59.998. if (adjustDate) { x.add(Calendar.DATE, 1); x.add(Calendar.MILLISECOND, -1); argument = x.getTime(); } } filters.add(fd.makeFilter(rel, argument)); } catch (OeDataSourceException e) { throw new ErrorMessageException("Could not create filter", e); } } else { final Object[] arguments = new Object[values.length]; for (int i = 0; i < values.length; i++) { arguments[i] = ControllerUtils.formatData(key, values[i], type, false).get(key); } try { filters.add(fd.makeFilter(Relation.IN, arguments)); } catch (OeDataSourceException e) { throw new ErrorMessageException("Could not create filter", e); } } } } } } return filters; }
From source file:com.hpe.elderberry.Taxii10Template.java
private XMLGregorianCalendar toXmlGregorianCalendar(Date date) throws DatatypeConfigurationException { GregorianCalendar c = new GregorianCalendar(); c.setTime(date); return newInstance().newXMLGregorianCalendar(c); }