List of usage examples for javax.xml.datatype XMLGregorianCalendar getMinute
public abstract int getMinute();
From source file:Main.java
public static DateTime xmlToDateTime(final XMLGregorianCalendar xmlCal) { DateTime result = null;// w w w . j ava 2s . com if (xmlCal != null) { int hourOfDay = xmlCal.getHour(); int minuteOfHour = xmlCal.getMinute(); int secondOfMinute = xmlCal.getSecond(); int milliOfSecond = xmlCal.getMillisecond(); if (hourOfDay < 0) { hourOfDay = 0; } if (minuteOfHour < 0) { minuteOfHour = 0; } if (secondOfMinute < 0) { secondOfMinute = 0; } if (milliOfSecond < 0) { milliOfSecond = 0; } result = new DateTime(xmlCal.getYear(), xmlCal.getMonth(), xmlCal.getDay(), hourOfDay, minuteOfHour, secondOfMinute, milliOfSecond); } return result; }
From source file:Main.java
/** * Converts from an XMLGregorianCalendar to a LocalTime i.e. represents a time without timezone or date information. * //from w w w . j a va2 s .c om * @param calendar XMLGregorianCalendar object. * @return The calendar converted to a LocalTime. */ public static LocalTime convertToLocalTime(XMLGregorianCalendar calendar) { if (calendar == null) { return null; } int hour = calendar.getHour() > 0 ? calendar.getHour() : 0; int minute = calendar.getMinute() > 0 ? calendar.getMinute() : 0; int second = calendar.getSecond() > 0 ? calendar.getSecond() : 0; int millisecond = calendar.getMillisecond() > 0 ? calendar.getMillisecond() : 0; return new LocalTime(hour, minute, second, millisecond); }
From source file:Main.java
/** * Converts from an XMLGregorianCalendar to a LocalDateTime i.e. represents a date and time without timezone * inform.ation//from ww w. j a v a 2 s.co m * * @param calendar XMLGregorianCalendar object. * @return The calendar converted to a LocalDateTime. */ public static LocalDateTime convertToLocalDateTime(XMLGregorianCalendar calendar) { if (calendar == null) { return null; } int year = calendar.getYear() > 0 ? calendar.getYear() : 0; int hour = calendar.getHour() > 0 ? calendar.getHour() : 0; int minute = calendar.getMinute() > 0 ? calendar.getMinute() : 0; int second = calendar.getSecond() > 0 ? calendar.getSecond() : 0; int millisecond = calendar.getMillisecond() > 0 ? calendar.getMillisecond() : 0; return new LocalDateTime(year, calendar.getMonth(), calendar.getDay(), hour, minute, second, millisecond); }
From source file:Main.java
public static String toStr(XMLGregorianCalendar xmlGregorianCalendar) { // 1970-01-01 => hour minute secend timezone :-2147483648 String result = ""; result += xmlGregorianCalendar.getYear(); result += "-"; result += zeroize(xmlGregorianCalendar.getMonth()); result += "-"; result += zeroize(xmlGregorianCalendar.getDay()); result += "T"; result += zeroize(xmlGregorianCalendar.getHour()); result += ":"; result += zeroize(xmlGregorianCalendar.getMinute()); result += ":"; result += zeroize(xmlGregorianCalendar.getSecond()); return result; // return new Date(xmlGregorianCalendar.getMillisecond()); }
From source file:Main.java
/** * Converts an XMLGregorianCalendar to a Date. * * @param xmlDate// w w w . j av a 2 s . c o m * XMLGregorianCalendar to convert. * @return corresponding date object. */ public static Date getDate(final XMLGregorianCalendar xmlDate) { // TODO: is this equivalent to getDate(String) processing above?? // start with UTC, i.e. no daylight savings time. TimeZone timezone = TimeZone.getTimeZone("GMT"); // adjust timezone to match xmldate int offsetMinutes = xmlDate.getTimezone(); if (offsetMinutes != DatatypeConstants.FIELD_UNDEFINED) { timezone.setRawOffset( // convert minutes to milliseconds offsetMinutes * 60 // seconds per minute * 1000 // milliseconds per second ); } // use calendar so parsed date will be UTC Calendar calendar = Calendar.getInstance(timezone); calendar.clear(); calendar.set(xmlDate.getYear(), // xmlcalendar is 1 based, calender is 0 based xmlDate.getMonth() - 1, xmlDate.getDay(), xmlDate.getHour(), xmlDate.getMinute(), xmlDate.getSecond()); Date date = calendar.getTime(); int millis = xmlDate.getMillisecond(); if (millis != DatatypeConstants.FIELD_UNDEFINED) { calendar.setTimeInMillis(calendar.getTimeInMillis() + millis); } return date; }
From source file:org.jasig.portlet.calendar.adapter.ExchangeCalendarAdapterTest.java
@Test public void testGetXmlDate() throws DatatypeConfigurationException { // construct a calendar representing 4:30PM on June 4, 2010 DateTime date = new DateTime(2010, 6, 3, 16, 30, DateTimeZone.UTC); XMLGregorianCalendar xmlCal = adapter.getXmlDate(date); assertEquals(2010, xmlCal.getYear()); assertEquals(6, xmlCal.getMonth());//from w w w. j a v a2 s.c o m assertEquals(3, xmlCal.getDay()); assertEquals(16, xmlCal.getHour()); assertEquals(30, xmlCal.getMinute()); assertEquals(0, xmlCal.getSecond()); assertEquals(0, xmlCal.getFractionalSecond().intValue()); }
From source file:net.servicefixture.converter.XMLGregorianCalendarConverter.java
public String toString(Object source) { XMLGregorianCalendar src = (XMLGregorianCalendar) source; SimpleDateFormat formatter = new SimpleDateFormat(DateConverter.DATE_FORMAT); formatter.setTimeZone(TimeZone.getTimeZone("GMT")); Calendar cal = Calendar.getInstance(); cal.set(Calendar.YEAR, src.getYear()); cal.set(Calendar.MONTH, src.getMonth() - 1); cal.set(Calendar.DAY_OF_MONTH, src.getDay()); cal.set(Calendar.HOUR, src.getHour()); cal.set(Calendar.MINUTE, src.getMinute()); cal.set(Calendar.SECOND, src.getSecond()); cal.set(Calendar.MILLISECOND, src.getMillisecond()); return formatter.format(cal.getTime()); }
From source file:be.fedict.trust.xkms2.XKMSPortImpl.java
private Date getDate(XMLGregorianCalendar xmlCalendar) { GregorianCalendar calendar = new GregorianCalendar(xmlCalendar.getYear(), xmlCalendar.getMonth() - 1, xmlCalendar.getDay(), // xmlCalendar.getHour(), xmlCalendar.getMinute(), xmlCalendar.getSecond()); calendar.setTimeZone(xmlCalendar.getTimeZone(0)); return calendar.getTime(); }
From source file:edu.harvard.i2b2.previousquery.QueryPreviousRunsPanel.java
private void populateChildNodes(DefaultMutableTreeNode node) { if (node.getUserObject().getClass().getSimpleName().equalsIgnoreCase("QueryMasterData")) { QueryMasterData data = (QueryMasterData) node.getUserObject(); try {//from w w w. j a v a2 s . c o m String xmlRequest = data.writeContentQueryXML(); lastRequestMessage = xmlRequest; //System.out.println(xmlRequest); String xmlResponse = QueryListNamesClient.sendQueryRequestREST(xmlRequest); if (xmlResponse.equalsIgnoreCase("CellDown")) { final JPanel parent = this; java.awt.EventQueue.invokeLater(new Runnable() { public void run() { JOptionPane.showMessageDialog(parent, "Trouble with connection to the remote server, " + "this is often a network error, please try again", "Network Error", JOptionPane.INFORMATION_MESSAGE); } }); return; } lastResponseMessage = xmlResponse; try { JAXBUtil jaxbUtil = PreviousQueryJAXBUtil.getJAXBUtil(); JAXBElement jaxbElement = jaxbUtil.unMashallFromString(xmlResponse); ResponseMessageType messageType = (ResponseMessageType) jaxbElement.getValue(); BodyType bt = messageType.getMessageBody(); InstanceResponseType instanceResponseType = (InstanceResponseType) new JAXBUnWrapHelper() .getObjectByClass(bt.getAny(), InstanceResponseType.class); for (QueryInstanceType queryInstanceType : instanceResponseType.getQueryInstance()) { //change later for working with new xml schema //RunQuery runQuery = queryInstanceType.getResult().get(i).getRunQuery().get(0); QueryInstanceData runData = new QueryInstanceData(); runData.visualAttribute("FA"); runData.tooltip("The results of the query run"); runData.id(new Integer(queryInstanceType.getQueryInstanceId()).toString()); //runData.patientRefId(new Integer(queryInstanceType.getRefId()).toString()); //runData.patientCount(new Long(queryInstanceType.getCount()).toString()); XMLGregorianCalendar cldr = queryInstanceType.getStartDate(); runData.name("Results of " + "[" + addZero(cldr.getMonth()) + "-" + addZero(cldr.getDay()) + "-" + addZero(cldr.getYear()) + " " + addZero(cldr.getHour()) + ":" + addZero(cldr.getMinute()) + ":" + addZero(cldr.getSecond()) + "]"); data.runs.add(runData); addNode(runData, node); } } catch (Exception e) { e.printStackTrace(); } jTree1.scrollPathToVisible(new TreePath(node.getPath())); } catch (Exception e) { e.printStackTrace(); } } else if (node.getUserObject().getClass().getSimpleName().equalsIgnoreCase("QueryInstanceData")) { QueryInstanceData data = (QueryInstanceData) node.getUserObject(); try { String xmlRequest = data.writeContentQueryXML(); lastRequestMessage = xmlRequest; //System.out.println(xmlRequest); String xmlResponse = QueryListNamesClient.sendQueryRequestREST(xmlRequest); if (xmlResponse.equalsIgnoreCase("CellDown")) { final JPanel parent = this; java.awt.EventQueue.invokeLater(new Runnable() { public void run() { JOptionPane.showMessageDialog(parent, "Trouble with connection to the remote server, " + "this is often a network error, please try again", "Network Error", JOptionPane.INFORMATION_MESSAGE); } }); return; } lastResponseMessage = xmlResponse; JAXBUtil jaxbUtil = PreviousQueryJAXBUtil.getJAXBUtil(); JAXBElement jaxbElement = jaxbUtil.unMashallFromString(xmlResponse); ResponseMessageType messageType = (ResponseMessageType) jaxbElement.getValue(); BodyType bt = messageType.getMessageBody(); ResultResponseType resultResponseType = (ResultResponseType) new JAXBUnWrapHelper() .getObjectByClass(bt.getAny(), ResultResponseType.class); for (QueryResultInstanceType queryResultInstanceType : resultResponseType .getQueryResultInstance()) { String status = queryResultInstanceType.getQueryStatusType().getName(); QueryResultData resultData = new QueryResultData(); resultData.visualAttribute("LAO"); resultData.tooltip("A patient set of the query run"); //resultData.queryId(data.queryId()); resultData.patientRefId(new Integer(queryResultInstanceType.getResultInstanceId()).toString());//data.patientRefId()); resultData.patientCount(new Integer(queryResultInstanceType.getSetSize()).toString());//data.patientCount()); if (status.equalsIgnoreCase("FINISHED")) { resultData.name("Patient Set - " + resultData.patientCount() + " Patients"); } else { resultData.name("Patient Set - " + status); } resultData.xmlContent(xmlResponse); addNode(resultData, node); } jTree1.scrollPathToVisible(new TreePath(node.getPath())); } catch (Exception e) { e.printStackTrace(); } } //implement for other type of nodes later!!! }
From source file:com.microsoft.exchange.integration.TimeZoneIntegrationTest.java
@Test public void createGetDeleteCalendarItem() throws DatatypeConfigurationException { TimeZone utcTimeZone = TimeZone.getTimeZone(RequestServerTimeZoneInterceptor.FALLBACK_TIMEZONE_ID); TimeZone.setDefault(utcTimeZone); ApplicationContext context = new ClassPathXmlApplicationContext( "classpath:test-contexts/exchangeContext.xml"); RequestServerTimeZoneInterceptor timeZoneInterceptor = context .getBean(RequestServerTimeZoneInterceptor.class); ExchangeWebServices ews = context.getBean(ExchangeWebServices.class); BaseExchangeCalendarDataDao exchangeCalendarDao = context.getBean(BaseExchangeCalendarDataDao.class); exchangeCalendarDao.setWebServices(ews); assertEquals(TimeZone.getDefault(), utcTimeZone); //XMLGregorianCalendar is sortof backed by a gregorian calendar, date/times should reflect default jvm timezone XMLGregorianCalendar xmlStart = DateHelp.getXMLGregorianCalendarNow(); CalendarItemType calendarItem = new CalendarItemType(); calendarItem.setStart(xmlStart);//ww w . j av a 2 s. c o m ItemIdType itemId = exchangeCalendarDao.createCalendarItem(upn, calendarItem); assertNotNull(itemId); Set<ItemIdType> itemIds = Collections.singleton(itemId); Set<CalendarItemType> calendarItems = exchangeCalendarDao.getCalendarItems(upn, itemIds); assertNotNull(calendarItems); CalendarItemType createdCalendarItem = DataAccessUtils.singleResult(calendarItems); assertNotNull(createdCalendarItem); XMLGregorianCalendar createdCalendarItemStart = createdCalendarItem.getStart(); assertNotNull(createdCalendarItemStart); assertEquals(xmlStart.getTimezone(), createdCalendarItemStart.getTimezone()); //nope! tzDisplayName = createdCalendarItem.getTimeZone() //assertEquals(RequestServerTimeZoneInterceptor.FALLBACK_TIMEZONE_ID, createdCalendarItem.getTimeZone()); assertEquals(xmlStart.getEon(), createdCalendarItemStart.getEon()); assertEquals(xmlStart.getEonAndYear(), createdCalendarItemStart.getEonAndYear()); assertEquals(xmlStart.getYear(), createdCalendarItemStart.getYear()); assertEquals(xmlStart.getMonth(), createdCalendarItemStart.getMonth()); assertEquals(xmlStart.getDay(), createdCalendarItemStart.getDay()); assertEquals(xmlStart.getHour(), createdCalendarItemStart.getHour()); assertEquals(xmlStart.getMinute(), createdCalendarItemStart.getMinute()); assertEquals(xmlStart.getSecond(), createdCalendarItemStart.getSecond()); //nope! always seems to be a slight variation //assertEquals(xmlStart.toGregorianCalendar().getTimeInMillis(), createdCalendarItemStart.toGregorianCalendar().getTimeInMillis()); //assertEquals(xmlStart.getMillisecond(), createdCalendarItemStart.getMillisecond()); //assertEquals(xmlStart.getFractionalSecond(), createdCalendarItemStart.getFractionalSecond()); assertTrue(DateHelp.withinOneSecond(xmlStart, createdCalendarItemStart)); assertTrue(exchangeCalendarDao.deleteCalendarItems(upn, itemIds)); }