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