com.groiss.cal
Class CalUtil

java.lang.Object
  extended by com.groiss.cal.CalUtil

public class CalUtil
extends java.lang.Object

This class provides some utilities for date and time handling. It uses two properties: 'DateFormat' and 'DateTimeFormat' which must be set in the default configuration object. The integer constants in this class can be used with the method getDateFormatter to get a thread save DateFormat instance for this format.


Field Summary
static int ANSI_C_ASCTIME
          ANSI C's asctime() format: EEE MMM d HH:mm:ss yyyy
static int DATE
          Date format as set in the configuration
static int DATE_TIME
          Date and time format as set in the configuration
static int DATE_TIME_SEC
          date format : yyyy-MM-dd HH:mm:ss
static int DATE_TIME_SEC_DIGITS
          date format : yyyyMMddHHmmss
static int DAYS
           
static int HOURS
           
static int ISO
          Date format ISO 8601: yyyy-MM-dd'T'HH:mm:ss'Z'
static int LOG_DATE
          Date format for log output: yyyy-MM-dd HH:mm:ss.SSS
static long MILLISPERDAY
          Number of milliseconds per day
static int MINUTES
           
static boolean[] nonWorkingDays
           
static int RFC1036
          Date format RFC1036: EEEEEEEEE, dd-MMM-yy HH:mm:ss z
static int RFC1123
          Date format RFC1123: EEE, dd MMM yyyy HH:mm:ss z
static int SECONDS
           
static java.lang.String[] SHORT_UNIT_NAMES
          short and normal names for TimeUnits
static long[] UNIT_FACTORS
          the Unit Factorys
static java.lang.String[] UNIT_NAMES
           
static int WEEK
           
static int XML_DATE
          xml date format: yyyy-MM-dd
static long YEAR_THOUSAND
          the time value of the date object of date January 1, 1000
 
Constructor Summary
CalUtil()
           
 
Method Summary
static java.util.Date addWorkdays(java.util.Date d1, int days)
           
static int easterDay(int year)
           
static java.util.Calendar getCalendar(java.util.Locale loc)
          Returns a calendar instance.
static java.text.DateFormat getDateFormatter(int type)
          Returns a thread save DateFormat object for the given format.
static java.text.SimpleDateFormat getDateFormatter(int type, java.util.Locale loc)
          Get local specific instance of predefined formatter types
static java.text.SimpleDateFormat getDateFormatter(java.lang.String pattern, java.util.Locale loc)
          Returns the date formatter defined in the configuration parameter "date.format.class".
static java.lang.String getIntervalInUnits(long interval)
           
static java.lang.String getIntervalInUnits(long interval, int maxunit)
           
static java.lang.String getIntervalInUnits(long interval, int maxunit, int minunit)
           
static java.lang.String getIntervalInUnits(long interval, int maxunit, int minunit, java.lang.String[] unitNames)
           
static java.lang.String getIntervalInUnits(long interval, int maxunit, java.lang.String[] unitNames)
          Returns a String representation of a TimeIntervall
static java.lang.String getIntervalInUnits(long interval, java.lang.String maxunit)
          Returns a String representation of a TimeIntervall using the short names of timeunits
static java.lang.String getIntervalInUnits(long interval, java.lang.String maxunit, java.lang.String minunit)
           
static int getUnitIntFromString(java.lang.String unit)
           
static java.lang.String isHoliday(java.util.Calendar c)
          Returns null or the name of the holiday for the given day
static java.util.Date parseDate(java.lang.String s)
          Parse a date from a string.
static java.util.Date parseDateEndDay(java.lang.String s)
          Parses the date sets the time to 23:59.
static void setDateFormatter(int type, java.text.DateFormat df)
           
static java.lang.String showDate(java.util.Date d)
          Show the date using the default formatter.
static java.lang.String showDateTime(java.util.Date d)
          Show the date and time using the default formatter.
static int thisYear()
          Return the current year.
static int workDaysBetween(java.util.Date d1, java.util.Date d2)
          Compute the working days between the two argument date
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DATE

public static int DATE
Date format as set in the configuration


DATE_TIME

public static int DATE_TIME
Date and time format as set in the configuration


RFC1123

public static int RFC1123
Date format RFC1123: EEE, dd MMM yyyy HH:mm:ss z


RFC1036

public static int RFC1036
Date format RFC1036: EEEEEEEEE, dd-MMM-yy HH:mm:ss z


ANSI_C_ASCTIME

public static int ANSI_C_ASCTIME
ANSI C's asctime() format: EEE MMM d HH:mm:ss yyyy


LOG_DATE

public static int LOG_DATE
Date format for log output: yyyy-MM-dd HH:mm:ss.SSS


ISO

public static int ISO
Date format ISO 8601: yyyy-MM-dd'T'HH:mm:ss'Z'


XML_DATE

public static int XML_DATE
xml date format: yyyy-MM-dd


DATE_TIME_SEC

public static int DATE_TIME_SEC
date format : yyyy-MM-dd HH:mm:ss


DATE_TIME_SEC_DIGITS

public static int DATE_TIME_SEC_DIGITS
date format : yyyyMMddHHmmss


YEAR_THOUSAND

public static final long YEAR_THOUSAND
the time value of the date object of date January 1, 1000

See Also:
Constant Field Values

MILLISPERDAY

public static final long MILLISPERDAY
Number of milliseconds per day

See Also:
Constant Field Values

nonWorkingDays

public static boolean[] nonWorkingDays

SECONDS

public static final int SECONDS
See Also:
Constant Field Values

MINUTES

public static final int MINUTES
See Also:
Constant Field Values

HOURS

public static final int HOURS
See Also:
Constant Field Values

DAYS

public static final int DAYS
See Also:
Constant Field Values

WEEK

public static final int WEEK
See Also:
Constant Field Values

SHORT_UNIT_NAMES

public static final java.lang.String[] SHORT_UNIT_NAMES
short and normal names for TimeUnits


UNIT_NAMES

public static final java.lang.String[] UNIT_NAMES

UNIT_FACTORS

public static final long[] UNIT_FACTORS
the Unit Factorys

Constructor Detail

CalUtil

public CalUtil()
Method Detail

thisYear

public static int thisYear()
Return the current year.

Returns:
the current year as integer.

parseDate

public static java.util.Date parseDate(java.lang.String s)
                                throws java.lang.Exception
Parse a date from a string.

Parameters:
s - a string representing a date or date + time
Returns:
a date object
Throws:
java.lang.Exception

parseDateEndDay

public static java.util.Date parseDateEndDay(java.lang.String s)
                                      throws java.lang.Exception
Parses the date sets the time to 23:59. This is useful for intervals.

Returns:
a date object
Throws:
java.lang.Exception

getDateFormatter

public static java.text.DateFormat getDateFormatter(int type)
Returns a thread save DateFormat object for the given format.

Parameters:
type - is one of the integer constants of this class (DATE, RFC1123, ...)
Returns:
a DateFormat instance

getDateFormatter

public static java.text.SimpleDateFormat getDateFormatter(java.lang.String pattern,
                                                          java.util.Locale loc)
                                                   throws java.lang.SecurityException,
                                                          java.lang.NoSuchMethodException,
                                                          java.lang.IllegalArgumentException,
                                                          java.lang.InstantiationException,
                                                          java.lang.IllegalAccessException,
                                                          java.lang.reflect.InvocationTargetException
Returns the date formatter defined in the configuration parameter "date.format.class". Default is SimpleDateFormat

Parameters:
pattern -
loc -
Returns:
a new instance of SimpleDateFormat
Throws:
java.lang.SecurityException
java.lang.NoSuchMethodException
java.lang.IllegalArgumentException
java.lang.InstantiationException
java.lang.IllegalAccessException
java.lang.reflect.InvocationTargetException

getDateFormatter

public static java.text.SimpleDateFormat getDateFormatter(int type,
                                                          java.util.Locale loc)
                                                   throws java.lang.SecurityException,
                                                          java.lang.NoSuchMethodException,
                                                          java.lang.IllegalArgumentException,
                                                          java.lang.InstantiationException,
                                                          java.lang.IllegalAccessException,
                                                          java.lang.reflect.InvocationTargetException
Get local specific instance of predefined formatter types

Parameters:
type -
loc -
Returns:
local specific instance of predefined formatter types
Throws:
java.lang.SecurityException
java.lang.NoSuchMethodException
java.lang.IllegalArgumentException
java.lang.InstantiationException
java.lang.IllegalAccessException
java.lang.reflect.InvocationTargetException

getCalendar

public static java.util.Calendar getCalendar(java.util.Locale loc)
                                      throws java.lang.SecurityException,
                                             java.lang.NoSuchMethodException,
                                             java.lang.IllegalArgumentException,
                                             java.lang.InstantiationException,
                                             java.lang.IllegalAccessException,
                                             java.lang.reflect.InvocationTargetException
Returns a calendar instance. The calendar class can be set using the configuration parameter "calendar.class". Default is the GregorianCalendar.

Parameters:
loc - the locale is used to get the calendar for the right locale (for example to determine first day of week.
Returns:
a calendar instance
Throws:
java.lang.SecurityException
java.lang.NoSuchMethodException
java.lang.IllegalArgumentException
java.lang.InstantiationException
java.lang.IllegalAccessException
java.lang.reflect.InvocationTargetException

setDateFormatter

public static void setDateFormatter(int type,
                                    java.text.DateFormat df)

showDateTime

public static java.lang.String showDateTime(java.util.Date d)
Show the date and time using the default formatter.

Parameters:
d - the date object

showDate

public static java.lang.String showDate(java.util.Date d)
Show the date using the default formatter.

Parameters:
d - the date object

isHoliday

public static java.lang.String isHoliday(java.util.Calendar c)
Returns null or the name of the holiday for the given day

Returns:
a holiday name or null

workDaysBetween

public static int workDaysBetween(java.util.Date d1,
                                  java.util.Date d2)
Compute the working days between the two argument date

Parameters:
d1 - the start date
d2 - the end date
Returns:
the days between, excluding holidays, saturdays, and sundays, including the start and the end day.

addWorkdays

public static java.util.Date addWorkdays(java.util.Date d1,
                                         int days)

easterDay

public static int easterDay(int year)

getUnitIntFromString

public static int getUnitIntFromString(java.lang.String unit)

getIntervalInUnits

public static java.lang.String getIntervalInUnits(long interval)

getIntervalInUnits

public static java.lang.String getIntervalInUnits(long interval,
                                                  java.lang.String maxunit)
Returns a String representation of a TimeIntervall using the short names of timeunits

Parameters:
interval - the intervall in millisecondes
unit - - the unis as string (maybe short or normal name)
Returns:
a String representation of this Intervals, embedded in a DIV block with textalign right.

getIntervalInUnits

public static java.lang.String getIntervalInUnits(long interval,
                                                  java.lang.String maxunit,
                                                  java.lang.String minunit)

getIntervalInUnits

public static java.lang.String getIntervalInUnits(long interval,
                                                  int maxunit)

getIntervalInUnits

public static java.lang.String getIntervalInUnits(long interval,
                                                  int maxunit,
                                                  int minunit)

getIntervalInUnits

public static java.lang.String getIntervalInUnits(long interval,
                                                  int maxunit,
                                                  java.lang.String[] unitNames)
Returns a String representation of a TimeIntervall

Parameters:
interval - the intervall in millisecondes
unit - - the unis as string (maybe short or normal name)
unitNames - - The UntiNames to use for the string representation
Returns:
a String representation of this Intervals, embedded in a DIV block with textalign right.

getIntervalInUnits

public static java.lang.String getIntervalInUnits(long interval,
                                                  int maxunit,
                                                  int minunit,
                                                  java.lang.String[] unitNames)


Copyright © 2001-2006 Groiss Informatics GmbH. All Rights Reserved.