/[classpath]/classpath/java/sql/Time.java
ViewVC logotype

Diff of /classpath/java/sql/Time.java

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.5 by mark, Tue Jan 22 22:27:01 2002 UTC revision 1.6 by bryce, Fri Jun 21 05:34:12 2002 UTC
# Line 1  Line 1 
1  /* Time.java -- Wrapper around java.util.Date  /* Time.java -- Wrapper around java.util.Date
2     Copyright (C) 1999, 2000 Free Software Foundation, Inc.     Copyright (C) 1999, 2000, 2002 Free Software Foundation, Inc.
3    
4  This file is part of GNU Classpath.  This file is part of GNU Classpath.
5    
# Line 41  package java.sql; Line 41  package java.sql;
41  import java.text.SimpleDateFormat;  import java.text.SimpleDateFormat;
42    
43  /**  /**
44    * This class is a wrapper around java.util.Date to allow the JDBC   * This class is a wrapper around java.util.Date to allow the JDBC
45    * driver to identify the value as a SQL Time.   * driver to identify the value as a SQL Time.
46    *   *
47    * @author Aaron M. Renn (arenn@urbanophile.com)   * @author Aaron M. Renn (arenn@urbanophile.com)
   */  
 public class Time extends java.util.Date  
 {  
   
 /*  
  * Class Variables  
  */  
   
 /**  
   * Used for parsing and formatting this date.  
   */  
 private static SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss");  
   
 /**  
   * This is the serialization UID for this class.  
   */  
 private static final long serialVersionUID = 8397324403548013681L;  
   
 /*************************************************************************/  
   
 /*  
  * Class Methods  
  */  
   
 /**  
   * This method returns a new instance of this class by parsing a  
   * date in JDBC format into a Java date.  
   *  
   * @param str The string to parse.  
   *  
   * @return The resulting <code>java.sql.Time</code> value.  
   */  
 public static Time  
 valueOf(String str)  
 {  
   try  
     {  
       java.util.Date d = (java.util.Date)sdf.parseObject(str);  
       return(new Time(d.getTime()));  
     }  
   catch(Exception e)  
     {  
       return(null);  
     }  
 }  
   
 /*************************************************************************/  
   
 /*  
  * Constructors  
48   */   */
49    public class Time extends java.util.Date
 /**  
   * This method initializes a new instance of this class with the  
   * specified year, month, and day.  
   *  
   * @param hour The hour for this Time (0-23)  
   * @param minute The minute for this time (0-59)  
   * @param second The second for this time (0-59)  
   *  
   * @deprecated  
   */  
 public  
 Time(int hour, int minute, int second)  
 {  
   super(System.currentTimeMillis());  
   
   setHours(hour);  
   setMinutes(minute);  
   setSeconds(second);  
 }  
   
 /*************************************************************************/  
   
 /**  
   * This method initializes a new instance of this class with the  
   * specified time value representing the number of seconds since  
   * Jan 1, 1970 at 12:00 midnight GMT.  
   *  
   * @param time The time value to intialize this <code>Time</code> to.  
   */  
 public  
 Time(long date)  
50  {  {
51    super(date);    static final long serialVersionUID = 8397324403548013681L;
 }  
   
 /*************************************************************************/  
52    
53  /*    /**
54   * Instance Methods     * Used for parsing and formatting this date.
55   */     */
56      private static SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss");
57    
58    
59      /**
60       * This method returns a new instance of this class by parsing a
61       * date in JDBC format into a Java date.
62       *
63       * @param str The string to parse.
64       * @return The resulting <code>java.sql.Time</code> value.
65       */
66      public static Time valueOf(String str)
67      {
68        try
69          {
70            java.util.Date d = (java.util.Date) sdf.parseObject(str);
71            return new Time(d.getTime());
72          }
73        catch (Exception e)
74          {
75            return null;
76          }
77      }
78    
79      /**
80        * This method initializes a new instance of this class with the
81        * specified year, month, and day.
82        *
83        * @param hour The hour for this Time (0-23)
84        * @param minute The minute for this time (0-59)
85        * @param second The second for this time (0-59)
86        * @deprecated
87        */
88      public Time(int hour, int minute, int second)
89      {
90        super(System.currentTimeMillis());
91    
92        setHours(hour);
93        setMinutes(minute);
94        setSeconds(second);
95      }
96    
97      /**
98       * This method initializes a new instance of this class with the
99       * specified time value representing the number of seconds since
100       * Jan 1, 1970 at 12:00 midnight GMT.
101       *
102       * @param time The time value to intialize this <code>Time</code> to.
103       */
104      public Time(long date)
105      {
106        super(date);
107      }
108    
109      /**
110       * This method returns this date in JDBC format.
111       *
112       * @return This date as a string.
113       */
114      public String
115      toString()
116      {
117        return sdf.format(this);
118      }
119    
 /**  
   * This method returns this date in JDBC format.  
   *  
   * @return This date as a string.  
   */  
 public String  
 toString()  
 {  
   return(sdf.format(this));  
120  }  }
121    
 } // class Time  
   

Legend:
Removed from v.1.5  
changed lines
  Added in v.1.6

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26