List of usage examples for javax.xml.datatype XMLGregorianCalendar setYear
public abstract void setYear(int year);
From source file:gov.nih.nci.cabig.caaers.service.migrator.StudyConverter.java
private XMLGregorianCalendar convertCalendar2XmlGregorianCalendar(Calendar c) throws Exception { XMLGregorianCalendar xml = DatatypeFactory.newInstance().newXMLGregorianCalendar(); xml.setYear(c.get(Calendar.YEAR)); xml.setMonth(c.get(Calendar.MONTH) + 1); xml.setDay(c.get(Calendar.DAY_OF_MONTH)); return xml;/* w w w. j a va2s .c om*/ }
From source file:org.jasig.portlet.calendar.adapter.ExchangeCalendarAdapterTest.java
@Test public void testGetInternalEvent() throws DatatypeConfigurationException { com.microsoft.exchange.types.CalendarEvent msEvent = new com.microsoft.exchange.types.CalendarEvent(); // set the test event start time to 4AM on November 1, 2010 DatatypeFactory datatypeFactory = DatatypeFactory.newInstance(); XMLGregorianCalendar start = datatypeFactory.newXMLGregorianCalendar(); start.setYear(2010); start.setMonth(11);// ww w. j a v a 2s. c om start.setDay(1); start.setTime(4, 0, 0, 0); msEvent.setStartTime(start); // set the test event end time to 5AM on November 1, 2010 XMLGregorianCalendar end = datatypeFactory.newXMLGregorianCalendar(); end.setYear(2010); end.setMonth(12); end.setDay(1); end.setTime(5, 0, 0, 0); msEvent.setEndTime(end); // set the event tname and location CalendarEventDetails details = new CalendarEventDetails(); details.setSubject("Naptime"); details.setLocation("My house"); msEvent.setCalendarEventDetails(details); // transform the Microsoft calendar event into a calendar portlet event VEvent event = adapter.getInternalEvent(3, msEvent); // ensure the calendar id, summary, and location are all set correctly assertEquals("Naptime", event.getSummary().getValue()); assertEquals("My house", event.getLocation().getValue()); // check the start time Calendar cal = Calendar.getInstance(java.util.TimeZone.getTimeZone("UTC")); cal.setTimeInMillis(event.getStartDate().getDate().getTime()); assertEquals(4, cal.get(Calendar.HOUR_OF_DAY)); assertEquals(java.util.TimeZone.getTimeZone("UTC"), cal.getTimeZone()); assertTrue(event.getStartDate().isUtc()); assertNull(event.getStartDate().getTimeZone()); // check the end time cal.setTimeInMillis(event.getEndDate().getDate().getTime()); assertEquals(5, cal.get(Calendar.HOUR_OF_DAY)); assertEquals(java.util.TimeZone.getTimeZone("UTC"), cal.getTimeZone()); assertTrue(event.getEndDate().isUtc()); assertNull(event.getEndDate().getTimeZone()); }
From source file:org.orcid.persistence.adapter.impl.Jpa2JaxbAdapterImpl.java
private XMLGregorianCalendar toXMLGregorianCalendarWithoutTime(Date date) { if (date != null) { GregorianCalendar c = new GregorianCalendar(); c.setTime(date);/*from w w w .j a v a 2s . c o m*/ XMLGregorianCalendar xmlGregorianCalendar = datatypeFactory.newXMLGregorianCalendar(); xmlGregorianCalendar.setDay(c.get(Calendar.DAY_OF_MONTH)); xmlGregorianCalendar.setMonth(c.get(Calendar.MONTH) + 1); xmlGregorianCalendar.setYear(c.get(Calendar.YEAR)); return xmlGregorianCalendar; } else { return null; } }
From source file:org.talend.components.netsuite.client.model.search.SearchDateFieldAdapter.java
protected XMLGregorianCalendar convertDateTime(String input) { String valueToParse = input;/*from ww w . j a v a 2 s . c o m*/ String dateTimeFormatPattern = dateFormatPattern + " " + timeFormatPattern; if (input.length() == dateFormatPattern.length()) { dateTimeFormatPattern = dateFormatPattern; } else if (input.length() == timeFormatPattern.length()) { DateTime dateTime = new DateTime(); DateTimeFormatter dateFormatter = DateTimeFormat.forPattern(dateFormatPattern); valueToParse = dateFormatter.print(dateTime) + " " + input; } DateTimeFormatter dateTimeFormatter = DateTimeFormat.forPattern(dateTimeFormatPattern); DateTime dateTime; try { dateTime = dateTimeFormatter.parseDateTime(valueToParse); } catch (IllegalArgumentException e) { throw new NetSuiteException(new NetSuiteErrorCode(NetSuiteErrorCode.CLIENT_ERROR), NetSuiteRuntimeI18n.MESSAGES.getMessage("error.searchDateField.invalidDateTimeFormat", valueToParse)); } XMLGregorianCalendar xts = datatypeFactory.newXMLGregorianCalendar(); xts.setYear(dateTime.getYear()); xts.setMonth(dateTime.getMonthOfYear()); xts.setDay(dateTime.getDayOfMonth()); xts.setHour(dateTime.getHourOfDay()); xts.setMinute(dateTime.getMinuteOfHour()); xts.setSecond(dateTime.getSecondOfMinute()); xts.setMillisecond(dateTime.getMillisOfSecond()); xts.setTimezone(dateTime.getZone().toTimeZone().getOffset(dateTime.getMillis()) / 60000); return xts; }
From source file:org.techytax.util.DateHelper.java
public static XMLGregorianCalendar getDate(String date_str) throws Exception { XMLGregorianCalendar calendar = DatatypeFactory.newInstance().newXMLGregorianCalendar(); Date date = stringToDate(date_str); calendar.setDay(getDay(date));/*from w ww.j a v a2s.c o m*/ calendar.setMonth(getMonth(date) + 1); calendar.setYear(getYear(date)); return calendar; }
From source file:org.techytax.util.DateHelper.java
public static XMLGregorianCalendar getDateForXml(Date date) { XMLGregorianCalendar calendar = null; try {/*ww w. j ava 2 s . c o m*/ calendar = DatatypeFactory.newInstance().newXMLGregorianCalendar(); } catch (DatatypeConfigurationException e) { e.printStackTrace(); } calendar.setDay(getDay(date)); calendar.setMonth(getMonth(date) + 1); calendar.setYear(getYear(date)); calendar.setHour(0); calendar.setMinute(0); calendar.setSecond(0); return calendar; }