aboutsummaryrefslogtreecommitdiff
path: root/src/share/classes/java/sql/Date.java
diff options
context:
space:
mode:
authorsherman <none@none>2013-02-12 09:25:43 -0800
committersherman <none@none>2013-02-12 09:25:43 -0800
commit4749a26bbdaa20f573cef277571463f302224374 (patch)
tree5b4db50783da808805f21b5e5baa10483d7e297e /src/share/classes/java/sql/Date.java
parent1a417aae6c1f53edadf188aa16124d84e8f58326 (diff)
downloadjdk8u_jdk-4749a26bbdaa20f573cef277571463f302224374.tar.gz
8007392: JSR 310: DateTime API Updates
8007520: Update date/time classes in j.util and j.sql packages 8007572: Replace existing jdk timezone data at <java.home>/lib/zi with JSR310's tzdb Summary: Integration of JSR310 Date/Time API for M7 Reviewed-by: darcy, alanb, naoto Contributed-by: scolebourne@joda.org, roger.riggs@oracle.com, masayoshi.okutsu@oracle.com, patrick.zhang@oracle.com
Diffstat (limited to 'src/share/classes/java/sql/Date.java')
-rw-r--r--src/share/classes/java/sql/Date.java50
1 files changed, 49 insertions, 1 deletions
diff --git a/src/share/classes/java/sql/Date.java b/src/share/classes/java/sql/Date.java
index 4c0e6e9d23..0133fbe87e 100644
--- a/src/share/classes/java/sql/Date.java
+++ b/src/share/classes/java/sql/Date.java
@@ -25,6 +25,9 @@
package java.sql;
+import java.time.Instant;
+import java.time.LocalDate;
+
/**
* <P>A thin wrapper around a millisecond value that allows
* JDBC to identify this as an SQL <code>DATE</code> value. A
@@ -113,7 +116,6 @@ public class Date extends java.util.Date {
int firstDash;
int secondDash;
Date d = null;
-
if (s == null) {
throw new java.lang.IllegalArgumentException();
}
@@ -255,4 +257,50 @@ public class Date extends java.util.Date {
* compatibility.
*/
static final long serialVersionUID = 1511598038487230103L;
+
+ /**
+ * Obtains an instance of {@code Date} from a {@link LocalDate} object
+ * with the same year, month and day of month value as the given
+ * {@code LocalDate}.
+ * <p>
+ * The provided {@code LocalDate} is interpreted as the local date
+ * in the local time zone.
+ *
+ * @param date a {@code LocalDate} to convert
+ * @return a {@code Date} object
+ * @exception NullPointerException if {@code date} is null
+ * @since 1.8
+ */
+ @SuppressWarnings("deprecation")
+ public static Date valueOf(LocalDate date) {
+ return new Date(date.getYear() - 1900, date.getMonthValue() -1,
+ date.getDayOfMonth());
+ }
+
+ /**
+ * Converts this {@code Date} object to a {@code LocalDate}
+ * <p>
+ * The conversion creates a {@code LocalDate} that represents the same
+ * date value as this {@code Date} in local time zone
+ *
+ * @return a {@code LocalDate} object representing the same date value
+ *
+ * @since 1.8
+ */
+ @SuppressWarnings("deprecation")
+ public LocalDate toLocalDate() {
+ return LocalDate.of(getYear() + 1900, getMonth() + 1, getDate());
+ }
+
+ /**
+ * This method always throws an UnsupportedOperationException and should
+ * not be used because SQL {@code Date} values do not have a time
+ * component.
+ *
+ * @exception java.lang.UnsupportedOperationException if this method is invoked
+ */
+ @Override
+ public Instant toInstant() {
+ throw new java.lang.UnsupportedOperationException();
+ }
}