org.sakaiproject.component.legacy.time
Class BasicTimeService

java.lang.Object
  extended byorg.sakaiproject.component.legacy.time.BasicTimeService
All Implemented Interfaces:
TimeService

public class BasicTimeService
extends Object
implements TimeService

BasicTimeService implements the Sakai TimeService

Version:
$Revision: 6400 $
Author:
University of Michigan, Sakai Software Development Team

Nested Class Summary
protected  class BasicTimeService.LocalTzFormat
          LocalTzFormat -- maintains a local timezone and SimpleDateFormats
 class BasicTimeService.MyTimeBreakdown
          TimeBreakdown implementation
 class BasicTimeService.MyTimeRange
          TimeRange implementation
 
Field Summary
protected  SimpleDateFormat M_fmtA
          The formatter for our special GMT format(s)
protected  SimpleDateFormat M_fmtB
           
protected  SimpleDateFormat M_fmtC
           
protected  SimpleDateFormat M_fmtD
           
protected  SimpleDateFormat M_fmtE
           
protected  SimpleDateFormat M_fmtG
           
protected  GregorianCalendar M_GCal
          a calendar to clone for GMT time construction
protected  Logger m_logger
          Dependency: logging service
protected  TimeZone M_tz
          The time zone for our GMT times.
protected  String M_tz_local_default
           
 
Fields inherited from interface org.sakaiproject.service.legacy.time.TimeService
SERVICE_NAME, TIMEZONE_KEY
 
Constructor Summary
BasicTimeService()
          no arg constructor
 
Method Summary
 boolean clearLocalTimeZone(String userId)
          Clear local time zone for specified user
 void destroy()
          Final cleanup.
 boolean different(Time a, Time b)
          Compare two Time for differences, either may be null
 GregorianCalendar getCalendar(TimeZone zone, int year, int month, int day, int hour, int min, int sec, int ms)
          Get a Calendar, set to this zone and these values.
 TimeZone getLocalTimeZone()
          Access the local TimeZone.
protected  BasicTimeService.LocalTzFormat getLocalTzFormat(String timeZoneId)
           
protected  String getUserLocalTzId()
           
 void init()
          Final initialization, once all dependencies are set.
 Time newTime()
          Get a time object.
 Time newTime(GregorianCalendar cal)
          Get a time object, based on the time set in the calendar
 Time newTime(long value)
          Get a time object, set from this long milliseconds since the "epoc" value.
 TimeBreakdown newTimeBreakdown(int year, int month, int day, int hour, int minute, int second, int millisecond)
          Get a TimeBreakdown object, set from individual ints.
 Time newTimeGmt(int year, int month, int day, int hour, int minute, int second, int millisecond)
          Get a time object, set from individual ints, Gmt values
 Time newTimeGmt(String value)
          Get a time object, set from this string in our format, Gmt values
 Time newTimeGmt(TimeBreakdown breakdown)
          Get a time object, set from this breakdown (Gmt values).
 Time newTimeLocal(int year, int month, int day, int hour, int minute, int second, int millisecond)
          Get a time object, set from individual ints, Local values
 Time newTimeLocal(TimeBreakdown breakdown)
          Get a time object, set from this breakdown (Local values).
 TimeRange newTimeRange(long start, long duration)
          Get a TimeRange, from a time value long start and duration
 TimeRange newTimeRange(String value)
          Get a TimeRange, from our string format.
 TimeRange newTimeRange(Time startAndEnd)
          Get a TimeRange, from a single time.
 TimeRange newTimeRange(Time start, Time end)
          Get a TimeRange, from two times, inclusive.
 TimeRange newTimeRange(Time start, Time end, boolean startIncluded, boolean endIncluded)
          Get a TimeRange, from parts.
 void setLogger(Logger service)
          Dependency: logging service.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

M_tz

protected TimeZone M_tz
The time zone for our GMT times.


M_GCal

protected GregorianCalendar M_GCal
a calendar to clone for GMT time construction


M_fmtA

protected SimpleDateFormat M_fmtA
The formatter for our special GMT format(s)


M_fmtB

protected SimpleDateFormat M_fmtB

M_fmtC

protected SimpleDateFormat M_fmtC

M_fmtD

protected SimpleDateFormat M_fmtD

M_fmtE

protected SimpleDateFormat M_fmtE

M_fmtG

protected SimpleDateFormat M_fmtG

M_tz_local_default

protected String M_tz_local_default

m_logger

protected Logger m_logger
Dependency: logging service

Constructor Detail

BasicTimeService

public BasicTimeService()
no arg constructor

Method Detail

setLogger

public void setLogger(Logger service)
Dependency: logging service.

Parameters:
service - The logging service.

init

public void init()
Final initialization, once all dependencies are set.


destroy

public void destroy()
Final cleanup.


getUserLocalTzId

protected String getUserLocalTzId()

getLocalTzFormat

protected BasicTimeService.LocalTzFormat getLocalTzFormat(String timeZoneId)

newTime

public Time newTime()
Get a time object.

Specified by:
newTime in interface TimeService
Returns:
A time object, set to now.

newTimeGmt

public Time newTimeGmt(String value)
Get a time object, set from this string in our format, Gmt values

Specified by:
newTimeGmt in interface TimeService
Parameters:
value - time format string.
Returns:
A time object.

newTime

public Time newTime(long value)
Get a time object, set from this long milliseconds since the "epoc" value.

Specified by:
newTime in interface TimeService
Parameters:
value - time long milliseconds value.
Returns:
A time object.

newTime

public Time newTime(GregorianCalendar cal)
Get a time object, based on the time set in the calendar

Specified by:
newTime in interface TimeService
Returns:
A time object, set to now.

newTimeGmt

public Time newTimeGmt(int year,
                       int month,
                       int day,
                       int hour,
                       int minute,
                       int second,
                       int millisecond)
Get a time object, set from individual ints, Gmt values

Specified by:
newTimeGmt in interface TimeService
Parameters:
year - full year (i.e. 1999, 2000)
month - month in year (1..12)
day - day in month (1..31)
hour - hour in day (0..23)
second - second in minute (0..59)
millisecond - millisecond in second (0..999)
Returns:
A time object.

newTimeGmt

public Time newTimeGmt(TimeBreakdown breakdown)
Get a time object, set from this breakdown (Gmt values).

Specified by:
newTimeGmt in interface TimeService
Parameters:
breakdown - The time breakdown values.
Returns:
A time object.

newTimeLocal

public Time newTimeLocal(int year,
                         int month,
                         int day,
                         int hour,
                         int minute,
                         int second,
                         int millisecond)
Get a time object, set from individual ints, Local values

Specified by:
newTimeLocal in interface TimeService
Parameters:
year - full year (i.e. 1999, 2000)
month - month in year (1..12)
day - day in month (1..31)
hour - hour in day (0..23)
second - second in minute (0..59)
millisecond - millisecond in second (0..999)
Returns:
A time object.

newTimeLocal

public Time newTimeLocal(TimeBreakdown breakdown)
Get a time object, set from this breakdown (Local values).

Specified by:
newTimeLocal in interface TimeService
Parameters:
breakdown - The time breakdown values.
Returns:
A time object.

newTimeBreakdown

public TimeBreakdown newTimeBreakdown(int year,
                                      int month,
                                      int day,
                                      int hour,
                                      int minute,
                                      int second,
                                      int millisecond)
Get a TimeBreakdown object, set from individual ints.

Specified by:
newTimeBreakdown in interface TimeService
Parameters:
year - full year (i.e. 1999, 2000)
month - month in year (1..12)
day - day in month (1..31)
hour - hour in day (0..23)
second - second in minute (0..59)
millisecond - millisecond in second (0..999)
Returns:
A TimeBreakdown.

newTimeRange

public TimeRange newTimeRange(Time start,
                              Time end,
                              boolean startIncluded,
                              boolean endIncluded)
Get a TimeRange, from parts.

Specified by:
newTimeRange in interface TimeService
Parameters:
start - The start Time.
end - The end Time.
startIncluded - true if start is part of the range, false if not.
endIncluded - true of end is part of the range, false if not.
Returns:
A TimeRange.

newTimeRange

public TimeRange newTimeRange(String value)
Get a TimeRange, from our string format.

Specified by:
newTimeRange in interface TimeService
Parameters:
value - The TimeRange string.
Returns:
A TimeRange.

newTimeRange

public TimeRange newTimeRange(Time startAndEnd)
Get a TimeRange, from a single time.

Specified by:
newTimeRange in interface TimeService
Parameters:
startAndEnd - The Time for the range.
Returns:
A TimeRange.

newTimeRange

public TimeRange newTimeRange(long start,
                              long duration)
Get a TimeRange, from a time value long start and duration

Specified by:
newTimeRange in interface TimeService
Parameters:
start - The long start time (milliseconds since).
duration - The long milliseconds duration.
Returns:
A TimeRange.

newTimeRange

public TimeRange newTimeRange(Time start,
                              Time end)
Get a TimeRange, from two times, inclusive.

Specified by:
newTimeRange in interface TimeService
Parameters:
start - The start time.
end - The end time.
Returns:
A TimeRange.

getLocalTimeZone

public TimeZone getLocalTimeZone()
Access the local TimeZone.

Specified by:
getLocalTimeZone in interface TimeService
Returns:
The local TimeZone.

clearLocalTimeZone

public boolean clearLocalTimeZone(String userId)
Clear local time zone for specified user

Specified by:
clearLocalTimeZone in interface TimeService
Returns:
true if successful

getCalendar

public GregorianCalendar getCalendar(TimeZone zone,
                                     int year,
                                     int month,
                                     int day,
                                     int hour,
                                     int min,
                                     int sec,
                                     int ms)
Get a Calendar, set to this zone and these values.

Specified by:
getCalendar in interface TimeService
Parameters:
zone - The TimeZone for the calendar.
year - full year (i.e. 1999, 2000)
month - month in year (1..12)
day - day in month (1..31)
hour - hour in day (0..23)
min - minute in hour (0..59)
ms - millisecond in second (0..999)

different

public boolean different(Time a,
                         Time b)
Compare two Time for differences, either may be null

Specified by:
different in interface TimeService
Parameters:
a - One Time.
b - The other Time.
Returns:
true if the Times are different, false if they are the same.