use of org.joda.time.MutableDateTime in project druid by druid-io.
the class FileRequestLogger method start.
@LifecycleStart
public void start() {
try {
baseDir.mkdirs();
MutableDateTime mutableDateTime = new DateTime().toMutableDateTime();
mutableDateTime.setMillisOfDay(0);
synchronized (lock) {
currentDay = mutableDateTime.toDateTime();
fileWriter = getFileWriter();
}
long nextDay = currentDay.plusDays(1).getMillis();
Duration delay = new Duration(nextDay - new DateTime().getMillis());
ScheduledExecutors.scheduleWithFixedDelay(exec, delay, Duration.standardDays(1), new Callable<ScheduledExecutors.Signal>() {
@Override
public ScheduledExecutors.Signal call() {
try {
synchronized (lock) {
currentDay = currentDay.plusDays(1);
CloseQuietly.close(fileWriter);
fileWriter = getFileWriter();
}
} catch (Exception e) {
Throwables.propagate(e);
}
return ScheduledExecutors.Signal.REPEAT;
}
});
} catch (IOException e) {
Throwables.propagate(e);
}
}
use of org.joda.time.MutableDateTime in project h2o-2 by h2oai.
the class ASTLs method apply.
@Override
void apply(Env env, int argcnt, ASTApply apply) {
// Single instance of MDT for the single call
if (!env.isAry()) {
// Single point
double d = env.popDbl();
if (!Double.isNaN(d))
d = op(new MutableDateTime((long) d));
env.poppush(d);
return;
}
// Whole column call
Frame fr = env.popAry();
String skey = env.key();
// Final 'this' so can use in closure
final ASTTimeOp uni = this;
Frame fr2 = new MRTask2() {
@Override
public void map(Chunk[] chks, NewChunk[] nchks) {
MutableDateTime dt = new MutableDateTime(0);
for (int i = 0; i < nchks.length; i++) {
NewChunk n = nchks[i];
Chunk c = chks[i];
int rlen = c._len;
for (int r = 0; r < rlen; r++) {
double d = c.at0(r);
if (!Double.isNaN(d)) {
dt.setMillis((long) d);
d = uni.op(dt);
}
n.addNum(d);
}
}
}
}.doAll(fr.numCols(), fr).outputFrame(fr._names, null);
env.subRef(fr, skey);
// Pop self
env.pop();
env.push(fr2);
}
use of org.joda.time.MutableDateTime in project gerrit by GerritCodeReview.
the class ScheduleConfig method initialDelay.
private static long initialDelay(Config rc, String section, String subsection, String keyStartTime, DateTime now, long interval) {
long delay = MISSING_CONFIG;
String start = rc.getString(section, subsection, keyStartTime);
try {
if (start != null) {
DateTimeFormatter formatter;
MutableDateTime startTime = now.toMutableDateTime();
try {
formatter = ISODateTimeFormat.hourMinute();
LocalTime firstStartTime = formatter.parseLocalTime(start);
startTime.hourOfDay().set(firstStartTime.getHourOfDay());
startTime.minuteOfHour().set(firstStartTime.getMinuteOfHour());
} catch (IllegalArgumentException e1) {
formatter = DateTimeFormat.forPattern("E HH:mm").withLocale(Locale.US);
LocalDateTime firstStartDateTime = formatter.parseLocalDateTime(start);
startTime.dayOfWeek().set(firstStartDateTime.getDayOfWeek());
startTime.hourOfDay().set(firstStartDateTime.getHourOfDay());
startTime.minuteOfHour().set(firstStartDateTime.getMinuteOfHour());
}
startTime.secondOfMinute().set(0);
startTime.millisOfSecond().set(0);
long s = startTime.getMillis();
long n = now.getMillis();
delay = (s - n) % interval;
if (delay <= 0) {
delay += interval;
}
} else {
log.info(MessageFormat.format("{0} schedule parameter \"{0}.{1}\" is not configured", section, keyStartTime));
}
} catch (IllegalArgumentException e2) {
log.error(MessageFormat.format("Invalid {0} schedule parameter \"{0}.{1}\"", section, keyStartTime), e2);
delay = INVALID_CONFIG;
}
return delay;
}
use of org.joda.time.MutableDateTime in project joda-time by JodaOrg.
the class TestTextFields method testHalfdayNames.
public void testHalfdayNames() {
DateTimeFormatter printer = DateTimeFormat.forPattern("a");
for (int i = 0; i < ZONES.length; i++) {
Chronology chrono = ISOChronology.getInstance(ZONES[i]);
MutableDateTime mdt = new MutableDateTime(2004, 5, 30, 0, 20, 30, 40, chrono);
for (int hour = 0; hour < 24; hour++) {
mdt.setHourOfDay(hour);
int halfday = mdt.get(chrono.halfdayOfDay());
String halfdayText = printer.print(mdt);
assertEquals(HALFDAYS[halfday], halfdayText);
}
}
}
use of org.joda.time.MutableDateTime in project joda-time by JodaOrg.
the class DateTimePerformance method checkJodaSetHour.
// Set hour
//------------------------------------------------------------------------
private void checkJodaSetHour() {
int COUNT = COUNT_VERY_FAST;
// Is it fair to use only MutableDateTime here? You decide.
MutableDateTime dt = new MutableDateTime(GJChronology.getInstance());
for (int i = 0; i < AVERAGE; i++) {
start("Joda", "setHour");
for (int j = 0; j < COUNT; j++) {
dt.setHourOfDay(13);
if (dt == null) {
System.out.println("Anti optimise");
}
}
end(COUNT);
}
}
Aggregations