Source for de.webdings.tools.time.EasyDate

   1: /* EasyDate.java - Copyright (c) 2005 by Stefan Thesing
   2:  <p>This file is part of Webdings Tools.</p>
   3:  <p>Webdings Tools is free software; you can redistribute it and/or modify
   4:  it under the terms of the GNU General Public License as published by
   5:  the Free Software Foundation; either version 2 of the License, or
   6:  (at your option) any later version.</p>
   7: <p>Webdings Tools is distributed in the hope that it will be useful,
   8: but WITHOUT ANY WARRANTY; without even the implied warranty of
   9: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  10: GNU General Public License for more details.</p>
  11: <p>You should have received a copy of the GNU General Public License
  12: along with Webdings Tools; if not, write to the<br>
  13: Free Software Foundation, Inc.,<br>
  14: 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA<br>
  15: */
  16: package de.webdings.tools.time;
  17: 
  18: import java.util.Calendar;
  19: import java.util.GregorianCalendar;
  20: 
  21: 
  22: /**
  23:  * EasyDate is a wrapper for {@link java.util.Calendar}
  24:  * and its subclasses to provide easy date-representing
  25:  * functionality.
  26:  * By default it wraps a {@link java.util.GregorianCalendar}
  27:  * 
  28:  * @author Stefan Thesing<br>
  29:  * Website: <a href="http://www.webdings.de">http://www.webdings.de</a>
  30:  * @version 1.0 23.05.2005
  31:  * @see java.util.Calendar
  32:  * @see java.util.GregorianCalendar
  33:  * @see EasyDateCreateException
  34:  */
  35: public class EasyDate {
  36:     //  Attributes
  37:     /**
  38:      * <code>cal</code> ist the wrapped calendar
  39:      */
  40:     private Calendar cal;
  41:     //Constructors
  42:     /**
  43:      * constructs an EasyDate object wrapping the
  44:      * specified calendar.
  45:      * @param cal The calendar to be wrapped. The
  46:      * constructor accepts any subclass of {@link java.util.Calendar}
  47:      */
  48:     public EasyDate(Calendar cal) {
  49:         this.cal = cal;
  50:     }
  51:     /**
  52:      * constructs an EasyDate object wrapping a
  53:      * {@link java.util.GregorianCalendar} initialized at the moment
  54:      * of this constructor's call. Essentially, an object
  55:      * constructed by this constructor represents today.
  56:      */
  57:     public EasyDate() {
  58:          this(new GregorianCalendar());    
  59:     }
  60:     /**
  61:      * constructs an EasyDate object wrapping a 
  62:      * {@link java.util.GregorianCalendar} of the
  63:      * specified year, month and day.
  64:      * <p>IMPORTANT: note that unlike in {@link 
  65:      * java.util.GregorianCalendar}'s constructors 
  66:      * January is represented by 1 and not by 0!
  67:      * So the months are represented according to the
  68:      * following table:<br>
  69:      *  <table border=1>
  70:      *         <tr><th align=center>int #</th><th>represented month</th></tr>
  71:      *      <tr><td align=right>1</td><td>January</td></tr>
  72:      *         <tr><td align=right>2</td><td>February</td></tr>
  73:      *         <tr><td align=right>3</td><td>March</td></tr>
  74:      *         <tr><td align=right>4</td><td>April</td></tr>
  75:      *         <tr><td align=right>5</td><td>May</td></tr>
  76:      *         <tr><td align=right>6</td><td>June</td></tr>
  77:      *         <tr><td align=right>7</td><td>July</td></tr>
  78:      *         <tr><td align=right>8</td><td>August</td></tr>
  79:      *         <tr><td align=right>9</td><td>September</td></tr>
  80:      *         <tr><td align=right>10</td><td>October</td></tr>
  81:      *         <tr><td align=right>11</td><td>November</td></tr>
  82:      *         <tr><td align=right>12</td><td>December</td></tr>
  83:      *  
  84:      * @param year the year
  85:      * @param month the month 
  86:      * @param day the day
  87:      * @throws EasyDateCreateException when an invalid month value
  88:      * is specified
  89:      */
  90:     public EasyDate(int year, int month, int day) throws EasyDateCreateException {
  91:         if(month<1 || month >12) {
  92:             throw new EasyDateCreateException(month);
  93:         } else {
  94:             this.cal = new GregorianCalendar(year, month-1, day);
  95:         }    
  96:     }
  97:     //Methods
  98:     /**
  99:      * @return the {@link 
 100:      * java.util.Calendar#YEAR} field of the
 101:      * wrapped calendar
 102:      */
 103:     public int getYear() {
 104:         return cal.get(Calendar.YEAR);
 105:     }
 106:     /**
 107:      * @return the {@link 
 108:      * java.util.Calendar#MONTH} field of the
 109:      * wrapped calendar
 110:      */
 111:     public int getMonth() {
 112:         return cal.get(Calendar.MONTH);
 113:     }
 114:     /**
 115:      * @return the {@link 
 116:      * java.util.Calendar#DAY_OF_MONTH} field of the
 117:      * wrapped calendar
 118:      */
 119:     public int getDay() {
 120:         return cal.get(Calendar.DAY_OF_MONTH);
 121:     }
 122:     /**
 123:      * @return the wrapped calendar.
 124:      */
 125:     public Calendar getCal() {
 126:         return cal;
 127:     }
 128:     /**
 129:      * @param cal The calender to be wrapped.
 130:      */
 131:     public void setCal(Calendar cal) {
 132:         this.cal = cal;
 133:     }
 134: }

© 2005 by Stefan Thesing;
Verbatim copying and redistribution of this entire page are permitted provided this notice is preserved.