title: Scala refactor string to Date code
body: <p>I have an API that accepts a date as a string as a query parameter. For the most part, I expect my users to send an optional date parameter in the format of "yyyyMMdd" so an example would be <code>2013/10/12</code> for October 12th, 2013. I then search for records in a MongoDB and/or cache for certain data that matches said date. The code I have that turns the string into something that's sane in Scala is the following:</p>
  
  <pre><code>def parseDate(date: String): org.joda.time.DateTime = {
      val formatter = DateTimeFormat.forPattern("yyyyMMdd")  
      formatter.parseDateTime(date)
  }
  </code></pre>
  
  <p>This works great. Now the issue I have is when the user does not submit a date, I want to default to today's date. This is where I need help. I don't have a great way of turning it into a string to pass to this method. I have code that looks like the following:</p>
  
  <pre><code>val gdate = params.getOrElse("gamedate", "0")
  val date = gdate match {
     case gd:String =&gt; MyDateTimeHelper.parseDate(gd)
  }
  </code></pre>
  
  <p>This is obviously wrong. I thought I could maybe do:</p>
  
  <pre><code>val gdate = params.getOrElse("gamedate", new DateTime)
  </code></pre>
  
  <p>But that also is not a solution (I was assuming it would just bypass the match since it's already a Date instance and not a string. </p>
  
  <p>What's a decent way to solve this problem in Scala? I'm just jodatime for Scala to help me with all Date / Time type problems. </p>