Search in sources :

Example 6 with DateLocale

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

the class TextLoaderTest method testTimestampFormatNoLocale.

@Test
public void testTimestampFormatNoLocale() throws Exception {
    DateLocale locale = DateFormatUtils.enLocale;
    assertNoLeak(textLoader -> {
        String csv = "\"name\",\"date\"\n" + "\"Всероссийские спортивные соревнования школьников «ПРЕЗИДЕНТСКИЕ СОСТЯЗАНИЯ»\",\"3 " + locale.getMonth(6) + " 2017 г.\"\n" + "\"Всероссийские спортивные игры школьников «ПРЕЗИДЕНТСКИЕ СПОРТИВНЫЕ ИГРЫ»\",\"10 " + locale.getMonth(2) + " 2018 г.\"\n" + "\"Всероссийский летний ФЕСТИВАЛЬ ГТО\",\"28 " + locale.getMonth(1) + " 2016 г.\"\n";
        String expected = "name\tdate\n" + "Всероссийские спортивные соревнования школьников «ПРЕЗИДЕНТСКИЕ СОСТЯЗАНИЯ»\t2017-07-03T00:00:00.000000Z\n" + "Всероссийские спортивные игры школьников «ПРЕЗИДЕНТСКИЕ СПОРТИВНЫЕ ИГРЫ»\t2018-03-10T00:00:00.000000Z\n" + "Всероссийский летний ФЕСТИВАЛЬ ГТО\t2016-02-28T00:00:00.000000Z\n";
        configureLoaderDefaults(textLoader, (byte) ',', Atomicity.SKIP_COL);
        playJson(textLoader, ("[\n" + "  {\n" + "    \"name\": \"date\",\n" + "    \"type\": \"TIMESTAMP\",\n" + "    \"pattern\": \"d MMMM y г.\",\n" + "    \"utf8\": true\n" + "  }\n" + "]"));
        textLoader.setForceHeaders(true);
        textLoader.setState(TextLoader.ANALYZE_STRUCTURE);
        playText0(textLoader, csv, 1024, ENTITY_MANIPULATOR);
        sink.clear();
        textLoader.getMetadata().toJson(sink);
        TestUtils.assertEquals("{\"columnCount\":2,\"columns\":[{\"index\":0,\"name\":\"name\",\"type\":\"STRING\"},{\"index\":1,\"name\":\"date\",\"type\":\"TIMESTAMP\"}],\"timestampIndex\":-1}", sink);
        Assert.assertEquals(3L, textLoader.getParsedLineCount());
        Assert.assertEquals(3L, textLoader.getWrittenLineCount());
        assertTable(expected);
        textLoader.clear();
    });
}
Also used : DateLocale(io.questdb.std.datetime.DateLocale) Test(org.junit.Test) AbstractGriffinTest(io.questdb.griffin.AbstractGriffinTest)

Example 7 with DateLocale

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

the class TimestampsTest method testToTimezoneWithTimezoneName.

@Test
public void testToTimezoneWithTimezoneName() throws NumericException {
    DateLocale locale = DateLocaleFactory.INSTANCE.getLocale("en");
    long micros = TimestampFormatUtils.parseTimestamp("2019-12-10T10:00:00.000000Z");
    long offsetMicros = Timestamps.toTimezone(micros, locale, "Europe/Prague");
    TestUtils.assertEquals("2019-12-10T11:00:00.000Z", Timestamps.toString(offsetMicros));
}
Also used : DateLocale(io.questdb.std.datetime.DateLocale) Test(org.junit.Test)

Example 8 with DateLocale

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

the class TimestampsTest method testToUTCInvalidTimezoneName.

@Test(expected = NumericException.class)
public void testToUTCInvalidTimezoneName() throws NumericException {
    DateLocale locale = DateLocaleFactory.INSTANCE.getLocale("en");
    long micros = TimestampFormatUtils.parseTimestamp("2019-12-10T10:00:00.000000Z");
    Timestamps.toUTC(micros, locale, "Somewhere");
}
Also used : DateLocale(io.questdb.std.datetime.DateLocale) Test(org.junit.Test)

Example 9 with DateLocale

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

the class TimestampsTest method testToTimezoneWithHours.

@Test
public void testToTimezoneWithHours() throws NumericException {
    DateLocale locale = DateLocaleFactory.INSTANCE.getLocale("en");
    long micros = TimestampFormatUtils.parseTimestamp("2019-12-10T10:00:00.000000Z");
    long offsetMicros = Timestamps.toTimezone(micros, locale, "+03:45");
    TestUtils.assertEquals("2019-12-10T13:45:00.000Z", Timestamps.toString(offsetMicros));
}
Also used : DateLocale(io.questdb.std.datetime.DateLocale) Test(org.junit.Test)

Example 10 with DateLocale

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

the class TimestampsTest method testToUTCWithHours.

@Test
public void testToUTCWithHours() throws NumericException {
    DateLocale locale = DateLocaleFactory.INSTANCE.getLocale("en");
    long micros = TimestampFormatUtils.parseTimestamp("2019-12-10T10:00:00.000000Z");
    long offsetMicros = Timestamps.toUTC(micros, locale, "+03:45");
    TestUtils.assertEquals("2019-12-10T06:15:00.000Z", Timestamps.toString(offsetMicros));
}
Also used : DateLocale(io.questdb.std.datetime.DateLocale) Test(org.junit.Test)

Aggregations

DateLocale (io.questdb.std.datetime.DateLocale)12 Test (org.junit.Test)10 AbstractGriffinTest (io.questdb.griffin.AbstractGriffinTest)2 DateFormat (io.questdb.std.datetime.DateFormat)1 TimestampFormatCompiler (io.questdb.std.datetime.microtime.TimestampFormatCompiler)1 Path (io.questdb.std.str.Path)1