org.mobicents.protocols.smpp.util
Class SMPPDate

java.lang.Object
  extended by org.mobicents.protocols.smpp.util.SMPPDate
All Implemented Interfaces:
Serializable

public abstract class SMPPDate
extends Object
implements Serializable

Object to represent an SMPP time specification. There are two types of SMPP time specs: an absolute time and a relative time. Absolute times specify the exact year, month, day, hour, minute, second, tenths of a second and timezone. Relative times specify an offset of years, months, days, hours, minutes and seconds from the current time. Both types of time formats take the same string form "YYMMDDhhmmss[tnnp]", where

See section 7.1 of the SMPP v3.4 specification for the official definition of SMPP time formats.

Version:
$Id: SMPPDate.java 463 2009-06-16 12:07:19Z orank $
See Also:
SMPPDateFormat, Serialized Form

Constructor Summary
protected SMPPDate()
           
 
Method Summary
static SMPPDate getAbsoluteInstance(Calendar calendar)
          Get a date object representing an absolute time, as represented by the supplied calendar.
static SMPPDate getAbsoluteInstance(Calendar calendar, boolean withTz)
          Get a date object representing an absolute time, as represented by the supplied calendar.
 Calendar getCalendar()
          Get a calendar object that represents the time specified by this SMPPDate.
abstract  int getDay()
          Get the day part of this time format.
abstract  int getHour()
          Get the hour part of this time format.
 int getLength()
          Return the length this SMPP date would encode as.
abstract  int getMinute()
          Get the minute part of this time format.
abstract  int getMonth()
          Get the month part of this time format.
static SMPPDate getRelativeInstance(int years, int months, int days, int hours, int minutes, int seconds)
          Get a date object representing a relative time.
abstract  int getSecond()
          Get the second part of this time format.
 char getSign()
          Get the timezone offset modifier character.
 int getTenth()
          Get the tenths of a second part of this time format.
 TimeZone getTimeZone()
          Get the timezone of this SMPPDate.
 int getUtcOffset()
          Get the UTC offset part of this time format.
abstract  int getYear()
          Get the year part of this time format.
 boolean hasTimezone()
          Determine if this date object has timezone information associated with it.
 boolean isAbsolute()
          Determine if this date object represents an absolute time.
 boolean isRelative()
          Determine if this date object represents a relative time.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SMPPDate

protected SMPPDate()
Method Detail

getAbsoluteInstance

public static SMPPDate getAbsoluteInstance(Calendar calendar)
Get a date object representing an absolute time, as represented by the supplied calendar. This is the same as calling SMPPDate.getAbsoluteInstance(calendar, true);.

Parameters:
calendar - A java.util.Calendar instance representing the desired date, time and timezone for the SMPP time.
Returns:
An SMPPDate object representing the date, time and timezone specified by calendar.

getAbsoluteInstance

public static SMPPDate getAbsoluteInstance(Calendar calendar,
                                           boolean withTz)
Get a date object representing an absolute time, as represented by the supplied calendar. The returned object will either use or ignore the timezone information in the calendar object, depending on whether withTz is true or false.

Parameters:
calendar - A java.util.Calendar instance representing the desired date, time and timezone for the SMPP time.
withTz - true to return an object that uses the timezone information specified in the calendar object, false to return an SMPPDate that does not contain any timezone information.
Returns:
An SMPPDate object representing the date, time and, optionally, timezone specified by calendar.

getRelativeInstance

public static SMPPDate getRelativeInstance(int years,
                                           int months,
                                           int days,
                                           int hours,
                                           int minutes,
                                           int seconds)
Get a date object representing a relative time.

Parameters:
years - The number of years.
months - The number of months.
days - The number of days.
hours - The number of hours.
minutes - The number of minutes.
seconds - The number of seconds.
Returns:
An SMPPDate object representing the relative time specified by the supplied parameters.

getCalendar

public Calendar getCalendar()
Get a calendar object that represents the time specified by this SMPPDate. The returned value will be null for relative SMPP times. Also, for absolute SMPP times that do not contain timezone information, the returned calendar's timezone cannot be trusted - it will simply be initialised to whatever java.util.Calendar considers its default (usually the timezone of the JVM).

Returns:
A calendar object, or null if this is a relative time specification.

getYear

public abstract int getYear()
Get the year part of this time format. The return value from this will be in the range 0 - 99 for relative times, or will be the full year (such as 2007) for absolute times.

Returns:
The year part of this time format.

getMonth

public abstract int getMonth()
Get the month part of this time format. This will always return a value in the range 1 - 12.

Returns:
The month part of this time format.

getDay

public abstract int getDay()
Get the day part of this time format. This will always return a value in the range 1 - 31.

Returns:
The day part of this time format.

getHour

public abstract int getHour()
Get the hour part of this time format. This will always return a value in the range 0 - 23.

Returns:
The hour part of this time format.

getMinute

public abstract int getMinute()
Get the minute part of this time format. This will always return a value in the range 0 - 59.

Returns:
The minute part of this time format.

getSecond

public abstract int getSecond()
Get the second part of this time format. This will always return a value in the range 0 - 59.

Returns:
The second part of this time format.

getTenth

public int getTenth()
Get the tenths of a second part of this time format. This will always return a value in the range 0 - 9.

Returns:
The tenths of a second part of this time format.

getUtcOffset

public int getUtcOffset()
Get the UTC offset part of this time format. This will always return a value in the range 0 - 48. The "direction" of the offset should be determined using getSign().

Returns:
The UTC offset part of this time format.
See Also:
getTimeZone()

getTimeZone

public TimeZone getTimeZone()
Get the timezone of this SMPPDate.

Returns:
The timezone of this SMPPDate object, or null if there is no timezone.

getSign

public char getSign()
Get the timezone offset modifier character. For absolute time formats, this will return one of '+' if the timezone offset is ahead of UTC, '-' if the timezone offset is behind UTC, or (char) 0 if there is no timezone information.

Returns:
One of '+', '-' or (char) 0.

isAbsolute

public boolean isAbsolute()
Determine if this date object represents an absolute time.

Returns:
true if this object is an absolute time, false otherwise.

isRelative

public boolean isRelative()
Determine if this date object represents a relative time.

Returns:
true if this object is a relative time, false otherwise.

hasTimezone

public boolean hasTimezone()
Determine if this date object has timezone information associated with it.

Returns:
true if this date object "knows" its timezone, false if it does not.

getLength

public int getLength()
Return the length this SMPP date would encode as.

Returns:
The number of bytes this SMPP date encodes to on the wire.


Copyright © 2011 Mobicents. All Rights Reserved.