From dd39a8969ce9cbbf219825d1dc0824b594334892 Mon Sep 17 00:00:00 2001 From: Marc Culler Date: Tue, 6 Jan 2015 13:17:35 -0600 Subject: [PATCH] Update timetypes.scala --- .../apache/spark/sql/catalyst/types/timetypes.scala | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/types/timetypes.scala b/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/types/timetypes.scala index 8ec617d226c3e..9c92bd6d50445 100644 --- a/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/types/timetypes.scala +++ b/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/types/timetypes.scala @@ -18,6 +18,7 @@ package org.apache.spark.sql.catalyst.expressions import java.sql.{Date, Timestamp} +import java.text.SimpleDateFormat import scala.language.implicitConversions /** @@ -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 { @@ -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 {