Search in sources :

Example 6 with DateConverter

use of org.graylog2.inputs.converters.DateConverter in project graylog2-server by Graylog2.

the class DateConverterTest method convertUsesEtcUTCIfTimeZoneSettingIsEmpty.

@Test
public void convertUsesEtcUTCIfTimeZoneSettingIsEmpty() throws Exception {
    final Converter c = new DateConverter(config("YYYY-MM-dd HH:mm:ss", "", null));
    final DateTime dateTime = (DateTime) c.convert("2014-03-12 10:00:00");
    assertThat(dateTime).isEqualTo("2014-03-12T10:00:00.000Z");
}
Also used : Converter(org.graylog2.plugin.inputs.Converter) DateTime(org.joda.time.DateTime) Test(org.junit.Test)

Example 7 with DateConverter

use of org.graylog2.inputs.converters.DateConverter in project graylog2-server by Graylog2.

the class DateConverterTest method convertUsesEnglishIfLocaleIsNull.

@Test
public void convertUsesEnglishIfLocaleIsNull() throws Exception {
    final Converter c = new DateConverter(config("dd/MMM/YYYY HH:mm:ss Z", null, null));
    final DateTime dateTime = (DateTime) c.convert("11/May/2017 15:10:48 +0200");
    assertThat(dateTime).isEqualTo("2017-05-11T13:10:48.000Z");
}
Also used : Converter(org.graylog2.plugin.inputs.Converter) DateTime(org.joda.time.DateTime) Test(org.junit.Test)

Example 8 with DateConverter

use of org.graylog2.inputs.converters.DateConverter in project graylog2-server by Graylog2.

the class DateConverterTest method convertUsesEnglishIfLocaleIsInvalid.

@Test
public void convertUsesEnglishIfLocaleIsInvalid() throws Exception {
    final Converter c = new DateConverter(config("dd/MMM/YYYY HH:mm:ss Z", null, "Wurstweck"));
    final DateTime dateTime = (DateTime) c.convert("11/May/2017 15:10:48 +0200");
    assertThat(dateTime).isEqualTo("2017-05-11T13:10:48.000Z");
}
Also used : Converter(org.graylog2.plugin.inputs.Converter) DateTime(org.joda.time.DateTime) Test(org.junit.Test)

Example 9 with DateConverter

use of org.graylog2.inputs.converters.DateConverter in project graylog2-server by Graylog2.

the class DateConverterTest method convertUsesEtcUTCIfTimeZoneSettingIsBlank.

@Test
public void convertUsesEtcUTCIfTimeZoneSettingIsBlank() throws Exception {
    final Converter c = new DateConverter(config("YYYY-MM-dd HH:mm:ss", " ", null));
    final DateTime dateTime = (DateTime) c.convert("2014-03-12 10:00:00");
    assertThat(dateTime).isEqualTo("2014-03-12T10:00:00.000Z");
}
Also used : Converter(org.graylog2.plugin.inputs.Converter) DateTime(org.joda.time.DateTime) Test(org.junit.Test)

Example 10 with DateConverter

use of org.graylog2.inputs.converters.DateConverter in project graylog2-server by Graylog2.

the class DateConverterTest method convertObeysTimeZone.

@Test
public void convertObeysTimeZone() throws Exception {
    final DateTimeZone timeZone = DateTimeZone.forOffsetHours(12);
    final Converter c = new DateConverter(config("YYYY-MM-dd HH:mm:ss", timeZone.toString(), null));
    final DateTime dateOnly = (DateTime) c.convert("2014-03-12 10:00:00");
    assertThat(dateOnly).isEqualTo("2014-03-12T10:00:00.000+12:00");
    final DateTime dateTime = (DateTime) c.convert("2014-03-12 12:34:00");
    assertThat(dateTime).isEqualTo("2014-03-12T12:34:00.000+12:00");
}
Also used : Converter(org.graylog2.plugin.inputs.Converter) DateTimeZone(org.joda.time.DateTimeZone) DateTime(org.joda.time.DateTime) Test(org.junit.Test)

Aggregations

DateTime (org.joda.time.DateTime)10 Test (org.junit.Test)10 Converter (org.graylog2.plugin.inputs.Converter)9 DateConverter (org.graylog2.inputs.converters.DateConverter)1 Message (org.graylog2.plugin.Message)1 Result (org.graylog2.plugin.inputs.Extractor.Result)1 DateTimeZone (org.joda.time.DateTimeZone)1