Created
March 7, 2017 13:56
-
-
Save mvervuurt/c4c635b732baddb6fbd56eae66d47930 to your computer and use it in GitHub Desktop.
Scala Pattern Matching Exercise with Dates and regular expressions.
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
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