use of org.joda.time.MutableDateTime in project components by Talend.
the class XMLGregorianCalendarToDateTimeConverter method convertToAvro.
@Override
public Object convertToAvro(XMLGregorianCalendar xts) {
if (xts == null) {
return null;
}
MutableDateTime dateTime = new MutableDateTime();
try {
dateTime.setYear(xts.getYear());
dateTime.setMonthOfYear(xts.getMonth());
dateTime.setDayOfMonth(xts.getDay());
dateTime.setHourOfDay(xts.getHour());
dateTime.setMinuteOfHour(xts.getMinute());
dateTime.setSecondOfMinute(xts.getSecond());
dateTime.setMillisOfSecond(xts.getMillisecond());
DateTimeZone tz = DateTimeZone.forOffsetMillis(xts.getTimezone() * 60000);
if (tz != null) {
dateTime.setZoneRetainFields(tz);
}
return Long.valueOf(dateTime.getMillis());
} catch (IllegalArgumentException e) {
throw new ComponentException(e);
}
}
use of org.joda.time.MutableDateTime in project ma-core-public by infiniteautomation.
the class Interpolation method updateYear.
public static List<PointValueTime> updateYear(List<PointValueTime> pvts, int year) {
List<PointValueTime> result = new ArrayList<PointValueTime>(pvts.size());
MutableDateTime mdt = new MutableDateTime();
for (PointValueTime pvt : pvts) {
mdt.setMillis(pvt.getTime());
mdt.setYear(year);
result.add(new PointValueTime(pvt.getValue(), mdt.getMillis()));
}
return result;
}
use of org.joda.time.MutableDateTime in project actframework by actframework.
the class CronExpression method nextTimeAfter.
public DateTime nextTimeAfter(DateTime afterTime, DateTime dateTimeBarrier) {
MutableDateTime nextTime = new MutableDateTime(afterTime);
nextTime.setMillisOfSecond(0);
nextTime.secondOfDay().add(1);
while (true) {
// day of week
while (true) {
// month
while (true) {
// day of month
while (true) {
// hour
while (true) {
// minute
while (true) {
// second
if (secondField.matches(nextTime.getSecondOfMinute())) {
break;
}
nextTime.secondOfDay().add(1);
}
if (minuteField.matches(nextTime.getMinuteOfHour())) {
break;
}
nextTime.minuteOfDay().add(1);
nextTime.secondOfMinute().set(0);
}
if (hourField.matches(nextTime.getHourOfDay())) {
break;
}
nextTime.hourOfDay().add(1);
nextTime.minuteOfHour().set(0);
nextTime.secondOfMinute().set(0);
}
if (dayOfMonthField.matches(new LocalDate(nextTime))) {
break;
}
nextTime.addDays(1);
nextTime.setTime(0, 0, 0, 0);
checkIfDateTimeBarrierIsReached(nextTime, dateTimeBarrier);
}
if (monthField.matches(nextTime.getMonthOfYear())) {
break;
}
nextTime.addMonths(1);
nextTime.setDayOfMonth(1);
nextTime.setTime(0, 0, 0, 0);
checkIfDateTimeBarrierIsReached(nextTime, dateTimeBarrier);
}
if (dayOfWeekField.matches(new LocalDate(nextTime))) {
break;
}
nextTime.addDays(1);
nextTime.setTime(0, 0, 0, 0);
checkIfDateTimeBarrierIsReached(nextTime, dateTimeBarrier);
}
return nextTime.toDateTime();
}
use of org.joda.time.MutableDateTime in project beam by apache.
the class SplittableDoFnTest method testPairWithIndexWindowedTimestamped.
private void testPairWithIndexWindowedTimestamped(IsBounded bounded) {
// Tests that Splittable DoFn correctly propagates windowing strategy, windows and timestamps
// of elements in the input collection.
MutableDateTime mutableNow = Instant.now().toMutableDateTime();
mutableNow.setMillisOfSecond(0);
Instant now = mutableNow.toInstant();
Instant nowP1 = now.plus(Duration.standardSeconds(1));
Instant nowP2 = now.plus(Duration.standardSeconds(2));
SlidingWindows windowFn = SlidingWindows.of(Duration.standardSeconds(5)).every(Duration.standardSeconds(1));
PCollection<KV<String, Integer>> res = p.apply(Create.timestamped(TimestampedValue.of("a", now), TimestampedValue.of("bb", nowP1), TimestampedValue.of("ccccc", nowP2))).apply(Window.into(windowFn)).apply(ParDo.of(pairStringWithIndexToLengthFn(bounded))).setCoder(KvCoder.of(StringUtf8Coder.of(), BigEndianIntegerCoder.of()));
assertEquals(windowFn, res.getWindowingStrategy().getWindowFn());
PCollection<TimestampedValue<KV<String, Integer>>> timestamped = res.apply(Reify.timestamps());
for (int i = 0; i < 4; ++i) {
Instant base = now.minus(Duration.standardSeconds(i));
IntervalWindow window = new IntervalWindow(base, base.plus(Duration.standardSeconds(5)));
List<TimestampedValue<KV<String, Integer>>> expectedUnfiltered = Arrays.asList(TimestampedValue.of(KV.of("a", 0), now), TimestampedValue.of(KV.of("bb", 0), nowP1), TimestampedValue.of(KV.of("bb", 1), nowP1), TimestampedValue.of(KV.of("ccccc", 0), nowP2), TimestampedValue.of(KV.of("ccccc", 1), nowP2), TimestampedValue.of(KV.of("ccccc", 2), nowP2), TimestampedValue.of(KV.of("ccccc", 3), nowP2), TimestampedValue.of(KV.of("ccccc", 4), nowP2));
List<TimestampedValue<KV<String, Integer>>> expected = new ArrayList<>();
for (TimestampedValue<KV<String, Integer>> tv : expectedUnfiltered) {
if (!window.start().isAfter(tv.getTimestamp()) && !tv.getTimestamp().isAfter(window.maxTimestamp())) {
expected.add(tv);
}
}
assertFalse(expected.isEmpty());
PAssert.that(timestamped).inWindow(window).containsInAnyOrder(expected);
}
p.run();
}
use of org.joda.time.MutableDateTime in project druid by druid-io.
the class FileRequestLogger method start.
@LifecycleStart
@Override
public void start() {
try {
FileUtils.mkdirp(baseDir);
MutableDateTime mutableDateTime = DateTimes.nowUtc().toMutableDateTime(ISOChronology.getInstanceUTC());
mutableDateTime.setMillisOfDay(0);
synchronized (lock) {
currentDay = mutableDateTime.toDateTime(ISOChronology.getInstanceUTC());
fileWriter = getFileWriter();
}
long nextDay = currentDay.plusDays(1).getMillis();
Duration initialDelay = new Duration(nextDay - System.currentTimeMillis());
ScheduledExecutors.scheduleWithFixedDelay(exec, initialDelay, Duration.standardDays(1), new Callable<ScheduledExecutors.Signal>() {
@Override
public ScheduledExecutors.Signal call() {
try {
synchronized (lock) {
currentDay = currentDay.plusDays(1);
CloseableUtils.closeAndSuppressExceptions(fileWriter, e -> log.warn("Could not close log file for %s. Creating new log file anyway.", currentDay));
fileWriter = getFileWriter();
}
} catch (Exception e) {
throw new RuntimeException(e);
}
return ScheduledExecutors.Signal.REPEAT;
}
});
} catch (IOException e) {
throw new RuntimeException(e);
}
}
Aggregations