Skip to content

Commit

Permalink
Update timetypes.scala
Browse files Browse the repository at this point in the history
  • Loading branch information
culler committed Jan 6, 2015
1 parent 4cfb864 commit dd39a89
Showing 1 changed file with 12 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
package org.apache.spark.sql.catalyst.expressions

import java.sql.{Date, Timestamp}
import java.text.SimpleDateFormat
import scala.language.implicitConversions

/**
Expand All @@ -43,6 +44,12 @@ class RichDate(milliseconds: Long) extends Date(milliseconds) {
def <= (that: Date): Boolean = (this.before(that) || this.equals(that))
def >= (that: Date): Boolean = (this.after(that) || this.equals(that))
def === (that: Date): Boolean = this.equals(that)
def compare(that: Date): Int = this.getTime.compare(that.getTime)
def format(format: String): String = {
val sdf = new SimpleDateFormat(format)
val d = new Date(this.getTime)
sdf.format(d)
}
}

object RichDate {
Expand Down Expand Up @@ -72,6 +79,11 @@ class RichTimestamp(milliseconds: Long) extends Timestamp(milliseconds) {
def <= (that: Timestamp): Boolean = (this.before(that) || this.equals(that))
def >= (that: Timestamp): Boolean = (this.after(that) || this.equals(that))
def === (that: Timestamp): Boolean = this.equals(that)
def format(format: String): String = {
val sdf = new SimpleDateFormat(format)
val ts = new Timestamp(this.getTime)
sdf.format(ts)
}
}

object RichTimestamp {
Expand Down

0 comments on commit dd39a89

Please sign in to comment.