Add Converters to the Database
Inside the data package, add a new class called Converters. This class will contain eight functions corresponding to four sets of conversions: OffsetDateTime to/from String, GameState to/from Int, List<Int> to/from String, and AI to Int.
The OffsetDateTime converter functions, used with the startTime and endTime properties inside the Game class, translate OffsetDateTime objects to and from a formatted string using a DateTimeFormatter object. You’re welcome to use any logical date/time format here; I’m using DateTimeFormatter.ISO_OFFSET_DATE_TIME since it has all the information we need and is a standardized format. For reference, date/time text in this format will look like 2014-01-24T15:45:05.023Z.
| private |
Get Kotlin and Android Development featuring Jetpack now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.