Search in sources :

Example 6 with MutableDateTime

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);
    }
}
Also used : MutableDateTime(org.joda.time.MutableDateTime) Duration(org.joda.time.Duration) IOException(java.io.IOException) DateTime(org.joda.time.DateTime) MutableDateTime(org.joda.time.MutableDateTime) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) LifecycleStart(io.druid.java.util.common.lifecycle.LifecycleStart)

Example 7 with MutableDateTime

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);
}
Also used : MutableDateTime(org.joda.time.MutableDateTime)

Example 8 with MutableDateTime

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;
}
Also used : LocalDateTime(org.joda.time.LocalDateTime) LocalTime(org.joda.time.LocalTime) MutableDateTime(org.joda.time.MutableDateTime) DateTimeFormatter(org.joda.time.format.DateTimeFormatter)

Example 9 with MutableDateTime

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);
        }
    }
}
Also used : MutableDateTime(org.joda.time.MutableDateTime) Chronology(org.joda.time.Chronology) ISOChronology(org.joda.time.chrono.ISOChronology)

Example 10 with MutableDateTime

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);
    }
}
Also used : MutableDateTime(org.joda.time.MutableDateTime)

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