Example usage for javax.xml.datatype XMLGregorianCalendar setTime

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

Introduction

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

Prototype

public void setTime(int hour, int minute, int second, int millisecond) 

Source Link

Document

Set time as one unit, including optional milliseconds.

Usage

From source file:name.persistent.behaviours.PURLValidationSupport.java

private XMLGregorianCalendar today() throws DatatypeConfigurationException {
    GregorianCalendar cal;//from  ww w . j ava2  s  . c  om
    XMLGregorianCalendar today;
    int n = DatatypeConstants.FIELD_UNDEFINED;
    DatatypeFactory f = DatatypeFactory.newInstance();
    cal = new GregorianCalendar(TimeZone.getTimeZone("UTC"));
    today = f.newXMLGregorianCalendar(cal);
    today.setTime(n, n, n, n);
    return today;
}

From source file:org.jasig.portlet.calendar.adapter.ExchangeCalendarAdapter.java

/**
 * Get an XMLGregorianCalendar for the specified date.
 *
 * @param date//from  ww  w  .j  av  a 2  s  . c  o  m
 * @return
 * @throws DatatypeConfigurationException
 */
protected XMLGregorianCalendar getXmlDate(DateTime date) throws DatatypeConfigurationException {
    // construct an XMLGregorianCalendar
    DatatypeFactory datatypeFactory = DatatypeFactory.newInstance();
    XMLGregorianCalendar start = datatypeFactory.newXMLGregorianCalendar();
    start.setYear(date.getYear());
    start.setMonth(date.getMonthOfYear());
    start.setTime(date.getHourOfDay(), date.getMinuteOfHour(), date.getSecondOfMinute(),
            date.getMillisOfSecond());
    start.setDay(date.getDayOfMonth());
    return start;
}

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);/*from   w  w  w. j a v a2  s.  com*/
    start.setMonth(11);
    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());

}