question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Replace LocalDateTime with Instant

See original GitHub issue

This issue concerns the support for the Logical Avro type timestamp_ms.

At present, the avrohugger maps the logical avro type timestamp_ms to the java.date.LocalDateTime Java class. We propose that, instead, the timestamp_ms logical type should be mapped to the java.time.Instant Java class.

The Avro logical type timestamp_ms is described in the specification as follows:

[…] represents an instant on the global timeline […] annotates an Avro long, where the long stores the number of milliseconds from the unix epoch, 1 January 1970 00:00:00.000 UTC.

This corresponds directly with the description of the java.time.Instant class, which says:

This class models a single instantaneous point on the time-line. This might be used to record event time-stamps in the application. […] The epoch-seconds are measured from the standard Java epoch of 1970-01-01T00:00:00Z

The LocalDateTime class is described in the documentation as serving a different purpose, more related to the human-readable descriptions of dates:

A date-time without a time-zone in the ISO-8601 calendar system. LocalDateTime is an immutable date-time object that represents a date-time, often viewed as year-month-day-hour-minute-second. This class does not store or represent a time-zone. […] It cannot represent an instant on the time-line without additional information such as an offset or time-zone.

Related Issues

Support for the logical timestamp_ms type was introduced in PR #87 by @raulraja, and a change to generate the converters is currently submitted in PR #88.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:3
  • Comments:8 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
julianpeeterscommented, Jul 10, 2018

Would you accept adding the needed marshalers to the tests for sbt-avrohugger

yep! nice solution

0reactions
diesalblacommented, Jul 10, 2018

Freestyle needs avro4s compatibility, correct? It’s not just the scripted tests that need it?

freestyle-rpc uses avro4s for marshalling and unmarshalling from Avro. However, for those types not directly supported by avro4s, it defines its own instances, as you can see here

I’m fairly opposed to adding avro4s-specific code the generated classes, avrohugger should just generate plain old case classes for this use case IMO.

I understand, and agree, that avrohugger should be only about code generation, not marshalling-unmarshalling. Would you accept adding the needed marshalers to the tests for sbt-avrohugger?

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to convert a LocalDate to an Instant? - Stack Overflow
LocalDate date = LocalDate.now(); Instant instant = date.atStartOfDay(ZoneId.systemDefault()).toInstant();. This example uses the default ...
Read more >
Convert between Java LocalDateTime and Instant
This page will provide how to convert between Java LocalDateTime and Instant . The LocalDateTime represents date-time without a time-zone ...
Read more >
Java 8 Date - LocalDate, LocalDateTime, Instant - DigitalOcean
LocalDate is an immutable class that represents Date with default format of yyyy-MM-dd. We can use now() method to get the current date....
Read more >
Convert LocalDate to Instant in Java - Java2Blog
Use ZoneDateTime 's toInstant() method to convert LocalDate to Instant in Java. If you want to have default timezone, you can use ZoneId....
Read more >
Convert Date to LocalDate or LocalDateTime and Back
Starting with Java 8, we can find an additional toLocalDate() method on java.sql.Date, which also gives us an easy way of converting it...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found