Search in sources :

Example 6 with DateTime

use of org.mule.runtime.core.internal.el.datetime.DateTime in project mule by mulesoft.

the class DateTimeExpressionLanguageFunctionTestCase method parseFormattedStringWithTimeZone.

@Test
public void parseFormattedStringWithTimeZone() throws Exception {
    DateTime dateTime = (DateTime) dateTimeFunction.call(new Object[] { "17/3/13 00:23:00 -0700", "dd/M/yy hh:mm:ss ZZ" }, context);
    assertNotNull(dateTime);
    assertEquals(2013, dateTime.getYear());
    assertEquals(3, dateTime.getMonth());
    assertEquals(17, dateTime.getDayOfMonth());
    assertEquals(0, dateTime.getHours());
    assertEquals(23, dateTime.getMinutes());
    assertEquals(0, dateTime.getSeconds());
    assertEquals(-7 * 1000 * 60 * 60, dateTime.toCalendar().get(Calendar.ZONE_OFFSET));
}
Also used : DateTime(org.mule.runtime.core.internal.el.datetime.DateTime) Test(org.junit.Test) SmallTest(org.mule.tck.size.SmallTest)

Example 7 with DateTime

use of org.mule.runtime.core.internal.el.datetime.DateTime in project mule by mulesoft.

the class DateTimeExpressionLanguageFunctionTestCase method convertCalendar.

@Test
public void convertCalendar() throws Exception {
    Calendar cal = Calendar.getInstance();
    DateTime dateTime = (DateTime) dateTimeFunction.call(new Object[] { cal }, context);
    assertNotNull(dateTime);
    assertEquals(cal.get(Calendar.YEAR), dateTime.getYear());
    assertEquals(cal.get(Calendar.MONTH) + 1, dateTime.getMonth());
    assertEquals(cal.get(Calendar.DAY_OF_MONTH), dateTime.getDayOfMonth());
    assertEquals(cal.get(Calendar.HOUR_OF_DAY), dateTime.getHours());
    assertEquals(cal.get(Calendar.MINUTE), dateTime.getMinutes());
    assertEquals(cal.get(Calendar.SECOND), dateTime.getSeconds());
}
Also used : Calendar(java.util.Calendar) DateTime(org.mule.runtime.core.internal.el.datetime.DateTime) Test(org.junit.Test) SmallTest(org.mule.tck.size.SmallTest)

Example 8 with DateTime

use of org.mule.runtime.core.internal.el.datetime.DateTime in project mule by mulesoft.

the class DateTimeExpressionLanguageFunctionTestCase method parseFormattedString.

@Test
public void parseFormattedString() throws Exception {
    DateTime dateTime = (DateTime) dateTimeFunction.call(new Object[] { "17/3/13 00:23:00", "dd/M/yy hh:mm:ss" }, context);
    assertNotNull(dateTime);
    assertEquals(2013, dateTime.getYear());
    assertEquals(3, dateTime.getMonth());
    assertEquals(17, dateTime.getDayOfMonth());
    assertEquals(0, dateTime.getHours());
    assertEquals(23, dateTime.getMinutes());
    assertEquals(0, dateTime.getSeconds());
    assertEquals(0, dateTime.toCalendar().get(Calendar.ZONE_OFFSET));
}
Also used : DateTime(org.mule.runtime.core.internal.el.datetime.DateTime) Test(org.junit.Test) SmallTest(org.mule.tck.size.SmallTest)

Example 9 with DateTime

use of org.mule.runtime.core.internal.el.datetime.DateTime in project mule by mulesoft.

the class AbstractSerializerProtocolContractTestCase method serializeWithoutDefaultConstructor.

@Test
public final void serializeWithoutDefaultConstructor() throws Exception {
    Calendar calendar = Calendar.getInstance();
    Locale locale = Locale.ITALIAN;
    DateTime dateTime = new DateTime(calendar, locale);
    dateTime.changeTimeZone("Pacific/Midway");
    CoreEvent event = eventBuilder(muleContext).message(of(dateTime)).build();
    byte[] bytes = serializationProtocol.serialize(event.getMessage());
    InternalMessage message = serializationProtocol.deserialize(bytes);
    DateTime deserealized = (DateTime) message.getPayload().getValue();
    assertEquals(calendar, deserealized.toCalendar());
    assertEquals(dateTime.format(), deserealized.format());
}
Also used : Locale(java.util.Locale) InternalMessage(org.mule.runtime.core.internal.message.InternalMessage) CoreEvent(org.mule.runtime.core.api.event.CoreEvent) Calendar(java.util.Calendar) DateTime(org.mule.runtime.core.internal.el.datetime.DateTime) Test(org.junit.Test)

Example 10 with DateTime

use of org.mule.runtime.core.internal.el.datetime.DateTime in project mule by mulesoft.

the class DateTimeTestCase method fromDate.

@Test
public void fromDate() {
    Date date = new Date();
    date.setYear(0);
    date.setMonth(0);
    date.setDate(1);
    assertEquals(1900, new DateTime(date).getYear());
    assertEquals(1, new DateTime(date).getMonth());
    assertEquals(1, new DateTime(date).getDayOfMonth());
}
Also used : Date(java.util.Date) DateTime(org.mule.runtime.core.internal.el.datetime.DateTime) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)14 DateTime (org.mule.runtime.core.internal.el.datetime.DateTime)14 SmallTest (org.mule.tck.size.SmallTest)6 Calendar (java.util.Calendar)5 GregorianCalendar (java.util.GregorianCalendar)4 XMLGregorianCalendar (javax.xml.datatype.XMLGregorianCalendar)4 Date (java.util.Date)3 Locale (java.util.Locale)1 CoreEvent (org.mule.runtime.core.api.event.CoreEvent)1 InternalMessage (org.mule.runtime.core.internal.message.InternalMessage)1