Skip to content

Commit dd39a89

Browse files
committed
Update timetypes.scala
1 parent 4cfb864 commit dd39a89

File tree

1 file changed

+12
-0
lines changed
  • sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/types

1 file changed

+12
-0
lines changed

sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/types/timetypes.scala

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
package org.apache.spark.sql.catalyst.expressions
1919

2020
import java.sql.{Date, Timestamp}
21+
import java.text.SimpleDateFormat
2122
import scala.language.implicitConversions
2223

2324
/**
@@ -43,6 +44,12 @@ class RichDate(milliseconds: Long) extends Date(milliseconds) {
4344
def <= (that: Date): Boolean = (this.before(that) || this.equals(that))
4445
def >= (that: Date): Boolean = (this.after(that) || this.equals(that))
4546
def === (that: Date): Boolean = this.equals(that)
47+
def compare(that: Date): Int = this.getTime.compare(that.getTime)
48+
def format(format: String): String = {
49+
val sdf = new SimpleDateFormat(format)
50+
val d = new Date(this.getTime)
51+
sdf.format(d)
52+
}
4653
}
4754

4855
object RichDate {
@@ -72,6 +79,11 @@ class RichTimestamp(milliseconds: Long) extends Timestamp(milliseconds) {
7279
def <= (that: Timestamp): Boolean = (this.before(that) || this.equals(that))
7380
def >= (that: Timestamp): Boolean = (this.after(that) || this.equals(that))
7481
def === (that: Timestamp): Boolean = this.equals(that)
82+
def format(format: String): String = {
83+
val sdf = new SimpleDateFormat(format)
84+
val ts = new Timestamp(this.getTime)
85+
sdf.format(ts)
86+
}
7587
}
7688

7789
object RichTimestamp {

0 commit comments

Comments
 (0)