Search in sources :

Example 26 with MutableDateTime

use of org.joda.time.MutableDateTime in project joda-time by JodaOrg.

the class TestDateTimeFormatter method testParseInto_monthDay_feb29_tokyo.

public void testParseInto_monthDay_feb29_tokyo() {
    DateTimeFormatter f = DateTimeFormat.forPattern("M d").withLocale(Locale.UK);
    MutableDateTime result = new MutableDateTime(2004, 1, 9, 12, 20, 30, 0, TOKYO);
    assertEquals(4, f.parseInto(result, "2 29", 0));
    assertEquals(new MutableDateTime(2004, 2, 29, 12, 20, 30, 0, TOKYO), result);
}
Also used : MutableDateTime(org.joda.time.MutableDateTime)

Example 27 with MutableDateTime

use of org.joda.time.MutableDateTime in project joda-time by JodaOrg.

the class AbstractInstant method toMutableDateTime.

/**
     * Get this object as a MutableDateTime using the same chronology but a different zone.
     * 
     * @param zone time zone to apply, or default if null
     * @return a MutableDateTime using the same millis
     */
public MutableDateTime toMutableDateTime(DateTimeZone zone) {
    Chronology chrono = DateTimeUtils.getChronology(getChronology());
    chrono = chrono.withZone(zone);
    return new MutableDateTime(getMillis(), chrono);
}
Also used : MutableDateTime(org.joda.time.MutableDateTime) Chronology(org.joda.time.Chronology) ISOChronology(org.joda.time.chrono.ISOChronology)

Example 28 with MutableDateTime

use of org.joda.time.MutableDateTime in project Protocol-Adapter-OSLP by OSGP.

the class OslpGetConfigurationResponseToConfigurationConverter method getLastDayOfMonth.

/**
 * For a given Month of this year, find the date for the weekday {@link day}
 * .
 */
private int getLastDayOfMonth(final int month, final int day) {
    final DateTime dateTime = DateTime.now();
    MutableDateTime x = dateTime.toMutableDateTime();
    x.set(DateTimeFieldType.monthOfYear(), month);
    x.set(DateTimeFieldType.dayOfMonth(), 31);
    x = this.findLastDayOfOfMonth(day, x);
    return x.getDayOfMonth();
}
Also used : MutableDateTime(org.joda.time.MutableDateTime) DateTime(org.joda.time.DateTime) MutableDateTime(org.joda.time.MutableDateTime)

Example 29 with MutableDateTime

use of org.joda.time.MutableDateTime in project components by Talend.

the class SearchQueryTest method testSearchDateField.

@Test
public void testSearchDateField() throws Exception {
    DateTimeFormatter dateFormatter = DateTimeFormat.forPattern("yyyy-MM-dd");
    DateTimeFormatter dateTimeFormatter = DateTimeFormat.forPattern("yyyy-MM-dd HH:mm:ss");
    DateTimeFormatter timeFormatter = DateTimeFormat.forPattern("HH:mm:ss");
    Instant now = Instant.now();
    String currentDateFormatted = dateFormatter.print(now.getMillis());
    SearchQuery s1 = clientService.newSearch();
    s1.target("Check");
    s1.condition(new SearchCondition("TranDate", "Date.onOrAfter", Arrays.asList("2017-01-01 12:00:00")));
    s1.condition(new SearchCondition("CustomDateField1", "Date.onOrAfter", Arrays.asList("14:00:00")));
    SearchRecord sr1 = (SearchRecord) s1.toNativeQuery();
    assertNotNull(sr1);
    Assert.assertEquals(TransactionSearch.class, sr1.getClass());
    TransactionSearch search = (TransactionSearch) sr1;
    assertNotNull(search.getBasic());
    TransactionSearchBasic searchBasic = search.getBasic();
    assertNotNull(searchBasic.getTranDate());
    SearchDateField field1 = searchBasic.getTranDate();
    Assert.assertEquals(SearchDateFieldOperator.ON_OR_AFTER, field1.getOperator());
    assertNotNull(field1.getSearchValue());
    assertNull(field1.getSearchValue2());
    assertEquals("2017-01-01 12:00:00", dateTimeFormatter.print((Long) calendarValueConverter.convertToAvro(field1.getSearchValue())));
    SearchCustomFieldList customFieldList = searchBasic.getCustomFieldList();
    assertNotNull(customFieldList);
    assertNotNull(customFieldList.getCustomField());
    Assert.assertEquals(1, customFieldList.getCustomField().size());
    MutableDateTime controlDateTime = new MutableDateTime();
    controlDateTime.setHourOfDay(14);
    controlDateTime.setMinuteOfHour(0);
    controlDateTime.setSecondOfMinute(0);
    controlDateTime.setMillisOfSecond(0);
    String controlTimeFormatted = timeFormatter.print(controlDateTime);
    SearchDateCustomField customField1 = (SearchDateCustomField) customFieldList.getCustomField().get(0);
    Assert.assertEquals(SearchDateFieldOperator.ON_OR_AFTER, customField1.getOperator());
    assertNotNull(customField1.getSearchValue());
    assertNull(customField1.getSearchValue2());
    assertEquals(currentDateFormatted + " " + controlTimeFormatted, dateTimeFormatter.print((Long) calendarValueConverter.convertToAvro(customField1.getSearchValue())));
}
Also used : SearchQuery(org.talend.components.netsuite.client.search.SearchQuery) TransactionSearch(com.netsuite.webservices.test.transactions.sales.TransactionSearch) Instant(org.joda.time.Instant) SearchDateField(com.netsuite.webservices.test.platform.core.SearchDateField) MutableDateTime(org.joda.time.MutableDateTime) TransactionSearchBasic(com.netsuite.webservices.test.platform.common.TransactionSearchBasic) SearchCustomFieldList(com.netsuite.webservices.test.platform.core.SearchCustomFieldList) SearchRecord(com.netsuite.webservices.test.platform.core.SearchRecord) SearchDateCustomField(com.netsuite.webservices.test.platform.core.SearchDateCustomField) SearchCondition(org.talend.components.netsuite.client.search.SearchCondition) DateTimeFormatter(org.joda.time.format.DateTimeFormatter) Test(org.junit.Test)

Example 30 with MutableDateTime

use of org.joda.time.MutableDateTime in project components by Talend.

the class ValueConverterTest method testXMLGregorianCalendarConverter.

@Test
public void testXMLGregorianCalendarConverter() throws Exception {
    DateTimeZone tz1 = DateTimeZone.getDefault();
    MutableDateTime dateTime1 = new MutableDateTime(tz1);
    dateTime1.setDate(System.currentTimeMillis());
    Long controlValue1 = dateTime1.getMillis();
    XMLGregorianCalendar xmlCalendar1 = datatypeFactory.newXMLGregorianCalendar();
    xmlCalendar1.setYear(dateTime1.getYear());
    xmlCalendar1.setMonth(dateTime1.getMonthOfYear());
    xmlCalendar1.setDay(dateTime1.getDayOfMonth());
    xmlCalendar1.setHour(dateTime1.getHourOfDay());
    xmlCalendar1.setMinute(dateTime1.getMinuteOfHour());
    xmlCalendar1.setSecond(dateTime1.getSecondOfMinute());
    xmlCalendar1.setMillisecond(dateTime1.getMillisOfSecond());
    xmlCalendar1.setTimezone(tz1.toTimeZone().getOffset(dateTime1.getMillis()) / 60000);
    FieldDesc fieldInfo = typeDesc.getField("tranDate");
    NsObjectInputTransducer transducer = new NsObjectInputTransducer(clientService, schema, typeDesc.getTypeName());
    AvroConverter<XMLGregorianCalendar, Long> converter1 = (AvroConverter<XMLGregorianCalendar, Long>) transducer.getValueConverter(fieldInfo);
    assertEquals(AvroUtils._logicalTimestamp(), converter1.getSchema());
    assertEquals(XMLGregorianCalendar.class, converter1.getDatumClass());
    assertEquals(controlValue1, converter1.convertToAvro(xmlCalendar1));
    assertEquals(xmlCalendar1, converter1.convertToDatum(controlValue1));
    AvroConverter<XMLGregorianCalendar, Object> converter2 = (AvroConverter<XMLGregorianCalendar, Object>) transducer.getValueConverter(fieldInfo);
    assertEquals(xmlCalendar1, converter2.convertToDatum(new Date(controlValue1.longValue())));
    assertNull(converter1.convertToAvro(null));
}
Also used : XMLGregorianCalendar(javax.xml.datatype.XMLGregorianCalendar) MutableDateTime(org.joda.time.MutableDateTime) NsObjectInputTransducer(org.talend.components.netsuite.input.NsObjectInputTransducer) DateTimeZone(org.joda.time.DateTimeZone) AvroConverter(org.talend.daikon.avro.converter.AvroConverter) Date(java.util.Date) FieldDesc(org.talend.components.netsuite.client.model.FieldDesc) Test(org.junit.Test)

Aggregations

MutableDateTime (org.joda.time.MutableDateTime)76 DateTime (org.joda.time.DateTime)12 Instant (org.joda.time.Instant)6 DateTimeFormatter (org.joda.time.format.DateTimeFormatter)6 Date (java.util.Date)5 Chronology (org.joda.time.Chronology)4 DateTimeZone (org.joda.time.DateTimeZone)4 ISOChronology (org.joda.time.chrono.ISOChronology)4 Test (org.junit.Test)4 ArrayList (java.util.ArrayList)3 IntervalWindow (org.apache.beam.sdk.transforms.windowing.IntervalWindow)3 SlidingWindows (org.apache.beam.sdk.transforms.windowing.SlidingWindows)3 FileNotFoundException (java.io.FileNotFoundException)2 IOException (java.io.IOException)2 XMLGregorianCalendar (javax.xml.datatype.XMLGregorianCalendar)2 KV (org.apache.beam.sdk.values.KV)2 TimestampedValue (org.apache.beam.sdk.values.TimestampedValue)2 Duration (org.joda.time.Duration)2 Category (org.junit.experimental.categories.Category)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1