Skip to content

Instantly share code, notes, and snippets.

@mvervuurt
Created March 7, 2017 13:56
Show Gist options
  • Save mvervuurt/c4c635b732baddb6fbd56eae66d47930 to your computer and use it in GitHub Desktop.
Save mvervuurt/c4c635b732baddb6fbd56eae66d47930 to your computer and use it in GitHub Desktop.
Scala Pattern Matching Exercise with Dates and regular expressions.
import java.time.LocalDate
val digitDate = """(\d\d)-(\d\d)""".r
val letterDate = """(\d\d)-([a-zA-Z]{3})""".r
def toStrHiveDateFrmt(str: String): String = str match {
case "" => "0001-01-01"
case digitDate(day, month) => {
val currentYear = LocalDate.now().getYear
val tmpDate = LocalDate.of(currentYear, Integer.valueOf(month), Integer.valueOf(day));
tmpDate.toString
}
case letterDate(day, month) => {
//TODO Implement
"letter"
}
case _ => {
//TODO Throw Exception
"oops"
}
}
toStrHiveDateFrmt("01-12")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment