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 DATE_TIME_WITHOUT_ZONE
          DATE_TIME without zone info
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 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
          TimeInterval Reporing & Time Managment
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
 
Method Summary
static java.util.Date addWorkdays(java.util.Date d1, int days)
          adds the specified amount of workdays to the given date
static boolean areHolidaysConfigured()
           
static void deleteTimeInfoUntil(Calendar cal, int field)
          Set the time information to 0 starting at the given field, for example hour
static int easterDay(int year)
          calculates the day of the easter-sunday for the given year
static Calendar getCalendar()
           
static Calendar getCalendar(java.util.Locale loc)
           
static Calendar getCalendar(java.util.Locale loc, java.util.TimeZone tz)
          Returns a calendar instance.
static Calendar getCalendar(java.util.TimeZone tz)
           
static DateFormatSymbols getDateFormatSymbols()
          Returns a DateFormatSymbols instance for the current ThreadContext.getThreadLocale()
static DateFormatSymbols getDateFormatSymbols(Calendar calendar, java.util.Locale loc)
          Returns a DateFormatSymbols instance for the specified Locale and Calendar
if Calendar is null getCalendar() is used
if Locale is null Locale.getDefault() is used
static DateFormatSymbols getDateFormatSymbols(java.util.Locale loc)
           
static SimpleDateFormat getDateFormatter(int type)
          Returns a thread save DateFormat object for the given format.
static SimpleDateFormat getDateFormatter(int type, java.util.Locale loc)
          Get local specific instance of predefined formatter types
static SimpleDateFormat getDateFormatter(int type, java.util.Locale locale, java.util.TimeZone timezone)
          get the localized SimpleDateFormat with the pattern specified by type if the given type has a fixed locale / timezone the given locale / timezone is ignored
static SimpleDateFormat getDateFormatter(int type, java.util.Locale locale, java.util.TimeZone timezone, Calendar cal)
           
static SimpleDateFormat getDateFormatter(int type, java.util.TimeZone tz)
           
static SimpleDateFormat getDateFormatter(java.lang.String pattern)
           
static SimpleDateFormat getDateFormatter(java.lang.String pattern, java.util.Locale loc)
           
static SimpleDateFormat getDateFormatter(java.lang.String pattern, java.util.Locale locale, java.util.TimeZone timezone)
          get a SimpleDateFormat instance for the pattern/locale/timezone
static SimpleDateFormat getDateFormatter(java.lang.String pattern, java.util.TimeZone tz)
           
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 java.util.Calendar getJavaCalendar(Calendar icuCalendar)
           
static int getUnitIntFromString(java.lang.String unit)
           
static boolean isBetween(java.util.Date date, java.util.Date start, java.util.Date end)
          returns true if the passed date is not before start and not after end.
static java.lang.String isHoliday(Calendar c)
          Returns null or the name of the holiday for the given day
static boolean isNonWorkingDay(int day_of_week)
           
static java.util.Date parseDate(int type, java.lang.String dateString)
          parse a date from a string with the specified formatter
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 TimeZone parseTimeZone(java.util.TimeZone tz)
           
static void reconfigure()
           
static void setDateFormatter(int type, SimpleDateFormat df)
           
static java.lang.String showDate(int type, java.util.Locale locale, java.util.TimeZone timezone, java.lang.Object d)
           
static java.lang.String showDate(int type, java.lang.Object d)
           
static java.lang.String showDate(java.lang.Object d)
          Show the date using the default formatter.
static java.lang.String showDate(java.lang.String pattern, java.util.Locale locale, java.util.TimeZone timeZone, java.lang.Object d)
           
static java.lang.String showDate(java.lang.String pattern, java.lang.Object d)
           
static java.lang.String showDateTime(java.lang.Object d)
          Show the date and time using the default formatter.
static java.lang.String showDateTimeSeconds(java.lang.Object d)
          Show the date and time in the form yyyy-MM-dd HH:mm:ss.
static int thisYear()
          Return the current year.
static java.util.Date toBeginDay(java.util.Date date)
          returns the date set to 00:00:00:00
static java.util.Date toEndDay(java.util.Date date)
          returns a date set to 23:59:59:999
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 final int DATE
Date format as set in the configuration

See Also:
Constant Field Values

DATE_TIME

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

See Also:
Constant Field Values

RFC1123

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

See Also:
Constant Field Values

RFC1036

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

See Also:
Constant Field Values

ANSI_C_ASCTIME

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

See Also:
Constant Field Values

LOG_DATE

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

See Also:
Constant Field Values

ISO

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

See Also:
Constant Field Values

XML_DATE

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

See Also:
Constant Field Values

DATE_TIME_SEC

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

See Also:
Constant Field Values

DATE_TIME_SEC_DIGITS

public static final int DATE_TIME_SEC_DIGITS
date format : yyyyMMddHHmmss

See Also:
Constant Field Values

DATE_TIME_WITHOUT_ZONE

public static final int DATE_TIME_WITHOUT_ZONE
DATE_TIME without zone info

See Also:
Constant Field Values

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

SECONDS

public static final int SECONDS
TimeInterval Reporing & Time Managment

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

Method Detail

addWorkdays

public static java.util.Date addWorkdays(java.util.Date d1,
                                         int days)
adds the specified amount of workdays to the given date

Parameters:
d1 -
days -
Returns:
the new date

areHolidaysConfigured

public static boolean areHolidaysConfigured()
Returns:
true if the special class was configured for holidays; otherwise returns false

deleteTimeInfoUntil

public static void deleteTimeInfoUntil(Calendar cal,
                                       int field)
Set the time information to 0 starting at the given field, for example hour

Parameters:
cal -
field -

easterDay

public static int easterDay(int year)
calculates the day of the easter-sunday for the given year

Parameters:
year -
Returns:
the easter-sunday for the given year

getCalendar

public static Calendar getCalendar()
Returns:
a calendar instance with ThreadContext.getThreadLocale() and ThreadContext.getThreadTimeZone()
See Also:
getCalendar(Locale, TimeZone)

getCalendar

public static Calendar getCalendar(java.util.Locale loc)
Returns:
a calendar instance
See Also:
getCalendar(Locale, TimeZone)

getCalendar

public static Calendar getCalendar(java.util.TimeZone tz)
Returns:
a calendar instance
See Also:
getCalendar(Locale, TimeZone)

getCalendar

public static Calendar getCalendar(java.util.Locale loc,
                                   java.util.TimeZone tz)
Returns a calendar instance. The calendar class can be set using the configuration parameter "calendar.class". Default is the GregorianCalendar.

Parameters:
loc - the locale if locale is null, Locale.getDefault() is used
tz - the TimeZone if timezone is null, TimeZone.getDefault() is used
Returns:
a calendar instance

getJavaCalendar

public static java.util.Calendar getJavaCalendar(Calendar icuCalendar)

getDateFormatSymbols

public static DateFormatSymbols getDateFormatSymbols()
Returns a DateFormatSymbols instance for the current ThreadContext.getThreadLocale()

Returns:
a DateFormatSymbols instance
See Also:
getDateFormatSymbols(Calendar, Locale)

getDateFormatSymbols

public static DateFormatSymbols getDateFormatSymbols(Calendar calendar,
                                                     java.util.Locale loc)
Returns a DateFormatSymbols instance for the specified Locale and Calendar
if Calendar is null getCalendar() is used
if Locale is null Locale.getDefault() is used

Parameters:
calendar - the calendar
loc - the locale
Returns:
a DateFormatSymbols instance

getDateFormatSymbols

public static DateFormatSymbols getDateFormatSymbols(java.util.Locale loc)
Parameters:
loc - the locale
Returns:
a DateFormatSymbols instance
See Also:
getDateFormatSymbols(Calendar, Locale)

getDateFormatter

public static SimpleDateFormat 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 SimpleDateFormat getDateFormatter(int type,
                                                java.util.Locale loc)
Get local specific instance of predefined formatter types

Parameters:
type -
loc -
Returns:
local specific instance of predefined formatter types

getDateFormatter

public static SimpleDateFormat getDateFormatter(int type,
                                                java.util.Locale locale,
                                                java.util.TimeZone timezone)
get the localized SimpleDateFormat with the pattern specified by type if the given type has a fixed locale / timezone the given locale / timezone is ignored

Parameters:
type - one of DATE,DATE_TIME,DATE_TIME_SEC,DATE_TIME_WITHOUT_ZONE,DATE_TIME_SEC_DIGITS
locale - the locale
timezone - the timezone
Returns:
the DateFormat

getDateFormatter

public static SimpleDateFormat getDateFormatter(int type,
                                                java.util.Locale locale,
                                                java.util.TimeZone timezone,
                                                Calendar cal)
Parameters:
type - one of DATE,DATE_TIME,DATE_TIME_SEC,DATE_TIME_WITHOUT_ZONE,DATE_TIME_SEC_DIGITS
locale - the locale
timezone - the timezone
cal - the calendar to be used
Returns:
the DateFormat

getDateFormatter

public static SimpleDateFormat getDateFormatter(int type,
                                                java.util.TimeZone tz)
Parameters:
type -
tz -
Returns:
the date formatter
See Also:
getDateFormatter(int, Locale, TimeZone)

getDateFormatter

public static SimpleDateFormat getDateFormatter(java.lang.String pattern)
Parameters:
pattern -
Returns:
the date formatter
See Also:
getDateFormatter(String, Locale, TimeZone)

getDateFormatter

public static SimpleDateFormat getDateFormatter(java.lang.String pattern,
                                                java.util.Locale loc)
Parameters:
pattern -
loc -
Returns:
the date formatter
See Also:
getDateFormatter(String, Locale, TimeZone)

getDateFormatter

public static SimpleDateFormat getDateFormatter(java.lang.String pattern,
                                                java.util.Locale locale,
                                                java.util.TimeZone timezone)
get a SimpleDateFormat instance for the pattern/locale/timezone

Parameters:
pattern -
locale -
timezone -
Returns:
the date formatter

getDateFormatter

public static SimpleDateFormat getDateFormatter(java.lang.String pattern,
                                                java.util.TimeZone tz)
Parameters:
pattern -
tz -
Returns:
the date formatter
See Also:
getDateFormatter(String, Locale, TimeZone)

getIntervalInUnits

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

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,
                                                  int minunit,
                                                  java.lang.String[] unitNames)

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
maxunit -
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,
                                                  java.lang.String maxunit)
Returns a String representation of a TimeIntervall using the short names of timeunits

Parameters:
interval - the intervall in millisecondes
maxunit - - 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)

getUnitIntFromString

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

isHoliday

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

Returns:
a holiday name or null

isNonWorkingDay

public static boolean isNonWorkingDay(int day_of_week)

parseDate

public static java.util.Date parseDate(int type,
                                       java.lang.String dateString)
parse a date from a string with the specified formatter

Parameters:
type -
dateString -
Returns:
Date instance

parseDate

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

Parameters:
s - a string representing a date or date + time
Returns:
a date object

parseDateEndDay

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

Returns:
a date object

parseTimeZone

public static TimeZone parseTimeZone(java.util.TimeZone tz)

reconfigure

public static void reconfigure()

setDateFormatter

public static void setDateFormatter(int type,
                                    SimpleDateFormat df)

showDate

public static java.lang.String showDate(int type,
                                        java.util.Locale locale,
                                        java.util.TimeZone timezone,
                                        java.lang.Object d)

showDate

public static java.lang.String showDate(int type,
                                        java.lang.Object d)

showDate

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

Parameters:
d - the date object

showDate

public static java.lang.String showDate(java.lang.String pattern,
                                        java.util.Locale locale,
                                        java.util.TimeZone timeZone,
                                        java.lang.Object d)

showDate

public static java.lang.String showDate(java.lang.String pattern,
                                        java.lang.Object d)

showDateTime

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

Parameters:
d - the date object

showDateTimeSeconds

public static java.lang.String showDateTimeSeconds(java.lang.Object d)
Show the date and time in the form yyyy-MM-dd HH:mm:ss.

Parameters:
d - the date object

thisYear

public static int thisYear()
Return the current year.

Returns:
the current year as integer.

toBeginDay

public static java.util.Date toBeginDay(java.util.Date date)
returns the date set to 00:00:00:00

Parameters:
date -
Returns:
the date set to 00:00:00:00

toEndDay

public static java.util.Date toEndDay(java.util.Date date)
returns a date set to 23:59:59:999

Parameters:
date -
Returns:
the date set to 23:59:59:999

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.

isBetween

public static boolean isBetween(java.util.Date date,
                                java.util.Date start,
                                java.util.Date end)
returns true if the passed date is not before start and not after end. If start is null the passed date is considered as not before start. If end is null the passed date is considered as not after end.



@enterprise 8.0.22989 Copyright © 2001-2017 Groiss Informatics GmbH. All Rights Reserved.