-
Notifications
You must be signed in to change notification settings - Fork 128
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Klock: Fixes Z parsing and adds DateTime.parseLocal as a shortcut for…
… parse(str).local (#1640) * Reproduces klock parsing problem * Fixes klock Z parsing * Adds DateFormat.parseLocal * Updates test to use parseLocal
- Loading branch information
Showing
3 changed files
with
71 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package korlibs.time | ||
|
||
import java.time.* | ||
import java.time.format.* | ||
import kotlin.test.* | ||
|
||
class JvmReferenceTest { | ||
fun jvmParse( | ||
pattern: String, | ||
dateString: String | ||
): Long { | ||
val formatter = DateTimeFormatter.ofPattern(pattern) | ||
val dateTime = LocalDateTime.parse(dateString, formatter); | ||
val timestampMillis = dateTime.toInstant(ZoneOffset.UTC).toEpochMilli(); | ||
return timestampMillis | ||
} | ||
|
||
fun klockParse( | ||
pattern: String, | ||
dateString: String | ||
): Long = DateFormat(pattern).parseLocal(dateString).unixMillisLong | ||
|
||
@Test | ||
fun testJvmParse() { | ||
assertEquals( | ||
1676679000000L, | ||
jvmParse("EEE MMM dd HH:mm:ss Z yyyy", "Sat Feb 18 00:10:00 +0000 2023") | ||
) | ||
assertEquals( | ||
1540124184000L, | ||
jvmParse("EEE, dd MMM yyyy HH:mm:ss X", "Sun, 21 Oct 2018 12:16:24 +0300") | ||
) | ||
} | ||
|
||
@Test | ||
fun testKlockParseZ() { | ||
assertEquals( | ||
1676679000000L, | ||
klockParse("EEE MMM dd HH:mm:ss Z yyyy", "Sat Feb 18 00:10:00 +0000 2023") | ||
) | ||
} | ||
|
||
@Test | ||
fun testKlockParseX() { | ||
assertEquals( | ||
1540124184000L, | ||
klockParse("EEE, dd MMM yyyy HH:mm:ss X", "Sun, 21 Oct 2018 12:16:24 +0300") | ||
) | ||
} | ||
} |