src/main/scala/net/tz/lift/util/YmdDateTimeConverter.scala
author Tomas Zeman <tzeman@volny.cz>
Tue, 23 Apr 2013 10:36:04 +0200
changeset 108 ef4e3e0ef83f
parent 5 993582ca8d2e
permissions -rw-r--r--
84a94fa29a67504b Task/Project notifications
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
5
993582ca8d2e Import of tz-lift-misc@14a648a3676f
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
     1
/*
993582ca8d2e Import of tz-lift-misc@14a648a3676f
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
     2
 * Copyright 2011 Tomas Zeman <tzeman@volny.cz>
993582ca8d2e Import of tz-lift-misc@14a648a3676f
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
     3
 *
993582ca8d2e Import of tz-lift-misc@14a648a3676f
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
     4
 * Licensed under the Apache License, Version 2.0 (the "License");
993582ca8d2e Import of tz-lift-misc@14a648a3676f
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
     5
 * you may not use this file except in compliance with the License.
993582ca8d2e Import of tz-lift-misc@14a648a3676f
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
     6
 * You may obtain a copy of the License at
993582ca8d2e Import of tz-lift-misc@14a648a3676f
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
     7
 *
993582ca8d2e Import of tz-lift-misc@14a648a3676f
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
     8
 *     http://www.apache.org/licenses/LICENSE-2.0
993582ca8d2e Import of tz-lift-misc@14a648a3676f
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
     9
 *
993582ca8d2e Import of tz-lift-misc@14a648a3676f
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
    10
 * Unless required by applicable law or agreed to in writing, software
993582ca8d2e Import of tz-lift-misc@14a648a3676f
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
    11
 * distributed under the License is distributed on an "AS IS" BASIS,
993582ca8d2e Import of tz-lift-misc@14a648a3676f
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
    12
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
993582ca8d2e Import of tz-lift-misc@14a648a3676f
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
    13
 * See the License for the specific language governing permissions and
993582ca8d2e Import of tz-lift-misc@14a648a3676f
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
    14
 * limitations under the License.
993582ca8d2e Import of tz-lift-misc@14a648a3676f
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
    15
 */
993582ca8d2e Import of tz-lift-misc@14a648a3676f
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
    16
package net.tz.lift.util
993582ca8d2e Import of tz-lift-misc@14a648a3676f
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
    17
993582ca8d2e Import of tz-lift-misc@14a648a3676f
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
    18
import java.text.SimpleDateFormat
993582ca8d2e Import of tz-lift-misc@14a648a3676f
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
    19
import java.util.Date
993582ca8d2e Import of tz-lift-misc@14a648a3676f
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
    20
import net.liftweb.common._
993582ca8d2e Import of tz-lift-misc@14a648a3676f
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
    21
import net.liftweb.util.DateTimeConverter
993582ca8d2e Import of tz-lift-misc@14a648a3676f
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
    22
import net.liftweb.util.TimeHelpers._
993582ca8d2e Import of tz-lift-misc@14a648a3676f
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
    23
993582ca8d2e Import of tz-lift-misc@14a648a3676f
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
    24
object YmdDateTimeConverter extends DateTimeConverter {
993582ca8d2e Import of tz-lift-misc@14a648a3676f
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
    25
  val df = new SimpleDateFormat("yyyy-MM-dd")
993582ca8d2e Import of tz-lift-misc@14a648a3676f
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
    26
  val dtf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss")
993582ca8d2e Import of tz-lift-misc@14a648a3676f
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
    27
993582ca8d2e Import of tz-lift-misc@14a648a3676f
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
    28
  def formatDateTime(d: Date) = dtf.format(d)
993582ca8d2e Import of tz-lift-misc@14a648a3676f
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
    29
  def formatDate(d: Date) = df.format(d)
993582ca8d2e Import of tz-lift-misc@14a648a3676f
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
    30
  /**  Uses Helpers.hourFormat which includes seconds but not time zone */
993582ca8d2e Import of tz-lift-misc@14a648a3676f
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
    31
  def formatTime(d: Date) = hourFormat.format(d)
993582ca8d2e Import of tz-lift-misc@14a648a3676f
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
    32
993582ca8d2e Import of tz-lift-misc@14a648a3676f
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
    33
  def parseDateTime(s: String) = tryo { dtf.parse(s) }
993582ca8d2e Import of tz-lift-misc@14a648a3676f
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
    34
  def parseDate(s: String) = tryo { df.parse(s) }
993582ca8d2e Import of tz-lift-misc@14a648a3676f
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
    35
  /** Tries Helpers.hourFormat and Helpers.timeFormat */
993582ca8d2e Import of tz-lift-misc@14a648a3676f
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
    36
  def parseTime(s: String) =
993582ca8d2e Import of tz-lift-misc@14a648a3676f
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
    37
    tryo{hourFormat.parse(s)} or tryo{timeFormatter.parse(s)}
993582ca8d2e Import of tz-lift-misc@14a648a3676f
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
    38
}
993582ca8d2e Import of tz-lift-misc@14a648a3676f
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
    39
993582ca8d2e Import of tz-lift-misc@14a648a3676f
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
    40
// vim: set ts=2 sw=2 et: