Search in sources :

Example 6 with DateFormat

use of io.questdb.std.datetime.DateFormat in project questdb by bluestreak01.

the class DateFormatCompilerTest method assertThat.

private void assertThat(String pattern, String expected, String input, DateLocale locale) throws NumericException {
    DateFormat format = get(pattern);
    TestUtils.assertEquals(expected, Dates.toString(format.parse(input, locale)));
    DateFormat compiled = compiler.compile(pattern);
    TestUtils.assertEquals(expected, Dates.toString(compiled.parse(input, locale)));
}
Also used : DateFormat(io.questdb.std.datetime.DateFormat)

Example 7 with DateFormat

use of io.questdb.std.datetime.DateFormat in project questdb by bluestreak01.

the class DateFormatCompilerTest method testFormatBSTtoMSK.

@Test
public void testFormatBSTtoMSK() throws Exception {
    DateFormat fmt = get("dd-MM-yyyy HH:mm:ss Z");
    String targetTimezoneName = "MSK";
    long millis = fmt.parse("06-04-2017 01:09:30 BST", defaultLocale);
    millis += defaultLocale.getRules(targetTimezoneName, RESOLUTION_MILLIS).getOffset(millis);
    sink.clear();
    fmt.format(millis, defaultLocale, targetTimezoneName, sink);
    TestUtils.assertEquals("06-04-2017 03:09:30 MSK", sink);
}
Also used : DateFormat(io.questdb.std.datetime.DateFormat) Test(org.junit.Test)

Example 8 with DateFormat

use of io.questdb.std.datetime.DateFormat in project questdb by bluestreak01.

the class TimestampFormatCompilerTest method assertThat.

private void assertThat(String pattern, String expected, String input, DateLocale locale) throws NumericException {
    DateFormat format = get(pattern);
    TestUtils.assertEquals(expected, Timestamps.toString(format.parse(input, locale)));
    DateFormat compiled = compiler.compile(pattern);
    TestUtils.assertEquals(expected, Timestamps.toString(compiled.parse(input, locale)));
}
Also used : DateFormat(io.questdb.std.datetime.DateFormat)

Example 9 with DateFormat

use of io.questdb.std.datetime.DateFormat in project questdb by bluestreak01.

the class TimestampFormatCompilerTest method testBasicParserCompiler.

@Test
public void testBasicParserCompiler() throws Exception {
    DateFormat fmt = compiler.compile("E, dd MMM yyyy a KK:m:s.S Z");
    String utcPattern = "yyyy-MM-ddTHH:mm:ss.SSSz";
    DateFormat utc = compiler.compile(utcPattern);
    long millis = fmt.parse("Mon, 08 Apr 2017 PM 11:11:10.123 UTC", defaultLocale);
    sink.clear();
    utc.format(millis, defaultLocale, "Z", sink);
    TestUtils.assertEquals("2017-04-08T23:11:10.123Z", sink);
}
Also used : DateFormat(io.questdb.std.datetime.DateFormat) Test(org.junit.Test)

Example 10 with DateFormat

use of io.questdb.std.datetime.DateFormat in project questdb by bluestreak01.

the class ToStrDateFunctionFactory method newInstance.

@Override
public Function newInstance(int position, ObjList<Function> args, IntList argPositions, CairoConfiguration configuration, SqlExecutionContext sqlExecutionContext) throws SqlException {
    Function fmt = args.getQuick(1);
    CharSequence format = fmt.getStr(null);
    if (format == null) {
        throw SqlException.$(argPositions.getQuick(1), "format must not be null");
    }
    DateFormat dateFormat = tlCompiler.get().compile(fmt.getStr(null));
    Function var = args.getQuick(0);
    if (var.isConstant()) {
        long value = var.getDate(null);
        if (value == Numbers.LONG_NaN) {
            return StrConstant.NULL;
        }
        StringSink sink = tlSink.get();
        sink.clear();
        dateFormat.format(value, configuration.getDefaultDateLocale(), "Z", sink);
        return new StrConstant(sink);
    }
    return new ToCharDateVCFFunc(args.getQuick(0), tlCompiler.get().compile(format), configuration.getDefaultDateLocale());
}
Also used : UnaryFunction(io.questdb.griffin.engine.functions.UnaryFunction) Function(io.questdb.cairo.sql.Function) StrFunction(io.questdb.griffin.engine.functions.StrFunction) DateFormat(io.questdb.std.datetime.DateFormat) StringSink(io.questdb.std.str.StringSink) StrConstant(io.questdb.griffin.engine.functions.constants.StrConstant)

Aggregations

DateFormat (io.questdb.std.datetime.DateFormat)18 Test (org.junit.Test)8 Record (io.questdb.cairo.sql.Record)4 RecordCursor (io.questdb.cairo.sql.RecordCursor)4 Function (io.questdb.cairo.sql.Function)2 StrFunction (io.questdb.griffin.engine.functions.StrFunction)2 UnaryFunction (io.questdb.griffin.engine.functions.UnaryFunction)2 StrConstant (io.questdb.griffin.engine.functions.constants.StrConstant)2 TimestampFormatCompiler (io.questdb.std.datetime.microtime.TimestampFormatCompiler)2 Path (io.questdb.std.str.Path)2 StringSink (io.questdb.std.str.StringSink)2 BindVariableServiceImpl (io.questdb.griffin.engine.functions.bind.BindVariableServiceImpl)1 FilesFacade (io.questdb.std.FilesFacade)1 FilesFacadeImpl (io.questdb.std.FilesFacadeImpl)1 DateLocale (io.questdb.std.datetime.DateLocale)1 File (java.io.File)1