/protocols/smpp/src/main/java/org/mobicents/protocols/smpp/util/SMPPDate.java

http://mobicents.googlecode.com/ · Java · 248 lines · 55 code · 22 blank · 171 comment · 0 complexity · f868310a6364e6275c4b0e4cb65a2bcb MD5 · raw file

  1. /*
  2. * JBoss, Home of Professional Open Source
  3. * Copyright 2011, Red Hat, Inc. and individual contributors
  4. * by the @authors tag. See the copyright.txt in the distribution for a
  5. * full listing of individual contributors.
  6. *
  7. * This is free software; you can redistribute it and/or modify it
  8. * under the terms of the GNU Lesser General Public License as
  9. * published by the Free Software Foundation; either version 2.1 of
  10. * the License, or (at your option) any later version.
  11. *
  12. * This software is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * Lesser General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Lesser General Public
  18. * License along with this software; if not, write to the Free
  19. * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
  20. * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
  21. */
  22. package org.mobicents.protocols.smpp.util;
  23. import java.util.Calendar;
  24. import java.util.TimeZone;
  25. /**
  26. * Object to represent an SMPP time specification.
  27. * There are two types of SMPP time specs: an absolute time and a relative
  28. * time. Absolute times specify the exact year, month, day, hour, minute,
  29. * second, tenths of a second and timezone. Relative times specify an
  30. * offset of years, months, days, hours, minutes and seconds from the
  31. * current time. Both types of time formats take the same string form
  32. * "YYMMDDhhmmss[tnnp]", where
  33. * <ul>
  34. * <li>YY is the representation of year, 00-99. The specification does not
  35. * define how these numbers are converted into actual years for absolute times.
  36. * By default, this API simply adds 2000 to this number to get the year.
  37. * This can be altered via the {@link SMPPDateFormat} class.</li>
  38. * <li>MM is the month (01-12).</li>
  39. * <li>DD is the day of the month (01-31)</li>
  40. * <li>hh is the hour (00-23)</li>
  41. * <li>mm is the minute (00-59)</li>
  42. * <li>ss is the second (00-59)</li>
  43. * <li>t is tenths of second (0-9)</li>
  44. * <li>nn is the time difference in quarter hours from UTC</li>
  45. * <li>p is one of '+', '-' or 'R'. + indicates the time is ahead of UTC, -
  46. * indicates it is behind UTC and R indicates the time specification is relative
  47. * to current SMSC time.</li>
  48. * </ul>
  49. * <p>
  50. * See section 7.1 of the SMPP v3.4 specification for the official definition
  51. * of SMPP time formats.
  52. * </p>
  53. * @see SMPPDateFormat
  54. * @version $Id: SMPPDate.java 463 2009-06-16 12:07:19Z orank $
  55. */
  56. public abstract class SMPPDate implements java.io.Serializable {
  57. private static final long serialVersionUID = 3L;
  58. protected SMPPDate() {
  59. }
  60. /**
  61. * Get a date object representing an absolute time, as represented by
  62. * the supplied <code>calendar</code>. This is the same as calling
  63. * <code>SMPPDate.getAbsoluteInstance(calendar, true);</code>.
  64. * @param calendar A <code>java.util.Calendar</code> instance representing
  65. * the desired date, time and timezone for the SMPP time.
  66. * @return An SMPPDate object representing the date, time and timezone
  67. * specified by <code>calendar</code>.
  68. */
  69. public static SMPPDate getAbsoluteInstance(Calendar calendar) {
  70. return new AbsoluteSMPPDate(calendar);
  71. }
  72. /**
  73. * Get a date object representing an absolute time, as represented by
  74. * the supplied <code>calendar</code>. The returned object will either
  75. * use or ignore the timezone information in the calendar object,
  76. * depending on whether <code>withTz</code> is <code>true</code> or
  77. * <code>false</code>.
  78. * @param calendar A <code>java.util.Calendar</code> instance representing
  79. * the desired date, time and timezone for the SMPP time.
  80. * @param withTz <code>true</code> to return an object that uses the
  81. * timezone information specified in the calendar object, <code>false</code>
  82. * to return an SMPPDate that does not contain any timezone information.
  83. * @return An SMPPDate object representing the date, time and, optionally,
  84. * timezone specified by <code>calendar</code>.
  85. */
  86. public static SMPPDate getAbsoluteInstance(Calendar calendar, boolean withTz) {
  87. return new AbsoluteSMPPDate(calendar, withTz);
  88. }
  89. /**
  90. * Get a date object representing a relative time.
  91. * @param years The number of years.
  92. * @param months The number of months.
  93. * @param days The number of days.
  94. * @param hours The number of hours.
  95. * @param minutes The number of minutes.
  96. * @param seconds The number of seconds.
  97. * @return An SMPPDate object representing the relative time specified
  98. * by the supplied parameters.
  99. */
  100. public static SMPPDate getRelativeInstance(int years,
  101. int months,
  102. int days,
  103. int hours,
  104. int minutes,
  105. int seconds) {
  106. return new RelativeSMPPDate(years, months, days, hours, minutes, seconds);
  107. }
  108. /**
  109. * Get a calendar object that represents the time specified by this
  110. * SMPPDate. The returned value will be <code>null</code> for relative
  111. * SMPP times. Also, for absolute SMPP times that do not contain timezone
  112. * information, the returned calendar&apos;s timezone cannot be trusted -
  113. * it will simply be initialised to whatever <code>java.util.Calendar</code>
  114. * considers its default (usually the timezone of the JVM).
  115. * @return A calendar object, or <code>null</code> if this is a
  116. * relative time specification.
  117. */
  118. public Calendar getCalendar() {
  119. return null;
  120. }
  121. /**
  122. * Get the year part of this time format. The return value from this will
  123. * be in the range 0 - 99 for relative times, or will be the full year
  124. * (such as <code>2007</code>) for absolute times.
  125. * @return The year part of this time format.
  126. */
  127. public abstract int getYear();
  128. /**
  129. * Get the month part of this time format. This will always return a value
  130. * in the range 1 - 12.
  131. * @return The month part of this time format.
  132. */
  133. public abstract int getMonth();
  134. /**
  135. * Get the day part of this time format. This will always return a value
  136. * in the range 1 - 31.
  137. * @return The day part of this time format.
  138. */
  139. public abstract int getDay();
  140. /**
  141. * Get the hour part of this time format. This will always return a value
  142. * in the range 0 - 23.
  143. * @return The hour part of this time format.
  144. */
  145. public abstract int getHour();
  146. /**
  147. * Get the minute part of this time format. This will always return a value
  148. * in the range 0 - 59.
  149. * @return The minute part of this time format.
  150. */
  151. public abstract int getMinute();
  152. /**
  153. * Get the second part of this time format. This will always return a value
  154. * in the range 0 - 59.
  155. * @return The second part of this time format.
  156. */
  157. public abstract int getSecond();
  158. /**
  159. * Get the tenths of a second part of this time format. This will always
  160. * return a value in the range 0 - 9.
  161. * @return The tenths of a second part of this time format.
  162. */
  163. public int getTenth() {
  164. return 0;
  165. }
  166. /**
  167. * Get the UTC offset part of this time format. This will always return a
  168. * value in the range 0 - 48. The "direction" of the offset should
  169. * be determined using {@link #getSign()}.
  170. * @return The UTC offset part of this time format.
  171. * @see #getTimeZone()
  172. */
  173. public int getUtcOffset() {
  174. return 0;
  175. }
  176. /**
  177. * Get the timezone of this SMPPDate.
  178. * @return The timezone of this SMPPDate object, or <code>null</code> if
  179. * there is no timezone.
  180. */
  181. public TimeZone getTimeZone() {
  182. return null;
  183. }
  184. /**
  185. * Get the timezone offset modifier character. For absolute time formats,
  186. * this will return one of '+' if the timezone offset is ahead of UTC,
  187. * '-' if the timezone offset is behind UTC, or <code>(char) 0</code> if
  188. * there is no timezone information.
  189. * @return One of '+', '-' or <code>(char) 0</code>.
  190. */
  191. public char getSign() {
  192. return (char) 0;
  193. }
  194. /**
  195. * Determine if this date object represents an absolute time.
  196. * @return <code>true</code> if this object is an absolute time,
  197. * <code>false</code> otherwise.
  198. */
  199. public boolean isAbsolute() {
  200. return false;
  201. }
  202. /**
  203. * Determine if this date object represents a relative time.
  204. * @return <code>true</code> if this object is a relative time,
  205. * <code>false</code> otherwise.
  206. */
  207. public boolean isRelative() {
  208. return false;
  209. }
  210. /**
  211. * Determine if this date object has timezone information associated
  212. * with it.
  213. * @return <code>true</code> if this date object "knows" its timezone,
  214. * <code>false</code> if it does not.
  215. */
  216. public boolean hasTimezone() {
  217. return false;
  218. }
  219. /**
  220. * Return the length this SMPP date would encode as.
  221. * @return The number of bytes this SMPP date encodes to on the wire.
  222. */
  223. public int getLength() {
  224. return 0;
  225. }
  226. }