uk.org.iscream.cms.util
Class DateUtils

java.lang.Object
  extended byuk.org.iscream.cms.util.DateUtils

public class DateUtils
extends Object

Provides easy to use date functions.

Version:
$Id: DateUtils.java,v 1.8 2003/02/05 14:27:58 tdb Exp $
Author:
$Author: tdb $

Field Summary
private  String _name
          This is the friendly identifier of the component this class is running in.
private static String daysKey
           
private static String hoursKey
           
private static String minsKey
           
 String REVISION
          The current CVS revision of this class
private static String secsKey
           
static long secsPerDay
           
static long secsPerHour
           
static long secsPerMin
           
static long secsPerMonth
           
static long secsPerWeek
           
 
Constructor Summary
DateUtils()
           
 
Method Summary
static String dateString(long t)
          Return a nice String representation of the date.
static String dayName(long t)
          Return a String representation of the day name (short format).
static String formatTime(long time)
          Format a long time (in seconds) as a String.
static String formatTime(long time, String layout)
          Format a long time (in seconds) as a String.
static String getTimeString(long time)
          Takes a time period in seconds and converts it to a reasonable message.
static String hourString(long t)
          Return a String representation of the hour.
static long now()
          Return the number of seconds between the epoch and now.
static String shortDateString(long t)
          Return a nice short String representation of the date.
static long startOfToday()
          Return the number of seconds between the epoch and midnight earlier today.
static long subtractDays(long before, int days)
          Accept a long representing the number of seconds since the epoch.
static long subtractHours(long before, int hours)
          Accept a long representing the number of seconds since the epoch.
static long subtractMonths(long before, int months)
          Accept a long representing the number of seconds since the epoch.
static long subtractWeeks(long before, int weeks)
          Accept a long representing the number of seconds since the epoch.
static String timeString(long t)
          Return a String representation of the time (short format).
 String toString()
          Overrides the Object.toString() method to provide clean logging (every class should have this).
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

REVISION

public final String REVISION
The current CVS revision of this class

See Also:
Constant Field Values

secsPerMonth

public static final long secsPerMonth
See Also:
Constant Field Values

secsPerWeek

public static final long secsPerWeek
See Also:
Constant Field Values

secsPerDay

public static final long secsPerDay
See Also:
Constant Field Values

secsPerHour

public static final long secsPerHour
See Also:
Constant Field Values

secsPerMin

public static final long secsPerMin
See Also:
Constant Field Values

daysKey

private static final String daysKey
See Also:
Constant Field Values

hoursKey

private static final String hoursKey
See Also:
Constant Field Values

minsKey

private static final String minsKey
See Also:
Constant Field Values

secsKey

private static final String secsKey
See Also:
Constant Field Values

_name

private String _name
This is the friendly identifier of the component this class is running in. eg, a Filter may be called "filter1", If this class does not have an owning component, a name from the configuration can be placed here. This name could also be changed to null for utility classes.

Constructor Detail

DateUtils

public DateUtils()
Method Detail

startOfToday

public static long startOfToday()
Return the number of seconds between the epoch and midnight earlier today.


now

public static long now()
Return the number of seconds between the epoch and now.


subtractMonths

public static long subtractMonths(long before,
                                  int months)
Accept a long representing the number of seconds since the epoch. An integer specifies the number of months to subtract. Returns a long representing the number of seconds since the epoch.


subtractWeeks

public static long subtractWeeks(long before,
                                 int weeks)
Accept a long representing the number of seconds since the epoch. An integer specifies the number of weeks to subtract. Returns a long representing the number of seconds since the epoch.


subtractDays

public static long subtractDays(long before,
                                int days)
Accept a long representing the number of seconds since the epoch. An integer specifies the number of days to subtract. Returns a long representing the number of seconds since the epoch.


subtractHours

public static long subtractHours(long before,
                                 int hours)
Accept a long representing the number of seconds since the epoch. An integer specifies the number of hours to subtract. Returns a long representing the number of seconds since the epoch.


dateString

public static String dateString(long t)
Return a nice String representation of the date.


shortDateString

public static String shortDateString(long t)
Return a nice short String representation of the date.


hourString

public static String hourString(long t)
Return a String representation of the hour.


dayName

public static String dayName(long t)
Return a String representation of the day name (short format).


timeString

public static String timeString(long t)
Return a String representation of the time (short format).


formatTime

public static String formatTime(long time)
Format a long time (in seconds) as a String. Can be used to clearly layout a period of time in days, hours, minutes and seconds. It could, for example, be used to format an uptime. This method uses a built in default layout, as shown here; "Days: xx, Hours: xx, Mins: xx, Secs: xx"

Parameters:
time - A long value representing the time period in seconds
Returns:
A string representation of the given time period

formatTime

public static String formatTime(long time,
                                String layout)
Format a long time (in seconds) as a String. Can be used to clearly layout a period of time in days, hours, minutes and seconds. It could, for example, be used to format an uptime. This method uses a custom layout given as a String. This string should contain the following keys; "%DAYS% %HOURS% %MINS% %SECS%" As an example, the default layout given by formatTime() is represented by the following layout String; "Days: %DAYS%, Hours: %HOURS%, Mins: %MINS%, Secs: %SECS%"

Parameters:
time - A long value representing the time period in seconds
layout - The custom layout format to use.
Returns:
A string representation of the given time period

getTimeString

public static String getTimeString(long time)
Takes a time period in seconds and converts it to a reasonable message.

Parameters:
time - the time period in seconds
Returns:
a String respresentation of the given time period

toString

public String toString()
Overrides the Object.toString() method to provide clean logging (every class should have this). This uses the uk.org.iscream.cms.server.util.FormatName class to format the toString()

Returns:
the name of this class and its CVS revision


Copyright © 2000-2003 i-scream. All Rights Reserved.