PageRenderTime 16ms CodeModel.GetById 7ms app.highlight 7ms RepoModel.GetById 1ms app.codeStats 0ms

/protocols/jain-megaco/megaco-api/src/main/java/javax/megaco/message/descriptor/TimeStamp.java

http://mobicents.googlecode.com/
Java | 116 lines | 39 code | 18 blank | 59 comment | 0 complexity | 75ccf613be64f0b50f928704dd5c1b83 MD5 | raw file
  1package javax.megaco.message.descriptor;
  2
  3import java.io.Serializable;
  4import java.util.Calendar;
  5import java.util.Date;
  6import java.util.GregorianCalendar;
  7
  8
  9
 10/**
 11 * The TimeStamp object is a class that shall be used to set the time and date
 12 * at which the event was detected within the observed event descriptor. This is
 13 * an independent class derived from java.util.Object and shall not have any
 14 * derived classes.
 15 */
 16public class TimeStamp implements Serializable {
 17
 18	private GregorianCalendar gc = new GregorianCalendar();
 19
 20	/**
 21	 * Constructs a timestamp object that contains the date and time. This shall
 22	 * be used within the observed event to detect the time at which the event
 23	 * was detected. Time stamp should be valid GregorianCallendar date.
 24	 * 
 25	 * @param year
 26	 *            -
 27	 * @param month
 28	 *            - index of month, starting from 0 for January
 29	 * @param day
 30	 *            - day of month
 31	 * @param hour
 32	 *            - 24h format hour
 33	 * @param min
 34	 *            -
 35	 * @param sec
 36	 *            -
 37	 * @throws IllegalArgumentException
 38	 *             - Thrown if an illegal date or time parameter is set.
 39	 */
 40	public TimeStamp(int year, int month, int day, int hour, int min, int sec) throws IllegalArgumentException {
 41		// Lets use trick to validate.
 42
 43		gc.setLenient(false);
 44
 45		gc.set(gc.YEAR, year);
 46		gc.set(gc.MONTH, month);
 47		gc.set(gc.DAY_OF_MONTH, day);
 48		gc.set(gc.HOUR_OF_DAY, hour);
 49		gc.set(gc.MILLISECOND, min);
 50		gc.set(gc.SECOND, sec);
 51
 52		// here we validate
 53		gc.getTime();
 54
 55	}
 56
 57	/**
 58	 * The method is used the to retrieve the year from the absolute date set.
 59	 * 
 60	 * @return year - The integer value of the year.
 61	 */
 62	public int getYear() {
 63		return this.gc.get(gc.YEAR);
 64	}
 65
 66	/**
 67	 * The method can be used the to retrieve month set in the object.
 68	 * 
 69	 * @return month - Integer value of the month.
 70	 */
 71	public int getMonth() {
 72		return this.gc.get(gc.MONTH);
 73	}
 74
 75	/**
 76	 * The method can be used the to retrieve day set in the object.
 77	 * 
 78	 * @return day - Integer value of the day.
 79	 */
 80	public int getDay() {
 81		return this.gc.get(gc.DAY_OF_MONTH);
 82	}
 83
 84	/**
 85	 * The method is used the to retrieve the hour from the absolute time set.
 86	 * 
 87	 * @return hour - The integer value of the hour.
 88	 */
 89	public int getHour() {
 90		return this.gc.get(gc.HOUR_OF_DAY);
 91	}
 92
 93	/**
 94	 * The method is used the to retrieve the minutes from the absolute time
 95	 * set.
 96	 * 
 97	 * @return minutes - The integer value of the minutes.
 98	 */
 99	public int getMinutes() {
100		return this.gc.get(gc.MINUTE);
101	}
102
103	/**
104	 * The method is used the to retrieve the secs from the absolute time set.
105	 * 
106	 * @return secs - The integer value of the secs.
107	 */
108	public int getSecs() {
109		return this.gc.get(gc.SECOND);
110	}
111
112	public java.lang.String toString() {
113		return this.getClass().getSimpleName() + "[" + gc.toString() + "]";
114	}
115
116}