File tree Expand file tree Collapse file tree 2 files changed +19
-2
lines changed
main/java/com/segment/analytics/kotlin/core/utilities
test/kotlin/com/segment/analytics/kotlin/core/utilities Expand file tree Collapse file tree 2 files changed +19
-2
lines changed Original file line number Diff line number Diff line change @@ -12,8 +12,10 @@ import java.util.*
1212 * dateTimeNowString(): 2023-04-19T04:03:46.880Z
1313 */
1414fun dateTimeNowString (): String {
15- val sdf = SimpleDateFormat (" yyyy-MM-dd'T'HH:mm:ss'.'Szzz" )
15+ // Note, we should specify locale = Locale.ROOT, otherwise the timestamp returned will use
16+ // the default locale, which may not be what we want.
17+ val sdf = SimpleDateFormat (" yyyy-MM-dd'T'HH:mm:ss'.'Szzz" , Locale .ROOT )
1618 val utc = TimeZone .getTimeZone(" UTC" );
1719 sdf.timeZone = utc;
1820 return sdf.format(Date ()).replace(" UTC" , " Z" )
19- }
21+ }
Original file line number Diff line number Diff line change 1+ package com.segment.analytics.kotlin.core.utilities
2+
3+ import org.junit.jupiter.api.Assertions.assertNotNull
4+ import org.junit.jupiter.api.Test
5+ import java.time.format.DateTimeFormatter.ISO_DATE_TIME
6+
7+ class DateTimeUtilsTest {
8+
9+ @Test
10+ fun `dateTimeNowString() produces a string in the correct ISO8601 format` () {
11+ val dateTimeNowString = dateTimeNowString()
12+ val date = ISO_DATE_TIME .parse(dateTimeNowString)
13+ assertNotNull(date)
14+ }
15+ }
You can’t perform that action at this time.
0 commit comments