src/java.sql/share/classes/java/sql/Date.java
author herrick
Wed, 20 Nov 2019 10:17:37 -0500
branchJDK-8200758-branch
changeset 59160 e90068e7afa1
parent 48065 c4f2b6749c86
permissions -rw-r--r--
JDK-8234402: revert change that stopped providing JPackageToolProvider Reviewed-by: asemenyuk, almatvee, kcr
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
41889
54d1ff9312ce 8169020: Add since element to JDBC deprecated methods
lancea
parents: 32834
diff changeset
     2
 * Copyright (c) 1996, 2016, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package java.sql;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
15658
55b829ca2334 8007392: JSR 310: DateTime API Updates
sherman
parents: 14342
diff changeset
    28
import java.time.Instant;
55b829ca2334 8007392: JSR 310: DateTime API Updates
sherman
parents: 14342
diff changeset
    29
import java.time.LocalDate;
55b829ca2334 8007392: JSR 310: DateTime API Updates
sherman
parents: 14342
diff changeset
    30
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
 * <P>A thin wrapper around a millisecond value that allows
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
 * JDBC to identify this as an SQL <code>DATE</code> value.  A
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 * milliseconds value represents the number of milliseconds that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 * have passed since January 1, 1970 00:00:00.000 GMT.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 * To conform with the definition of SQL <code>DATE</code>, the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 * millisecond values wrapped by a <code>java.sql.Date</code> instance
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 * must be 'normalized' by setting the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 * hours, minutes, seconds, and milliseconds to zero in the particular
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * time zone with which the instance is associated.
44256
12050b22e372 8176721: @since value errors java.sql module
mli
parents: 41889
diff changeset
    42
 *
12050b22e372 8176721: @since value errors java.sql module
mli
parents: 41889
diff changeset
    43
 * @since 1.1
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
public class Date extends java.util.Date {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
     * Constructs a <code>Date</code> object initialized with the given
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
     * year, month, and day.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
     * <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
     * The result is undefined if a given argument is out of bounds.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
     * @param year the year minus 1900; must be 0 to 8099. (Note that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
     *        8099 is 9999 minus 1900.)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
     * @param month 0 to 11
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
     * @param day 1 to 31
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
     * @deprecated instead use the constructor <code>Date(long date)</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
     */
41889
54d1ff9312ce 8169020: Add since element to JDBC deprecated methods
lancea
parents: 32834
diff changeset
    59
    @Deprecated(since="1.2")
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
    public Date(int year, int month, int day) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
        super(year, month, day);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
     * Constructs a <code>Date</code> object using the given milliseconds
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
     * time value.  If the given milliseconds value contains time
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
     * information, the driver will set the time components to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
     * time in the default time zone (the time zone of the Java virtual
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
     * machine running the application) that corresponds to zero GMT.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
     * @param date milliseconds since January 1, 1970, 00:00:00 GMT not
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
     *        to exceed the milliseconds representation for the year 8099.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
     *        A negative number indicates the number of milliseconds
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
     *        before January 1, 1970, 00:00:00 GMT.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
    public Date(long date) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
        // If the millisecond date value contains time info, mask it out.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
        super(date);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
     * Sets an existing <code>Date</code> object
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
     * using the given milliseconds time value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
     * If the given milliseconds value contains time information,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
     * the driver will set the time components to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
     * time in the default time zone (the time zone of the Java virtual
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
     * machine running the application) that corresponds to zero GMT.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
     * @param date milliseconds since January 1, 1970, 00:00:00 GMT not
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
     *        to exceed the milliseconds representation for the year 8099.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
     *        A negative number indicates the number of milliseconds
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
     *        before January 1, 1970, 00:00:00 GMT.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
    public void setTime(long date) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
        // If the millisecond date value contains time info, mask it out.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
        super.setTime(date);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
     * Converts a string in JDBC date escape format to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
     * a <code>Date</code> value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
     * @param s a <code>String</code> object representing a date in
6540
a4ae668f6125 6589685: JDBC 4.1 updates
lancea
parents: 6298
diff changeset
   105
     *        in the format "yyyy-[m]m-[d]d". The leading zero for <code>mm</code>
a4ae668f6125 6589685: JDBC 4.1 updates
lancea
parents: 6298
diff changeset
   106
     * and <code>dd</code> may also be omitted.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
     * @return a <code>java.sql.Date</code> object representing the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
     *         given date
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
     * @throws IllegalArgumentException if the date given is not in the
6540
a4ae668f6125 6589685: JDBC 4.1 updates
lancea
parents: 6298
diff changeset
   110
     *         JDBC date escape format (yyyy-[m]m-[d]d)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
    public static Date valueOf(String s) {
26596
85ea379d419a 8055055: Improve numeric parsing in java.sql
redestad
parents: 25859
diff changeset
   113
        if (s == null) {
85ea379d419a 8055055: Improve numeric parsing in java.sql
redestad
parents: 25859
diff changeset
   114
            throw new java.lang.IllegalArgumentException();
85ea379d419a 8055055: Improve numeric parsing in java.sql
redestad
parents: 25859
diff changeset
   115
        }
6298
470b6c49fe5c 6898593: java.sql.Date.valueOf no exception if date given is not in the JDBC date escape syntax
lancea
parents: 5506
diff changeset
   116
        final int YEAR_LENGTH = 4;
470b6c49fe5c 6898593: java.sql.Date.valueOf no exception if date given is not in the JDBC date escape syntax
lancea
parents: 5506
diff changeset
   117
        final int MONTH_LENGTH = 2;
470b6c49fe5c 6898593: java.sql.Date.valueOf no exception if date given is not in the JDBC date escape syntax
lancea
parents: 5506
diff changeset
   118
        final int DAY_LENGTH = 2;
470b6c49fe5c 6898593: java.sql.Date.valueOf no exception if date given is not in the JDBC date escape syntax
lancea
parents: 5506
diff changeset
   119
        final int MAX_MONTH = 12;
470b6c49fe5c 6898593: java.sql.Date.valueOf no exception if date given is not in the JDBC date escape syntax
lancea
parents: 5506
diff changeset
   120
        final int MAX_DAY = 31;
470b6c49fe5c 6898593: java.sql.Date.valueOf no exception if date given is not in the JDBC date escape syntax
lancea
parents: 5506
diff changeset
   121
        Date d = null;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
26596
85ea379d419a 8055055: Improve numeric parsing in java.sql
redestad
parents: 25859
diff changeset
   123
        int firstDash = s.indexOf('-');
85ea379d419a 8055055: Improve numeric parsing in java.sql
redestad
parents: 25859
diff changeset
   124
        int secondDash = s.indexOf('-', firstDash + 1);
85ea379d419a 8055055: Improve numeric parsing in java.sql
redestad
parents: 25859
diff changeset
   125
        int len = s.length();
6298
470b6c49fe5c 6898593: java.sql.Date.valueOf no exception if date given is not in the JDBC date escape syntax
lancea
parents: 5506
diff changeset
   126
26596
85ea379d419a 8055055: Improve numeric parsing in java.sql
redestad
parents: 25859
diff changeset
   127
        if ((firstDash > 0) && (secondDash > 0) && (secondDash < len - 1)) {
85ea379d419a 8055055: Improve numeric parsing in java.sql
redestad
parents: 25859
diff changeset
   128
            if (firstDash == YEAR_LENGTH &&
85ea379d419a 8055055: Improve numeric parsing in java.sql
redestad
parents: 25859
diff changeset
   129
                    (secondDash - firstDash > 1 && secondDash - firstDash <= MONTH_LENGTH + 1) &&
85ea379d419a 8055055: Improve numeric parsing in java.sql
redestad
parents: 25859
diff changeset
   130
                    (len - secondDash > 1 && len - secondDash <= DAY_LENGTH + 1)) {
85ea379d419a 8055055: Improve numeric parsing in java.sql
redestad
parents: 25859
diff changeset
   131
                int year = Integer.parseInt(s, 0, firstDash, 10);
85ea379d419a 8055055: Improve numeric parsing in java.sql
redestad
parents: 25859
diff changeset
   132
                int month = Integer.parseInt(s, firstDash + 1, secondDash, 10);
85ea379d419a 8055055: Improve numeric parsing in java.sql
redestad
parents: 25859
diff changeset
   133
                int day = Integer.parseInt(s, secondDash + 1, len, 10);
6298
470b6c49fe5c 6898593: java.sql.Date.valueOf no exception if date given is not in the JDBC date escape syntax
lancea
parents: 5506
diff changeset
   134
470b6c49fe5c 6898593: java.sql.Date.valueOf no exception if date given is not in the JDBC date escape syntax
lancea
parents: 5506
diff changeset
   135
                if ((month >= 1 && month <= MAX_MONTH) && (day >= 1 && day <= MAX_DAY)) {
470b6c49fe5c 6898593: java.sql.Date.valueOf no exception if date given is not in the JDBC date escape syntax
lancea
parents: 5506
diff changeset
   136
                    d = new Date(year - 1900, month - 1, day);
470b6c49fe5c 6898593: java.sql.Date.valueOf no exception if date given is not in the JDBC date escape syntax
lancea
parents: 5506
diff changeset
   137
                }
470b6c49fe5c 6898593: java.sql.Date.valueOf no exception if date given is not in the JDBC date escape syntax
lancea
parents: 5506
diff changeset
   138
            }
470b6c49fe5c 6898593: java.sql.Date.valueOf no exception if date given is not in the JDBC date escape syntax
lancea
parents: 5506
diff changeset
   139
        }
470b6c49fe5c 6898593: java.sql.Date.valueOf no exception if date given is not in the JDBC date escape syntax
lancea
parents: 5506
diff changeset
   140
        if (d == null) {
470b6c49fe5c 6898593: java.sql.Date.valueOf no exception if date given is not in the JDBC date escape syntax
lancea
parents: 5506
diff changeset
   141
            throw new java.lang.IllegalArgumentException();
470b6c49fe5c 6898593: java.sql.Date.valueOf no exception if date given is not in the JDBC date escape syntax
lancea
parents: 5506
diff changeset
   142
        }
470b6c49fe5c 6898593: java.sql.Date.valueOf no exception if date given is not in the JDBC date escape syntax
lancea
parents: 5506
diff changeset
   143
470b6c49fe5c 6898593: java.sql.Date.valueOf no exception if date given is not in the JDBC date escape syntax
lancea
parents: 5506
diff changeset
   144
        return d;
470b6c49fe5c 6898593: java.sql.Date.valueOf no exception if date given is not in the JDBC date escape syntax
lancea
parents: 5506
diff changeset
   145
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
6298
470b6c49fe5c 6898593: java.sql.Date.valueOf no exception if date given is not in the JDBC date escape syntax
lancea
parents: 5506
diff changeset
   148
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
     * Formats a date in the date escape format yyyy-mm-dd.
23590
ffd8b0b70511 8038493: Tidy warnings cleanup for java.sql
yan
parents: 23010
diff changeset
   151
     *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
     * @return a String in yyyy-mm-dd format
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
     */
11129
f9ad1aadf3fa 7116445: Miscellaneous warnings in the JDBC/RowSet classes
lancea
parents: 6540
diff changeset
   154
    @SuppressWarnings("deprecation")
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
    public String toString () {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
        int year = super.getYear() + 1900;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
        int month = super.getMonth() + 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
        int day = super.getDate();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
26597
c840e6631327 8058230: Improve java.sql toString formatting
redestad
parents: 26596
diff changeset
   160
        char buf[] = new char[10];
c840e6631327 8058230: Improve java.sql toString formatting
redestad
parents: 26596
diff changeset
   161
        formatDecimalInt(year, buf, 0, 4);
c840e6631327 8058230: Improve java.sql toString formatting
redestad
parents: 26596
diff changeset
   162
        buf[4] = '-';
c840e6631327 8058230: Improve java.sql toString formatting
redestad
parents: 26596
diff changeset
   163
        Date.formatDecimalInt(month, buf, 5, 2);
c840e6631327 8058230: Improve java.sql toString formatting
redestad
parents: 26596
diff changeset
   164
        buf[7] = '-';
c840e6631327 8058230: Improve java.sql toString formatting
redestad
parents: 26596
diff changeset
   165
        Date.formatDecimalInt(day, buf, 8, 2);
c840e6631327 8058230: Improve java.sql toString formatting
redestad
parents: 26596
diff changeset
   166
48065
c4f2b6749c86 8176188: jdk/internal/misc/JavaLangAccess/NewUnsafeString.java failing since 9-b93
redestad
parents: 47216
diff changeset
   167
        return new String(buf);
26597
c840e6631327 8058230: Improve java.sql toString formatting
redestad
parents: 26596
diff changeset
   168
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
26616
7330ab4d8b8e 8058394: Doclint clean up in java.sql.Date
lancea
parents: 26597
diff changeset
   170
    /**
26597
c840e6631327 8058230: Improve java.sql toString formatting
redestad
parents: 26596
diff changeset
   171
     * Formats an unsigned integer into a char array in decimal output format.
c840e6631327 8058230: Improve java.sql toString formatting
redestad
parents: 26596
diff changeset
   172
     * Numbers will be zero-padded or truncated if the string representation
c840e6631327 8058230: Improve java.sql toString formatting
redestad
parents: 26596
diff changeset
   173
     * of the integer is smaller than or exceeds len, respectively.
c840e6631327 8058230: Improve java.sql toString formatting
redestad
parents: 26596
diff changeset
   174
     *
c840e6631327 8058230: Improve java.sql toString formatting
redestad
parents: 26596
diff changeset
   175
     * Should consider moving this to Integer and expose it through
c840e6631327 8058230: Improve java.sql toString formatting
redestad
parents: 26596
diff changeset
   176
     * JavaLangAccess similar to Integer::formatUnsignedInt
26616
7330ab4d8b8e 8058394: Doclint clean up in java.sql.Date
lancea
parents: 26597
diff changeset
   177
     * @param val  Value to convert
7330ab4d8b8e 8058394: Doclint clean up in java.sql.Date
lancea
parents: 26597
diff changeset
   178
     * @param buf  Array containing converted value
7330ab4d8b8e 8058394: Doclint clean up in java.sql.Date
lancea
parents: 26597
diff changeset
   179
     * @param offset Starting pos in buf
7330ab4d8b8e 8058394: Doclint clean up in java.sql.Date
lancea
parents: 26597
diff changeset
   180
     * @param len  length of output value
26597
c840e6631327 8058230: Improve java.sql toString formatting
redestad
parents: 26596
diff changeset
   181
     */
26619
28b1c3535fe7 8058413: Change formatDecimalInt so it is package private
lancea
parents: 26616
diff changeset
   182
    static void formatDecimalInt(int val, char[] buf, int offset, int len) {
26597
c840e6631327 8058230: Improve java.sql toString formatting
redestad
parents: 26596
diff changeset
   183
        int charPos = offset + len;
c840e6631327 8058230: Improve java.sql toString formatting
redestad
parents: 26596
diff changeset
   184
        do {
c840e6631327 8058230: Improve java.sql toString formatting
redestad
parents: 26596
diff changeset
   185
            buf[--charPos] = (char)('0' + (val % 10));
c840e6631327 8058230: Improve java.sql toString formatting
redestad
parents: 26596
diff changeset
   186
            val /= 10;
c840e6631327 8058230: Improve java.sql toString formatting
redestad
parents: 26596
diff changeset
   187
        } while (charPos > offset);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
    // Override all the time operations inherited from java.util.Date;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
   /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
    * This method is deprecated and should not be used because SQL Date
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
    * values do not have a time component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
    *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
    * @deprecated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
    * @exception java.lang.IllegalArgumentException if this method is invoked
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
    * @see #setHours
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
    */
41889
54d1ff9312ce 8169020: Add since element to JDBC deprecated methods
lancea
parents: 32834
diff changeset
   200
    @Deprecated(since="1.2")
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
    public int getHours() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
        throw new java.lang.IllegalArgumentException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
   /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
    * This method is deprecated and should not be used because SQL Date
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
    * values do not have a time component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
    *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
    * @deprecated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
    * @exception java.lang.IllegalArgumentException if this method is invoked
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
    * @see #setMinutes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
    */
41889
54d1ff9312ce 8169020: Add since element to JDBC deprecated methods
lancea
parents: 32834
diff changeset
   213
    @Deprecated(since="1.2")
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
    public int getMinutes() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
        throw new java.lang.IllegalArgumentException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
   /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
    * This method is deprecated and should not be used because SQL Date
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
    * values do not have a time component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
    *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
    * @deprecated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
    * @exception java.lang.IllegalArgumentException if this method is invoked
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
    * @see #setSeconds
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
    */
41889
54d1ff9312ce 8169020: Add since element to JDBC deprecated methods
lancea
parents: 32834
diff changeset
   226
    @Deprecated(since="1.2")
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
    public int getSeconds() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
        throw new java.lang.IllegalArgumentException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
   /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
    * This method is deprecated and should not be used because SQL Date
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
    * values do not have a time component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
    *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
    * @deprecated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
    * @exception java.lang.IllegalArgumentException if this method is invoked
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
    * @see #getHours
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
    */
41889
54d1ff9312ce 8169020: Add since element to JDBC deprecated methods
lancea
parents: 32834
diff changeset
   239
    @Deprecated(since="1.2")
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
    public void setHours(int i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
        throw new java.lang.IllegalArgumentException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
   /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
    * This method is deprecated and should not be used because SQL Date
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
    * values do not have a time component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
    *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
    * @deprecated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
    * @exception java.lang.IllegalArgumentException if this method is invoked
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
    * @see #getMinutes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
    */
41889
54d1ff9312ce 8169020: Add since element to JDBC deprecated methods
lancea
parents: 32834
diff changeset
   252
    @Deprecated(since="1.2")
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
    public void setMinutes(int i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
        throw new java.lang.IllegalArgumentException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
   /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
    * This method is deprecated and should not be used because SQL Date
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
    * values do not have a time component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
    *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
    * @deprecated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
    * @exception java.lang.IllegalArgumentException if this method is invoked
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
    * @see #getSeconds
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
    */
41889
54d1ff9312ce 8169020: Add since element to JDBC deprecated methods
lancea
parents: 32834
diff changeset
   265
    @Deprecated(since="1.2")
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
    public void setSeconds(int i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
        throw new java.lang.IllegalArgumentException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
   /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
    * Private serial version unique ID to ensure serialization
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
    * compatibility.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
    */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
    static final long serialVersionUID = 1511598038487230103L;
15658
55b829ca2334 8007392: JSR 310: DateTime API Updates
sherman
parents: 14342
diff changeset
   275
55b829ca2334 8007392: JSR 310: DateTime API Updates
sherman
parents: 14342
diff changeset
   276
    /**
55b829ca2334 8007392: JSR 310: DateTime API Updates
sherman
parents: 14342
diff changeset
   277
     * Obtains an instance of {@code Date} from a {@link LocalDate} object
55b829ca2334 8007392: JSR 310: DateTime API Updates
sherman
parents: 14342
diff changeset
   278
     * with the same year, month and day of month value as the given
55b829ca2334 8007392: JSR 310: DateTime API Updates
sherman
parents: 14342
diff changeset
   279
     * {@code LocalDate}.
55b829ca2334 8007392: JSR 310: DateTime API Updates
sherman
parents: 14342
diff changeset
   280
     * <p>
55b829ca2334 8007392: JSR 310: DateTime API Updates
sherman
parents: 14342
diff changeset
   281
     * The provided {@code LocalDate} is interpreted as the local date
55b829ca2334 8007392: JSR 310: DateTime API Updates
sherman
parents: 14342
diff changeset
   282
     * in the local time zone.
55b829ca2334 8007392: JSR 310: DateTime API Updates
sherman
parents: 14342
diff changeset
   283
     *
55b829ca2334 8007392: JSR 310: DateTime API Updates
sherman
parents: 14342
diff changeset
   284
     * @param date a {@code LocalDate} to convert
55b829ca2334 8007392: JSR 310: DateTime API Updates
sherman
parents: 14342
diff changeset
   285
     * @return a {@code Date} object
55b829ca2334 8007392: JSR 310: DateTime API Updates
sherman
parents: 14342
diff changeset
   286
     * @exception NullPointerException if {@code date} is null
55b829ca2334 8007392: JSR 310: DateTime API Updates
sherman
parents: 14342
diff changeset
   287
     * @since 1.8
55b829ca2334 8007392: JSR 310: DateTime API Updates
sherman
parents: 14342
diff changeset
   288
     */
55b829ca2334 8007392: JSR 310: DateTime API Updates
sherman
parents: 14342
diff changeset
   289
    @SuppressWarnings("deprecation")
55b829ca2334 8007392: JSR 310: DateTime API Updates
sherman
parents: 14342
diff changeset
   290
    public static Date valueOf(LocalDate date) {
55b829ca2334 8007392: JSR 310: DateTime API Updates
sherman
parents: 14342
diff changeset
   291
        return new Date(date.getYear() - 1900, date.getMonthValue() -1,
55b829ca2334 8007392: JSR 310: DateTime API Updates
sherman
parents: 14342
diff changeset
   292
                        date.getDayOfMonth());
55b829ca2334 8007392: JSR 310: DateTime API Updates
sherman
parents: 14342
diff changeset
   293
    }
55b829ca2334 8007392: JSR 310: DateTime API Updates
sherman
parents: 14342
diff changeset
   294
55b829ca2334 8007392: JSR 310: DateTime API Updates
sherman
parents: 14342
diff changeset
   295
    /**
32277
8671ccb7af7c 8133939: javadoc clarification for java.sql.Date.toLocalDate
lancea
parents: 26619
diff changeset
   296
     * Creates a {@code LocalDate} instance using the year, month and day
8671ccb7af7c 8133939: javadoc clarification for java.sql.Date.toLocalDate
lancea
parents: 26619
diff changeset
   297
     * from this {@code Date} object.
15658
55b829ca2334 8007392: JSR 310: DateTime API Updates
sherman
parents: 14342
diff changeset
   298
     * @return a {@code LocalDate} object representing the same date value
55b829ca2334 8007392: JSR 310: DateTime API Updates
sherman
parents: 14342
diff changeset
   299
     *
55b829ca2334 8007392: JSR 310: DateTime API Updates
sherman
parents: 14342
diff changeset
   300
     * @since 1.8
55b829ca2334 8007392: JSR 310: DateTime API Updates
sherman
parents: 14342
diff changeset
   301
     */
55b829ca2334 8007392: JSR 310: DateTime API Updates
sherman
parents: 14342
diff changeset
   302
    @SuppressWarnings("deprecation")
55b829ca2334 8007392: JSR 310: DateTime API Updates
sherman
parents: 14342
diff changeset
   303
    public LocalDate toLocalDate() {
55b829ca2334 8007392: JSR 310: DateTime API Updates
sherman
parents: 14342
diff changeset
   304
        return LocalDate.of(getYear() + 1900, getMonth() + 1, getDate());
55b829ca2334 8007392: JSR 310: DateTime API Updates
sherman
parents: 14342
diff changeset
   305
    }
55b829ca2334 8007392: JSR 310: DateTime API Updates
sherman
parents: 14342
diff changeset
   306
55b829ca2334 8007392: JSR 310: DateTime API Updates
sherman
parents: 14342
diff changeset
   307
   /**
55b829ca2334 8007392: JSR 310: DateTime API Updates
sherman
parents: 14342
diff changeset
   308
    * This method always throws an UnsupportedOperationException and should
55b829ca2334 8007392: JSR 310: DateTime API Updates
sherman
parents: 14342
diff changeset
   309
    * not be used because SQL {@code Date} values do not have a time
55b829ca2334 8007392: JSR 310: DateTime API Updates
sherman
parents: 14342
diff changeset
   310
    * component.
55b829ca2334 8007392: JSR 310: DateTime API Updates
sherman
parents: 14342
diff changeset
   311
    *
55b829ca2334 8007392: JSR 310: DateTime API Updates
sherman
parents: 14342
diff changeset
   312
    * @exception java.lang.UnsupportedOperationException if this method is invoked
55b829ca2334 8007392: JSR 310: DateTime API Updates
sherman
parents: 14342
diff changeset
   313
    */
55b829ca2334 8007392: JSR 310: DateTime API Updates
sherman
parents: 14342
diff changeset
   314
    @Override
55b829ca2334 8007392: JSR 310: DateTime API Updates
sherman
parents: 14342
diff changeset
   315
    public Instant toInstant() {
55b829ca2334 8007392: JSR 310: DateTime API Updates
sherman
parents: 14342
diff changeset
   316
        throw new java.lang.UnsupportedOperationException();
55b829ca2334 8007392: JSR 310: DateTime API Updates
sherman
parents: 14342
diff changeset
   317
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
}