My code is probably so butchered that I need to explain things in English. Basically I’ve created a Date class and I would like it to take a String as a constructor and handle two cases
-
String in format “2011-06-30”
get() returns “2011-06-30 00:00:00.000” -
String in format “2011-06-30 16:32:19.452”
get() splits into rawDate=2011-06-30 and rawTime=16:32:19.452 and then prints
My attempt is below
case class Date(date: String) {
// regex
val DateAndTime = """rawDate rawTme""".r
def get(): String = date match {
case DateTime(rawDate, rawTime) => rawDate + "*" + rawTime
case _ => date + " 00:00:00.000"
}
}
Unfortunately it does not even compile but I’m not sure where I’m going wrong
1 Answer