wt.projmgmt.util
Class CalendarHelper

java.lang.Object
  extended bywt.projmgmt.util.CalendarHelper
All Implemented Interfaces:
Externalizable, Serializable

public class CalendarHelper
extends Object
implements Externalizable

Encapsulates calendar functions.

Supported API: false

Extendable: false

See Also:
Serialized Form

Field Summary
private static CalendarService calService
           
private static String CLASSNAME
           
static long EXTERNALIZATION_VERSION_UID
           
static long MILLIS_IN_DAY
          Number of milliseconds in a day (86400000L).
static long MILLIS_IN_HOUR
           
protected static long OLD_FORMAT_VERSION_UID
           
private static String RESOURCE
           
(package private) static long serialVersionUID
           
(package private) static boolean SERVER
           
private static TimeZone serverTimeZone
           
private static WTPrincipal systemCalendarOwner
           
private static boolean VERBOSE
           
 
Constructor Summary
CalendarHelper()
           
 
Method Summary
static TimeToElapse calculateDuration(ExecutionObject exec_obj, Timestamp start, Timestamp finish)
          Computes and returns the duration (TimeToElapse) given the ExecutionObject, a start and a finish time (Timestamp).
static Timestamp calculateFinish(ExecutionObject exec_obj, Timestamp start, TimeToElapse duration)
          Computes and returns the finish time (Timestamp) given the ExecutionObject, the start time and the duration time (Timestamp).
static TimeToElapse calculateUserDuration(WTPrincipal user, Timestamp start, Timestamp finish)
          Computes and returns the duration (TimeToElapse) given the wt.orgWTUser, a start and a finish time (Timestamp).
static Timestamp calculateUserFinish(WTPrincipal user, Timestamp start, TimeToElapse duration)
          Computes and returns the finish time given the wt.orgWTUser, the start time (Timestamp) and the duration (TimeToElapse).
static Timestamp convertCalendarToTimestamp(Calendar tmpCal)
          Given a java.util.Calendar obj, return a java.sql.Timestamp obj.
private static GregorianCalendar convertTimestampToCalendar(Timestamp time)
          Given a java.sql.Timestamp obj, return a java.util.Calendar obj.
private static CalendarService getCalendarService()
           
static Timestamp getNextWorkingDay(WTPrincipal user, Timestamp aDay)
          Calculates and returns the next working day.
static Timestamp getNextWorkingDay(WTPrincipal user, Timestamp aDay, TimeZone aTZ)
          Calculates and returns the next working day.
static WTPrincipal getPrincipal(ExecutionObject exec_obj)
           
private static TimeZone getServerTZ()
           
static WTPrincipal getSystemCalendarOwner()
          Retrieves, caches and returns the system administrators group.
static boolean isNonWorking(WTPrincipal user, Date date, TimeZone tzone)
          Return whether or not the specified Date is considered a working day for the specified WTPrincipal in the specified TimeZone.
 void readExternal(ObjectInput input)
          Reads the non-transient fields of this class from an external source.
private  boolean readOldVersion(ObjectInput input, long readSerialVersionUID, boolean passThrough, boolean superDone)
          Reads the non-transient fields of this class from an external source, which is not the current version.
protected  boolean readVersion(CalendarHelper thisObject, ObjectInput input, long readSerialVersionUID, boolean passThrough, boolean superDone)
          Reads the non-transient fields of this class from an external source.
private static long resetHours(Timestamp time)
          Convert time to a Calendar object and set it to 00:00 hours on that day.
static Calendar shiftToMethodServerTime(WTPrincipal user, Timestamp time)
          This method takes the specified Timestamp and interprets it as a year, month, day, hour, minute, second, & millisecond in the specified WTUser's preferred timezone.
static Calendar shiftToUserTime(WTPrincipal user, Timestamp time)
          This method takes the specified Timestamp and interprets it as a year, month, day, hour, minute, second, & millisecond in the method server's time zone (usually GMT).
private static String showTime(Timestamp time)
           
 void writeExternal(ObjectOutput output)
          Writes the non-transient fields of this class to an external source.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

RESOURCE

private static final String RESOURCE
See Also:
Constant Field Values

CLASSNAME

private static final String CLASSNAME

MILLIS_IN_DAY

public static final long MILLIS_IN_DAY
Number of milliseconds in a day (86400000L).

Supported API: false


serialVersionUID

static final long serialVersionUID
See Also:
Constant Field Values

EXTERNALIZATION_VERSION_UID

public static final long EXTERNALIZATION_VERSION_UID
See Also:
Constant Field Values

OLD_FORMAT_VERSION_UID

protected static final long OLD_FORMAT_VERSION_UID
See Also:
Constant Field Values

calService

private static CalendarService calService

systemCalendarOwner

private static WTPrincipal systemCalendarOwner

serverTimeZone

private static TimeZone serverTimeZone

VERBOSE

private static final boolean VERBOSE

MILLIS_IN_HOUR

public static final long MILLIS_IN_HOUR
See Also:
Constant Field Values

SERVER

static final boolean SERVER
Constructor Detail

CalendarHelper

public CalendarHelper()
Method Detail

writeExternal

public void writeExternal(ObjectOutput output)
                   throws IOException
Writes the non-transient fields of this class to an external source.

Supported API: false

Specified by:
writeExternal in interface Externalizable
Parameters:
output -
Throws:
IOException

readExternal

public void readExternal(ObjectInput input)
                  throws IOException,
                         ClassNotFoundException
Reads the non-transient fields of this class from an external source.

Supported API: false

Specified by:
readExternal in interface Externalizable
Parameters:
input -
Throws:
IOException
ClassNotFoundException

readVersion

protected boolean readVersion(CalendarHelper thisObject,
                              ObjectInput input,
                              long readSerialVersionUID,
                              boolean passThrough,
                              boolean superDone)
                       throws IOException,
                              ClassNotFoundException
Reads the non-transient fields of this class from an external source.

Supported API: false

Parameters:
thisObject -
input -
readSerialVersionUID -
passThrough -
superDone -
Returns:
boolean
Throws:
IOException
ClassNotFoundException

readOldVersion

private boolean readOldVersion(ObjectInput input,
                               long readSerialVersionUID,
                               boolean passThrough,
                               boolean superDone)
                        throws IOException,
                               ClassNotFoundException
Reads the non-transient fields of this class from an external source, which is not the current version.

Parameters:
input -
readSerialVersionUID -
passThrough -
superDone -
Returns:
boolean
Throws:
IOException
ClassNotFoundException

calculateDuration

public static TimeToElapse calculateDuration(ExecutionObject exec_obj,
                                             Timestamp start,
                                             Timestamp finish)
                                      throws WTException
Computes and returns the duration (TimeToElapse) given the ExecutionObject, a start and a finish time (Timestamp).

Supported API: false

Parameters:
exec_obj -
start -
finish -
Returns:
TimeToElapse
Throws:
WTException

calculateFinish

public static Timestamp calculateFinish(ExecutionObject exec_obj,
                                        Timestamp start,
                                        TimeToElapse duration)
                                 throws WTException
Computes and returns the finish time (Timestamp) given the ExecutionObject, the start time and the duration time (Timestamp).

Supported API: false

Parameters:
exec_obj -
start -
duration -
Returns:
Timestamp
Throws:
WTException

calculateUserDuration

public static TimeToElapse calculateUserDuration(WTPrincipal user,
                                                 Timestamp start,
                                                 Timestamp finish)
                                          throws WTException
Computes and returns the duration (TimeToElapse) given the wt.orgWTUser, a start and a finish time (Timestamp). If the used passed as argument is null, the system administrators group is used.

Supported API: false

Parameters:
user -
start -
finish -
Returns:
TimeToElapse
Throws:
WTException

calculateUserFinish

public static Timestamp calculateUserFinish(WTPrincipal user,
                                            Timestamp start,
                                            TimeToElapse duration)
                                     throws WTException
Computes and returns the finish time given the wt.orgWTUser, the start time (Timestamp) and the duration (TimeToElapse). If the user is null, the system administrators group is used.

Supported API: false

Parameters:
user -
start -
duration -
Returns:
Timestamp
Throws:
WTException

getSystemCalendarOwner

public static WTPrincipal getSystemCalendarOwner()
                                          throws WTException
Retrieves, caches and returns the system administrators group.

Supported API: false

Returns:
WTPrincipal
Throws:
WTException

isNonWorking

public static boolean isNonWorking(WTPrincipal user,
                                   Date date,
                                   TimeZone tzone)
                            throws WTException
Return whether or not the specified Date is considered a working day for the specified WTPrincipal in the specified TimeZone.

If user is null then the system administrators group is used.

Supported API: false

Parameters:
user -
date -
tzone -
Returns:
boolean
Throws:
WTException

getNextWorkingDay

public static Timestamp getNextWorkingDay(WTPrincipal user,
                                          Timestamp aDay)
                                   throws WTException
Calculates and returns the next working day. Throws a WTException if user is null.

Supported API: false

Returns:
Timestamp
Throws:
WTException

getNextWorkingDay

public static Timestamp getNextWorkingDay(WTPrincipal user,
                                          Timestamp aDay,
                                          TimeZone aTZ)
                                   throws WTException
Calculates and returns the next working day. Throws a WTException if user is null.

Supported API: false

Returns:
Timestamp
Throws:
WTException

getPrincipal

public static WTPrincipal getPrincipal(ExecutionObject exec_obj)
                                throws WTException
Throws:
WTException

getCalendarService

private static CalendarService getCalendarService()

resetHours

private static long resetHours(Timestamp time)
Convert time to a Calendar object and set it to 00:00 hours on that day. Then convert it to a long.


convertTimestampToCalendar

private static GregorianCalendar convertTimestampToCalendar(Timestamp time)
Given a java.sql.Timestamp obj, return a java.util.Calendar obj.


convertCalendarToTimestamp

public static Timestamp convertCalendarToTimestamp(Calendar tmpCal)
Given a java.util.Calendar obj, return a java.sql.Timestamp obj.


showTime

private static String showTime(Timestamp time)

shiftToMethodServerTime

public static Calendar shiftToMethodServerTime(WTPrincipal user,
                                               Timestamp time)
                                        throws WTException
This method takes the specified Timestamp and interprets it as a year, month, day, hour, minute, second, & millisecond in the specified WTUser's preferred timezone. It returns a Calendar that represents the same year, month, day, hour, minute, second & millisecond in the method server's time zone (usually GMT).

Please note that the Calendar returned by this method does not represent the same instant in time as the specified Timestamp.

Parameters:
user - the user whose time zone should be shifted from
time - the time to shift
Throws:
WTException

shiftToUserTime

public static Calendar shiftToUserTime(WTPrincipal user,
                                       Timestamp time)
                                throws WTException
This method takes the specified Timestamp and interprets it as a year, month, day, hour, minute, second, & millisecond in the method server's time zone (usually GMT). It returns a Calendar that represents the same year, month, day, hour, minute, second & millisecond in the WTUser's preferred timezone.

Please note that the Calendar returned by this method does not represent the same instant in time as the specified Timestamp.

Parameters:
user - the user whose time zone should be shifted to
time - the time to shift
Throws:
WTException

getServerTZ

private static TimeZone getServerTZ()
                             throws WTException
Throws:
WTException