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.*
12
12
* dateTimeNowString(): 2023-04-19T04:03:46.880Z
13
13
*/
14
14
fun 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 )
16
18
val utc = TimeZone .getTimeZone(" UTC" );
17
19
sdf.timeZone = utc;
18
20
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