home *** CD-ROM | disk | FTP | other *** search
/ The Net: Ultimate Internet Guide / WWLCD1.ISO / pc / java / unuy2wen / cybcerone / utils / date.java < prev    next >
Encoding:
Java Source  |  1996-08-14  |  1.6 KB  |  69 lines

  1. // Date.java
  2. // 24.03.96
  3. // 
  4. // for demonstration and testing purposes, it helps to be able to
  5. //  use a date other than the actual, current one.  This class allows
  6. //  us to set a new current date
  7.  
  8. package cybcerone.utils;
  9.  
  10. /** 
  11.  * Our own little date class, so that we can set the current date
  12.  * for demonstrations.
  13.  */
  14. public class Date extends java.util.Date {
  15.   private static java.util.Date currentDate = new java.util.Date ();
  16.   private static java.util.Date current = 
  17.     new java.util.Date (currentDate.getYear (),
  18.             currentDate.getMonth (),
  19.             currentDate.getDate ());
  20.  
  21.   private static boolean real = true;
  22.  
  23.   public Date () {
  24.     super (current.getTime ());
  25.     java.util.Date temp = new java.util.Date ();
  26.     setHours (temp.getHours ());
  27.     setMinutes (temp.getMinutes ());
  28.     setSeconds (temp.getSeconds ());
  29.   }
  30.  
  31.   public Date (int year, int month, int date) {
  32.     super (year, month, date);
  33.   }
  34.  
  35.   public Date (int year, int month, int date, int hrs, int min) {
  36.     super (year, month, date, hrs, min);
  37.   }
  38.  
  39.   public Date (int year, int month, int date, int hrs, int min, int sec) {
  40.     super (year, month, date, hrs, min, sec);
  41.   }
  42.  
  43.   public Date (String s) {
  44.     super (s);
  45.   }
  46.   
  47.   /** Set today's date. */
  48.   public static void setCurrent (int year, int month, int day) {
  49.     current = new java.util.Date (year - 1900, month - 1, day);
  50.     real = false;
  51.   }
  52.  
  53.   /** Returns true the current date has been set, otherwise false */
  54.   public static boolean realDate () {
  55.     return real;
  56.   }
  57.  
  58.   /** Redefine midnight to be 24 */
  59.   public int getHours () {
  60.     int hours = super.getHours ();
  61.  
  62.     if (hours == 0)
  63.       return 24;
  64.     else
  65.       return hours;
  66.   }
  67.  
  68. }
  69.