Implement parsing and formatting for Instant as separate functions#411
Implement parsing and formatting for Instant as separate functions#411dkhalanskyjb wants to merge 6 commits into
Conversation
71fc711 to
fd78536
Compare
| total += (y + 3) / 4 - (y + 99) / 100 + (y + 399) / 400 | ||
| } else { | ||
| total -= y / -4 - y / -100 + y / -400 |
fd78536 to
019c71b
Compare
| private fun parseInstant(isoString: String): Instant { | ||
| // return Instant.parse(isoString) | ||
| return parseIso(isoString) | ||
| } | ||
|
|
||
| private fun displayInstant(instant: Instant): String { | ||
| // return instant.toString() | ||
| return formatIso(instant) | ||
| } |
There was a problem hiding this comment.
@qurbonzoda, here's the logic behind this PR: the newly-added formatIso can replace toString, and the newly-added parseIso can replace Instant.parse in the case when no specific format is passed (which is the only case supported by `kotlin.time.Instant).
023b7ac to
ece4e11
Compare
| expect("'T' or 't'", i + 6) { it == 'T' || it == 't' } | ||
| expect("':'", i + 9) { it == ':' } | ||
| expect("':'", i + 12) { it == ':' } | ||
| for (j in listOf(1, 2, 4, 5, 7, 8, 10, 11, 13, 14)) { |
There was a problem hiding this comment.
Better to extract such index lists to variables outside the function and (optionally) make them arrays.
f77c2a0 to
3de6ba9
Compare
| override fun toString(): String = "UnboundedLocalDateTime($year-$month-$day $hour:$minute:$second.$nanosecond)" | ||
|
|
||
| companion object { | ||
| fun fromInstant(instant: Instant, offsetSeconds: Int): UnboundedLocalDateTime { |
There was a problem hiding this comment.
There is only one call to this function, and it passes 0 for offsetSeconds.
There was a problem hiding this comment.
Yes. Do you see any problems with that?
| fun parseFailure(error: String): Nothing { | ||
| throw IllegalArgumentException("$error when parsing an Instant from $isoString") | ||
| } | ||
| inline fun expect(what: String, where: Int, predicate: (Char) -> Boolean) { |
There was a problem hiding this comment.
Local inline functions are not yet supported.
There was a problem hiding this comment.
When I build the project or open it in the IDE, I receive no such error/warning.
c01263f to
5882b5c
Compare
4c4e638 to
70469f0
Compare
|
This code is in some form already in Kotlin's |
Implement parsing and formatting of ISO strings for instant values separately from the rest of the library.
A stage of fixing #382
This is a draft PR because we probably don't need to actually merge it into the datetime library. However, the code is already written and can be reviewed.