Verified Commit 627b2141 authored by Sebastian Schüpbach's avatar Sebastian Schüpbach
Browse files

accept more kinds of date ranges

parent bab2662c
Pipeline #43386 passed with stages
in 5 minutes and 50 seconds
......@@ -229,12 +229,17 @@ class Manifest {
website
}
private lazy val onlyYear = "^(\\d{4})$".r
private lazy val date = "^(\\d{4}-\\d{2}-\\d{2})$".r
private lazy val yearRange = "^(\\d{4}/\\d{4})$".r
private lazy val dateRange = "^(\\d{4}-\\d{2}-\\d{2}/\\d{4}-\\d{2}-\\d{2})$".r
private lazy val untilYear = "^(\\?/\\d{4})$".r
private lazy val fromYear = "^(\\d{4}/\\?)$".r
private lazy val onlyYear = "^(\\d{4})$".r // e.g. 1931
private lazy val date = "^(\\d{4}-\\d{2}-\\d{2})$".r // e.g. 1931-12-30
private lazy val yearRange = "^(\\d{4}/\\d{4})$".r // e.g. 1931/1964
private lazy val monthRange = "^(\\d{4}-\\d{2}/\\d{4}-\\d{2})$".r // e.g. 1931-12/1964-01
private lazy val dayRange = "^(\\d{4}-\\d{2}-\\d{2}/\\d{4}-\\d{2}-\\d{2})$".r // e.g. 1931-12-30/1964-01-25
private lazy val monthInYearRange = "^(\\d{4}-\\d{2}/\\d{2})$".r // e.g. 1931-01/12
private lazy val dayInMonthRange = "^(\\d{4}-\\d{2}-\\d{2}/\\d{2})$".r // e.g. 1931-12-01/30
private lazy val dayInYearRange = "^(\\d{4}-\\d{2}-\\d{2}/\\d{2}-\\d{2})$".r // e.g. 1931-01-25/12-30
private lazy val untilYear = "^(\\?/\\d{4})$".r // e.g. ?/1964
private lazy val fromYear = "^(\\d{4}/\\?)$".r // e.g. 1931/?
private def parseTimestamp(parseDate: => LocalDate): DateExtractionResult = {
Try(parseDate) match {
......@@ -266,7 +271,22 @@ class Manifest {
)
case der @ _ => der
}
case dateRange(value) =>
case monthRange(value) =>
val dateRangeStart = value.split("/")(0)
val dateRangeEnd = value.split("/")(1)
parseTimestamp(
LocalDate.parse(s"$dateRangeStart-01", dateTimeFormatter)
) match {
case der@DateExtractionResult(Some(_), _, None) =>
der.copy(metadata =
List(
("Date range start", dateRangeStart),
("Date range end", dateRangeEnd)
)
)
case der@_ => der
}
case dayRange(value) =>
val dateRangeStart = value.split("/")(0)
val dateRangeEnd = value.split("/")(1)
parseTimestamp(
......@@ -281,6 +301,51 @@ class Manifest {
)
case der @ _ => der
}
case monthInYearRange(value) =>
val dateRangeStart = value.split("/")(0)
val dateRangeEnd = value.split("/")(1)
parseTimestamp(
LocalDate.parse(s"$dateRangeStart-01", dateTimeFormatter)
) match {
case der@DateExtractionResult(Some(_), _, None) =>
der.copy(metadata =
List(
("Date range start", dateRangeStart),
("Date range end", dateRangeEnd)
)
)
case der@_ => der
}
case dayInMonthRange(value) =>
val dateRangeStart = value.split("/")(0)
val dateRangeEnd = value.split("/")(1)
parseTimestamp(
LocalDate.parse(dateRangeStart, dateTimeFormatter)
) match {
case der@DateExtractionResult(Some(_), _, None) =>
der.copy(metadata =
List(
("Date range start", dateRangeStart),
("Date range end", dateRangeStart.substring(0, 8) + dateRangeEnd)
)
)
case der@_ => der
}
case dayInYearRange(value) =>
val dateRangeStart = value.split("/")(0)
val dateRangeEnd = value.split("/")(1)
parseTimestamp(
LocalDate.parse(dateRangeStart, dateTimeFormatter)
) match {
case der@DateExtractionResult(Some(_), _, None) =>
der.copy(metadata =
List(
("Date range start", dateRangeStart),
("Date range end", dateRangeStart.substring(0, 5) + dateRangeEnd)
)
)
case der@_ => der
}
case fromYear(value) =>
val dateRangeStart = value.split("/")(0)
parseTimestamp(
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment