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);
}
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);
}
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();
}
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())));
}
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));
}
Aggregations