EDTF4K is a Kotlin library for parsing EDTF (Extended Date/Time Format) strings.
org.edtf4k.EdtfDateFactory is the entry-point to parsing an EDTF string. The return will be one of an org.edtf4k.EdtfDateType type depending on the string.
There are three EdtfDateType's
org.edtf4k.EdtfDateholds a single dateorg.edtf4k.EdtfDatePairholds a pair oforg.edtf4k.EdtfDates for ranges and intervalsorg.edtf4k.EdtfDateSetholds a list of EdtfDateTypes
Each org.edtf4k.EdtfDate has a status to determine if it is NORMAL, OPEN, UNUSED, UNKNOWN, or INVALID.
This implementation supports all EDTF Levels (0, 1, and 2)
for (dateString in arrayOf("2006", "2008..2009", "{2006,2008..2009}")) {
when (val dateType = EdtfDateFactory.parse(dateString)) {
is EdtfDate -> println("Single - $dateType")
is EdtfDatePair -> println("Pair - $dateType")
is EdtfDateSet -> println("Set - ${dateType.joinToString()}")
}
}will output
Single - 2006
Pair - 2008..2009
Set - {2006,2008..2009}
The Extended Date/Time Format (EDTF) was created by the Library of Congress with the participation and support of the bibliographic community as well as communities with related interests. It defines features to be supported in a date/time string, features considered useful for a wide variety of applications.