comparison src/main/kotlin/name/blackcap/passman/Time.kt @ 6:711cc42e96d7

Got the list subcommand working, but needs efficiency improvements.
author David Barts <n5jrn@me.com>
date Tue, 20 Sep 2022 20:52:21 -0700
parents a6cfdffcaa94
children
comparison
equal deleted inserted replaced
5:ad997df1f560 6:711cc42e96d7
1 package name.blackcap.passman 1 package name.blackcap.passman
2 2
3 import java.text.ParseException
3 import java.text.SimpleDateFormat 4 import java.text.SimpleDateFormat
4 5
5 val ISO8601 = SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ") 6 val ISO8601 = SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ")
7 private val PARSERS = arrayOf<SimpleDateFormat>(
8 SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss").apply { isLenient = false },
9 SimpleDateFormat("yyyy-MM-dd'T'HH:mm").apply { isLenient = false },
10 SimpleDateFormat("yyyy-MM-dd").apply { isLenient = false },
11 )
12
13 fun parseDateTime(unparsed: String): Long? {
14 for (parser in PARSERS) {
15 val ret = try {
16 parser.parse(unparsed)
17 } catch (e: ParseException) {
18 null
19 }
20 if (ret != null) {
21 return ret.time
22 }
23 }
24 return null
25 }