scala/lift/date-time-converter.scala
author Tomas Zeman <tomas@functionals.cz>
Tue, 15 Dec 2020 09:22:21 +0100
changeset 60 4267602e8494
parent 6 b2c3a430fd59
permissions -rw-r--r--
fs2json: directory structure -> json object converter. E.g. to be used instead of erica / py-Couchapp (interaction with couchdb is left to the user).

package example

object YmdDateTimeConverter extends DateTimeConverter {
  val df = new SimpleDateFormat("yyyy-MM-dd")
  val dtf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss")

  def formatDateTime(d: Date) = dtf.format(d)
  def formatDate(d: Date) = df.format(d)
  /**  Uses Helpers.hourFormat which includes seconds but not time zone */
  def formatTime(d: Date) = hourFormat.format(d)

  def parseDateTime(s: String) = tryo { dtf.parse(s) }
  def parseDate(s: String) = tryo { df.parse(s) }
  /** Tries Helpers.hourFormat and Helpers.timeFormat */
  def parseTime(s: String) =
    tryo{hourFormat.parse(s)} or tryo{timeFormatter.parse(s)}
}

// vim: set ts=2 sw=2 et: