List of usage examples for javax.xml.datatype XMLGregorianCalendar getDay
public abstract int getDay();
From source file:Main.java
public static Date convertDate(XMLGregorianCalendar date) { return new GregorianCalendar(date.getYear(), date.getMonth(), date.getDay()).getTime(); }
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 from an XMLGregorianCalendar to a LocalDateTime i.e. represents a date and time without timezone * inform.ation//from w ww .java2 s .c o 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 DateTime xmlToDateTime(final XMLGregorianCalendar xmlCal) { DateTime result = null;//from ww w.j a v a 2 s . 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 an XMLGregorianCalendar to a Date. * * @param xmlDate/*from w w w. j ava 2 s. com*/ * 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 ww w . j a v a 2 s .c om*/ 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:ca.phon.session.io.xml.v12.XMLSessionReader_v12.java
private Participant copyParticipant(SessionFactory factory, ParticipantType pt, LocalDate sessionDate) { final Participant retVal = factory.createParticipant(); retVal.setId(pt.getId());// w w w . j ava 2 s .co m retVal.setName(pt.getName()); final XMLGregorianCalendar bday = pt.getBirthday(); if (bday != null) { final LocalDate bdt = LocalDate.of(bday.getYear(), bday.getMonth(), bday.getDay()); retVal.setBirthDate(bdt); // calculate age up to the session date final Period period = Period.between(bdt, sessionDate); retVal.setAgeTo(period); } final Duration ageDuration = pt.getAge(); if (ageDuration != null) { // convert to period final Period age = Period.of(ageDuration.getYears(), ageDuration.getMonths(), ageDuration.getDays()); retVal.setAge(age); } retVal.setEducation(pt.getEducation()); retVal.setGroup(pt.getGroup()); String langs = ""; for (String lang : pt.getLanguage()) langs += (langs.length() > 0 ? ", " : "") + lang; retVal.setLanguage(langs); if (pt.getSex() == SexType.MALE) retVal.setSex(Sex.MALE); else if (pt.getSex() == SexType.FEMALE) retVal.setSex(Sex.FEMALE); else retVal.setSex(Sex.UNSPECIFIED); ParticipantRole prole = ParticipantRole.fromString(pt.getRole()); if (prole == null) prole = ParticipantRole.TARGET_CHILD; retVal.setRole(prole); retVal.setSES(pt.getSES()); return retVal; }
From source file:eu.openminted.registry.service.generate.WorkflowOutputMetadataGenerate.java
protected ResourceCreationInfo generateResourceCreationInfo(String userId) throws JsonParseException, JsonMappingException, IOException { ResourceCreationInfo resourceCreationInfo = new ResourceCreationInfo(); // resourceCreators.resourceCreator.relatedPerson List<ActorInfo> resourceCreators = new ArrayList<>(); ActorInfo actorInfo = new ActorInfo(); actorInfo.setActorType(ActorTypeEnum.PERSON); actorInfo.setRelatedPerson(generatePersonInfo(userId, false)); resourceCreators.add(actorInfo);/*from ww w.jav a2s. c o m*/ resourceCreationInfo.setResourceCreators(resourceCreators); // resourceCreationDate DateCombination creationDate = new DateCombination(); XMLGregorianCalendar calendar = null; try { calendar = DatatypeFactory.newInstance().newXMLGregorianCalendar(gregory); } catch (DatatypeConfigurationException e) { e.printStackTrace(); } Date date = new Date(); date.setYear(calendar.getYear()); date.setMonth(calendar.getMonth()); date.setDay(calendar.getDay()); creationDate.setDate(date); resourceCreationInfo.setCreationDate(creationDate); return resourceCreationInfo; }