File tree Expand file tree Collapse file tree 1 file changed +12
-0
lines changed
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/types Expand file tree Collapse file tree 1 file changed +12
-0
lines changed Original file line number Diff line number Diff line change 1818package org .apache .spark .sql .catalyst .expressions
1919
2020import java .sql .{Date , Timestamp }
21+ import java .text .SimpleDateFormat
2122import 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
4855object 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
7789object RichTimestamp {
You can’t perform that action at this time.
0 commit comments