Example usage for javax.xml.datatype XMLGregorianCalendar getYear

List of usage examples for javax.xml.datatype XMLGregorianCalendar getYear

Introduction

In this page you can find the example usage for javax.xml.datatype XMLGregorianCalendar getYear.

Prototype

public abstract int getYear();

Source Link

Document

Returns the low order component for XML Schema 1.0 dateTime datatype field for year or DatatypeConstants#FIELD_UNDEFINED .

Usage

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

/**
 * Converts from an XMLGregorianCalendar to a LocalDateTime i.e. represents a date and time without timezone
 * inform.ation/*from   www.  j  a  v a2  s  .c  om*/
 * 
 * @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

public static DateTime xmlToDateTime(final XMLGregorianCalendar xmlCal) {
    DateTime result = null;/*from w ww  .j a  v a  2 s .c  om*/
    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// w  ww.  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());/*  www .j  a  va 2  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:no.uis.fsws.proxy.StudinfoProxyImpl.java

@Override
@SneakyThrows/*www.j  a  v a 2 s . co m*/
public List<Kurs> getKurs(final XMLGregorianCalendar arstall, final Terminkode terminkode,
        final Sprakkode sprak, final int institusjonsnr, Integer fakultetsnr, Integer instituttnr,
        Integer gruppenr) {
    final StudInfoImport svc = getServiceForPrincipal();

    Future<List<Kurs>> future = executor.submit(new Callable<List<Kurs>>() {

        @Override
        public List<Kurs> call() throws Exception {
            final FsStudieinfo sinfo = svc.fetchCourses(institusjonsnr, arstall.getYear(),
                    terminkode.toString(), sprak.toString());
            return sinfo.getKurs();
        }
    });

    return future.get(timeoutMinutes, TimeUnit.MINUTES);
}

From source file:no.uis.fsws.proxy.StudinfoProxyImpl.java

@Override
@SneakyThrows/*from w  w  w  .j  av a  2  s  .  c o  m*/
public List<Emne> getEmne(final XMLGregorianCalendar arstall, final Terminkode terminkode,
        final Sprakkode sprak, final int institusjonsnr, final String emnekode, final String versjonskode) {
    final StudInfoImport svc = getServiceForPrincipal();
    Future<List<Emne>> future = executor.submit(new Callable<List<Emne>>() {

        @Override
        public List<Emne> call() throws Exception {
            final FsStudieinfo sinfo = svc.fetchSubject(institusjonsnr, emnekode, versjonskode,
                    arstall.getYear(), terminkode.toString(), sprak.toString());
            return sinfo.getEmne();
        }
    });

    return future.get(timeoutMinutes, TimeUnit.MINUTES);
}