Colton Idle
10/16/2023, 5:15 PMreactormonk
10/16/2023, 5:35 PMephemient
10/16/2023, 5:48 PMSystem.currentTimeMillis()
is not monotonic and may not always have a consistent delta to server timeColton Idle
10/16/2023, 7:27 PMephemient
10/16/2023, 7:30 PMTies
10/17/2023, 7:44 AMRob Elliot
10/17/2023, 4:39 PMjava.time.format.DateTimeFormatter
in preference to java.text.SimpleDateFormat
unless you have some very good reason to prefer the latter.class MyClass(
private val clock: Clock = Clock.systemUTC()
) {
...
val now = clock.instant()
...
}
you will save yourself a bunch of refactoring when you need to properly test some time dependent code 😉ephemient
10/17/2023, 4:56 PMColton Idle
10/18/2023, 4:19 PMreactormonk
10/18/2023, 4:19 PMRob Elliot
10/18/2023, 4:22 PMSimpleDateFormat
works on Date
, which is a notoriously badly designed class, whereas DateTimeFormatter
uses Instant
which is immutable and sane
• SimpleDateFormat
is not threadsafe, and anyone who worked for very long on the JVM more than a decade ago will have at some point found someone thinking "may as well make this format a static constant" and only found out when it failed under heavy loadColton Idle
10/18/2023, 8:03 PMKlitos Kyriacou
10/19/2023, 3:07 PM•Yep, that was me, 10 years ago!is not threadsafe, and anyone who worked for very long on the JVM more than a decade ago will have at some point found someone thinking "may as well make this format a static constant" and only found out when it failed under heavy loadSimpleDateFormat
Colton Idle
10/19/2023, 4:57 PMephemient
10/19/2023, 5:03 PMjava.util.*
and java.text.*
along with other many classes you still needandroid.icu.*