Try to fix test failing due to timezones.

This commit is contained in:
Mark Nellemann 2020-09-23 08:19:24 +02:00
parent 688cbf12a3
commit 7a019c5c18
3 changed files with 2 additions and 6 deletions

View file

@ -4,8 +4,6 @@ Basic syslog server written in Java. All received messages are written to *stdou
The syslog server is able to listen on UDP and/or TCP and parses syslog messages in either RFC5424 or RFC3164 (BSD) format. The default syslog port (514) requires you to run syslogd as root / administrator. If you do not with to do so, you can choose a port number (with the -p flag) above 1024. The syslog server is able to listen on UDP and/or TCP and parses syslog messages in either RFC5424 or RFC3164 (BSD) format. The default syslog port (514) requires you to run syslogd as root / administrator. If you do not with to do so, you can choose a port number (with the -p flag) above 1024.
*This project is in no way associated with, supported or endorsed by, International Business Machines Corporation (IBM).*
## Usage Instructions ## Usage Instructions
- Install the syslogd package (*.deb* or *.rpm*) from [downloads](https://bitbucket.org/mnellemann/syslogd/downloads/) or compile from source. - Install the syslogd package (*.deb* or *.rpm*) from [downloads](https://bitbucket.org/mnellemann/syslogd/downloads/) or compile from source.

View file

@ -137,9 +137,7 @@ public class SyslogParser {
// Date: Mmm dd hh:mm:ss // Date: Mmm dd hh:mm:ss
Instant instant = null; Instant instant = null;
try { try {
DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy MMM dd HH:mm:ss") DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy MMM dd HH:mm:ss").withZone(ZoneOffset.UTC);
.withLocale(Locale.getDefault())
.withZone(ZoneId.systemDefault());
instant = Instant.from(dateTimeFormatter.parse(odt.getYear() + " " + dateString)); instant = Instant.from(dateTimeFormatter.parse(odt.getYear() + " " + dateString));
} catch(DateTimeParseException e) { } catch(DateTimeParseException e) {
log.error("parseDate()", e); log.error("parseDate()", e);

View file

@ -10,7 +10,7 @@ class SyslogParserTest extends Specification {
setup: setup:
OffsetDateTime odt = OffsetDateTime.now() OffsetDateTime odt = OffsetDateTime.now()
String dateString = "Sep 12 22:50:13" String dateString = "Sep 12 20:50:13"
when: when:
Instant inst = SyslogParser.parseRfc3164Timestamp(dateString) Instant inst = SyslogParser.parseRfc3164Timestamp(dateString)