src/main/scala/net/tz/lift/util/DateExtension.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
 * Refactored from net.liftweb.util.TimeHelpers.scala, which is
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
 * Copyright 2006-2011 WorldWide Conferencing, LLC and
993582ca8d2e Import of tz-lift-misc@14a648a3676f
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
     5
 *
993582ca8d2e Import of tz-lift-misc@14a648a3676f
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
     6
 * 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
     7
 * 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
     8
 * You may obtain a copy of the License at
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
 *     http://www.apache.org/licenses/LICENSE-2.0
993582ca8d2e Import of tz-lift-misc@14a648a3676f
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
    11
 *
993582ca8d2e Import of tz-lift-misc@14a648a3676f
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
    12
 * 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
    13
 * 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
    14
 * 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
    15
 * 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
    16
 * limitations under the License.
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
package net.tz.lift.util
993582ca8d2e Import of tz-lift-misc@14a648a3676f
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
    19
993582ca8d2e Import of tz-lift-misc@14a648a3676f
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
    20
import java.util.{Calendar, Date}
993582ca8d2e Import of tz-lift-misc@14a648a3676f
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
    21
993582ca8d2e Import of tz-lift-misc@14a648a3676f
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
    22
/**
993582ca8d2e Import of tz-lift-misc@14a648a3676f
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
    23
 * Fixed version of DateExtension (from
993582ca8d2e Import of tz-lift-misc@14a648a3676f
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
    24
 * net.liftweb.util.TimeSpan.DateExtension).
993582ca8d2e Import of tz-lift-misc@14a648a3676f
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
    25
 */
993582ca8d2e Import of tz-lift-misc@14a648a3676f
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
    26
class DateExtension(d: Date) {
993582ca8d2e Import of tz-lift-misc@14a648a3676f
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
    27
  /** @returns a Date object starting at 00:00 from date */
993582ca8d2e Import of tz-lift-misc@14a648a3676f
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
    28
  def noTime = {
993582ca8d2e Import of tz-lift-misc@14a648a3676f
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
    29
    val calendar = Calendar.getInstance
993582ca8d2e Import of tz-lift-misc@14a648a3676f
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
    30
    calendar.setTime(d)
993582ca8d2e Import of tz-lift-misc@14a648a3676f
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
    31
    calendar.set(Calendar.HOUR_OF_DAY, 0)
993582ca8d2e Import of tz-lift-misc@14a648a3676f
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
    32
    calendar.set(Calendar.MINUTE, 0)
993582ca8d2e Import of tz-lift-misc@14a648a3676f
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
    33
    calendar.set(Calendar.SECOND, 0)
993582ca8d2e Import of tz-lift-misc@14a648a3676f
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
    34
    calendar.set(Calendar.MILLISECOND, 0)
993582ca8d2e Import of tz-lift-misc@14a648a3676f
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
    35
    calendar.getTime
993582ca8d2e Import of tz-lift-misc@14a648a3676f
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
    36
  }
993582ca8d2e Import of tz-lift-misc@14a648a3676f
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
    37
}
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
object DateExtension {
993582ca8d2e Import of tz-lift-misc@14a648a3676f
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
    40
  implicit def date2dateExtension(d: Date): DateExtension =
993582ca8d2e Import of tz-lift-misc@14a648a3676f
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
    41
    new DateExtension(d)
993582ca8d2e Import of tz-lift-misc@14a648a3676f
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
    42
}
993582ca8d2e Import of tz-lift-misc@14a648a3676f
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
    43
993582ca8d2e Import of tz-lift-misc@14a648a3676f
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
    44
// vim: set ts=2 sw=2 et: