nl.knowledgeplaza.util
Class CalendarUtil

java.lang.Object
  extended by nl.knowledgeplaza.util.CalendarUtil

public class CalendarUtil
extends java.lang.Object

Quick format and quick parse (ISO) for Calendars

Version:
$Revision: 1.5 $
Author:
$Author: toeukpap $

Field Summary
static long EPOCH_UNIX_ERA_DAY
          Value to add to the day number returned by this calendar to find the Julian Day number.
protected static long MILLISECS_PER_DAY
          Number of leap seconds per day expect on
1.
static long MILLISECS_PER_HOUR
          Number of milliseconds per hour, except when a leap second is inserted.
static long MILLISECS_PER_MINUTE
          All minutes have this many milliseconds except the last minute of the day on a day defined with a leap second.
static java.lang.String SOURCECODE_VERSION
          Standard variable for determining version of a class file.
 
Constructor Summary
CalendarUtil()
           
 
Method Summary
static java.util.Calendar clearDate(java.util.Calendar c)
          Clear date (date becomes 1-1-1)
static java.util.Calendar clearTime(java.util.Calendar c)
          Clear time
static java.util.Calendar copyDate(java.util.Calendar from, java.util.Calendar to)
          copies the date fields from the first into the second parameter
static java.util.Calendar copyTime(java.util.Calendar from, java.util.Calendar to)
          copies the time fields from the first into the second parameter
static long distanceInDays(java.util.Calendar c1, java.util.Calendar c2)
          Difference between two dates in days
static long distanceInMilliseconds(java.util.Calendar c1, java.util.Calendar c2)
          Difference between two dates in milliseconds
static java.lang.String filePrefix()
           
static java.lang.String filePrefix(java.util.Calendar calendar)
          create a date-time file prefix
static java.lang.String filePrefixLong()
           
static java.lang.String filePrefixLong(java.util.Calendar calendar)
          create a date-time file prefix including milliseconds
static java.lang.String getDateSeparator()
          Return the date separator, e.g.
static java.lang.String getDateSeparator(java.util.Locale locale)
          Return the date separator, e.g.
static long getJulianDay(java.util.Calendar c)
           
static long getUnixDay(java.util.Calendar c)
           
static java.util.Calendar gotoFirstDateOfHalfyear(java.util.Calendar c)
          Move the provided calendar to the first date Make sure to provide a clone if you don't want to provided calendar to be altered.
static java.util.Calendar gotoFirstDateOfLastFewMonths(java.util.Calendar c, int months)
          Move the provided calendar to the first date Make sure to provide a clone if you don't want to provided calendar to be altered.
static java.util.Calendar gotoFirstDateOfMonth(java.util.Calendar c)
          Move the provided calendar to the first date Make sure to provide a clone if you don't want to provided calendar to be altered.
static java.util.Calendar gotoFirstDateOfQuarter(java.util.Calendar c)
          Move the provided calendar to the first date Make sure to provide a clone if you don't want to provided calendar to be altered.
static java.util.Calendar gotoFirstDateOfWeek(java.util.Calendar c)
          Move the provided calendar to the first date of the week.
static java.util.Calendar gotoFirstDateOfYear(java.util.Calendar c)
          Move the provided calendar to the first date Make sure to provide a clone if you don't want to provided calendar to be altered.
static java.util.Calendar gotoLastDateOfHalfyear(java.util.Calendar c)
          Move the provided calendar to the last date Make sure to provide a clone if you don't want to provided calendar to be altered.
static java.util.Calendar gotoLastDateOfLastFewMonths(java.util.Calendar c, int months)
          Move the provided calendar to the last date, Make sure to provide a clone if you don't want to provided calendar to be altered.
static java.util.Calendar gotoLastDateOfMonth(java.util.Calendar c)
          Move the provided calendar to the last date Make sure to provide a clone if you don't want to provided calendar to be altered.
static java.util.Calendar gotoLastDateOfQuarter(java.util.Calendar c)
          Move the provided calendar to the last date Make sure to provide a clone if you don't want to provided calendar to be altered.
static java.util.Calendar gotoLastDateOfWeek(java.util.Calendar c)
          Move the provided calendar to the last date of the week.
static java.util.Calendar gotoLastDateOfYear(java.util.Calendar c)
          Move the provided calendar to the last date Make sure to provide a clone if you don't want to provided calendar to be altered.
static boolean isSameDate(java.util.Calendar c1, java.util.Calendar c2)
          See if two dates are on the same date (ignoring the time)
static boolean isSameTimeHMS(java.util.Calendar c1, java.util.Calendar c2)
          See if two dates are on the same time (ignoring the date) for hour, minute and second
static boolean isSameTimeHMSM(java.util.Calendar c1, java.util.Calendar c2)
          See if two dates are on the same time (ignoring the date) for hour, minute, second and millesecond
static java.lang.String quickFormatCalendar(java.util.Calendar calendar)
          small utility method to format a calendar for logging according to YYYY-MM-DD
static java.lang.String quickFormatCalendarDate(java.util.Calendar calendar)
          small utility method to format a calendar for logging according to YYYY-MM-DD
static java.lang.String quickFormatCalendarTime(java.util.Calendar pCalendar)
          small utility method to format a calendar for logging according to YYYY-MM-DD
static java.util.GregorianCalendar quickParseGregorianCalendar(java.lang.String value)
          small utility method to format a calendar for logging according to YYYY-MM-DD
static java.util.GregorianCalendar quickParseGregorianCalendarDate(java.lang.String value)
          small utility method to format a calendar for logging according to YYYY-MM-DD
static java.util.GregorianCalendar quickParseGregorianCalendarFull(java.lang.String value)
          small utility method to format a calendar for logging according to YYYY-MM-DD
static java.util.GregorianCalendar quickParseGregorianCalendarTime(java.lang.String value)
          small utility method to format a calendar for logging according to YYYY-MM-DD
static java.util.Calendar setFromMilliseconds(java.util.Calendar calendar, long value)
          Set calendar from milliseconds
static java.util.Calendar setTimeToJustBeforeMidnight(java.util.Calendar c)
          23:59:59.999
static java.util.Calendar setTimeToMidnight(java.util.Calendar c)
          00:00:00.000
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

SOURCECODE_VERSION

public static final java.lang.String SOURCECODE_VERSION
Standard variable for determining version of a class file.

See Also:
Constant Field Values

MILLISECS_PER_MINUTE

public static final long MILLISECS_PER_MINUTE
All minutes have this many milliseconds except the last minute of the day on a day defined with a leap second.

See Also:
Constant Field Values

MILLISECS_PER_HOUR

public static final long MILLISECS_PER_HOUR
Number of milliseconds per hour, except when a leap second is inserted.

See Also:
Constant Field Values

MILLISECS_PER_DAY

protected static final long MILLISECS_PER_DAY
Number of leap seconds per day expect on
1. days when a leap second has been inserted, e.g. 1999 JAN 1.
2. Daylight-savings "spring forward" or "fall back" days.

See Also:
Constant Field Values

EPOCH_UNIX_ERA_DAY

public static final long EPOCH_UNIX_ERA_DAY
Value to add to the day number returned by this calendar to find the Julian Day number. This is the Julian Day number for 1/1/1970. Note: Since the unix Day number is the same from local midnight to local midnight adding JULIAN_DAY_OFFSET to that value results in the chronologist, historians, or calenderists Julian Day number.

See Also:
http://www.hermetic.ch/cal_stud/jdn.htm, Constant Field Values
Constructor Detail

CalendarUtil

public CalendarUtil()
Method Detail

quickFormatCalendar

public static java.lang.String quickFormatCalendar(java.util.Calendar calendar)
small utility method to format a calendar for logging according to YYYY-MM-DD

Parameters:
calendar - the calendar
Returns:
a string with the formatted calendar

quickFormatCalendarDate

public static java.lang.String quickFormatCalendarDate(java.util.Calendar calendar)
small utility method to format a calendar for logging according to YYYY-MM-DD

Parameters:
calendar - the calendar
Returns:
a string with the formatted calendar

quickFormatCalendarTime

public static java.lang.String quickFormatCalendarTime(java.util.Calendar pCalendar)
small utility method to format a calendar for logging according to YYYY-MM-DD

Parameters:
pCalendar - the calendar
Returns:
a string with the formatted calendar

quickParseGregorianCalendar

public static java.util.GregorianCalendar quickParseGregorianCalendar(java.lang.String value)
small utility method to format a calendar for logging according to YYYY-MM-DD

Parameters:
pCalendar - the calendar
Returns:
a string with the formatted calendar

quickParseGregorianCalendarFull

public static java.util.GregorianCalendar quickParseGregorianCalendarFull(java.lang.String value)
small utility method to format a calendar for logging according to YYYY-MM-DD

Parameters:
pCalendar - the calendar
Returns:
a string with the formatted calendar

quickParseGregorianCalendarDate

public static java.util.GregorianCalendar quickParseGregorianCalendarDate(java.lang.String value)
small utility method to format a calendar for logging according to YYYY-MM-DD

Parameters:
pCalendar - the calendar
Returns:
a string with the formatted calendar

quickParseGregorianCalendarTime

public static java.util.GregorianCalendar quickParseGregorianCalendarTime(java.lang.String value)
small utility method to format a calendar for logging according to YYYY-MM-DD

Parameters:
pCalendar - the calendar
Returns:
a string with the formatted calendar

gotoFirstDateOfWeek

public static java.util.Calendar gotoFirstDateOfWeek(java.util.Calendar c)
Move the provided calendar to the first date of the week. Make sure to provide a clone if you don't want to provided calendar to be altered.

Parameters:
c -

gotoLastDateOfWeek

public static java.util.Calendar gotoLastDateOfWeek(java.util.Calendar c)
Move the provided calendar to the last date of the week. Make sure to provide a clone if you don't want to provided calendar to be altered.

Parameters:
c -

gotoFirstDateOfMonth

public static java.util.Calendar gotoFirstDateOfMonth(java.util.Calendar c)
Move the provided calendar to the first date Make sure to provide a clone if you don't want to provided calendar to be altered.

Parameters:
c -

gotoLastDateOfMonth

public static java.util.Calendar gotoLastDateOfMonth(java.util.Calendar c)
Move the provided calendar to the last date Make sure to provide a clone if you don't want to provided calendar to be altered.

Parameters:
c -

gotoFirstDateOfLastFewMonths

public static java.util.Calendar gotoFirstDateOfLastFewMonths(java.util.Calendar c,
                                                              int months)
Move the provided calendar to the first date Make sure to provide a clone if you don't want to provided calendar to be altered.

Parameters:
c -

gotoLastDateOfLastFewMonths

public static java.util.Calendar gotoLastDateOfLastFewMonths(java.util.Calendar c,
                                                             int months)
Move the provided calendar to the last date, Make sure to provide a clone if you don't want to provided calendar to be altered.

Parameters:
c -

gotoFirstDateOfQuarter

public static java.util.Calendar gotoFirstDateOfQuarter(java.util.Calendar c)
Move the provided calendar to the first date Make sure to provide a clone if you don't want to provided calendar to be altered.

Parameters:
c -

gotoLastDateOfQuarter

public static java.util.Calendar gotoLastDateOfQuarter(java.util.Calendar c)
Move the provided calendar to the last date Make sure to provide a clone if you don't want to provided calendar to be altered.

Parameters:
c -

gotoFirstDateOfHalfyear

public static java.util.Calendar gotoFirstDateOfHalfyear(java.util.Calendar c)
Move the provided calendar to the first date Make sure to provide a clone if you don't want to provided calendar to be altered.

Parameters:
c -

gotoLastDateOfHalfyear

public static java.util.Calendar gotoLastDateOfHalfyear(java.util.Calendar c)
Move the provided calendar to the last date Make sure to provide a clone if you don't want to provided calendar to be altered.

Parameters:
c -

gotoFirstDateOfYear

public static java.util.Calendar gotoFirstDateOfYear(java.util.Calendar c)
Move the provided calendar to the first date Make sure to provide a clone if you don't want to provided calendar to be altered.

Parameters:
c -

gotoLastDateOfYear

public static java.util.Calendar gotoLastDateOfYear(java.util.Calendar c)
Move the provided calendar to the last date Make sure to provide a clone if you don't want to provided calendar to be altered.

Parameters:
c -

clearDate

public static java.util.Calendar clearDate(java.util.Calendar c)
Clear date (date becomes 1-1-1)

Parameters:
c -

clearTime

public static java.util.Calendar clearTime(java.util.Calendar c)
Clear time

Parameters:
c -

setTimeToMidnight

public static java.util.Calendar setTimeToMidnight(java.util.Calendar c)
00:00:00.000

Parameters:
c -

setTimeToJustBeforeMidnight

public static java.util.Calendar setTimeToJustBeforeMidnight(java.util.Calendar c)
23:59:59.999

Parameters:
c -

copyDate

public static java.util.Calendar copyDate(java.util.Calendar from,
                                          java.util.Calendar to)
copies the date fields from the first into the second parameter

Parameters:
c -

copyTime

public static java.util.Calendar copyTime(java.util.Calendar from,
                                          java.util.Calendar to)
copies the time fields from the first into the second parameter

Parameters:
c -

isSameDate

public static boolean isSameDate(java.util.Calendar c1,
                                 java.util.Calendar c2)
See if two dates are on the same date (ignoring the time)

Parameters:
c1 -
c2 -
Returns:

isSameTimeHMS

public static boolean isSameTimeHMS(java.util.Calendar c1,
                                    java.util.Calendar c2)
See if two dates are on the same time (ignoring the date) for hour, minute and second

Parameters:
c1 -
c2 -
Returns:

isSameTimeHMSM

public static boolean isSameTimeHMSM(java.util.Calendar c1,
                                     java.util.Calendar c2)
See if two dates are on the same time (ignoring the date) for hour, minute, second and millesecond

Parameters:
c1 -
c2 -
Returns:

getDateSeparator

public static java.lang.String getDateSeparator()
Return the date separator, e.g. - for Dutch, . for German

Returns:

getDateSeparator

public static java.lang.String getDateSeparator(java.util.Locale locale)
Return the date separator, e.g. - for Dutch, . for German

Parameters:
locale -
Returns:

distanceInDays

public static long distanceInDays(java.util.Calendar c1,
                                  java.util.Calendar c2)
Difference between two dates in days

Parameters:
c1 -
c2 -
Returns:

distanceInMilliseconds

public static long distanceInMilliseconds(java.util.Calendar c1,
                                          java.util.Calendar c2)
Difference between two dates in milliseconds

Parameters:
c1 -
c2 -
Returns:

setFromMilliseconds

public static java.util.Calendar setFromMilliseconds(java.util.Calendar calendar,
                                                     long value)
Set calendar from milliseconds

Parameters:
value -

getUnixDay

public static long getUnixDay(java.util.Calendar c)
Returns:
Day number where day 0 is 1/1/1970, as per the Unix/Java date/time epoch.

getJulianDay

public static long getJulianDay(java.util.Calendar c)
Returns:
LOCAL Chronologists Julian day number each day starting from midnight LOCAL TIME.
See Also:
for more information about local C-JDN

filePrefix

public static java.lang.String filePrefix(java.util.Calendar calendar)
create a date-time file prefix

Parameters:
calendar - the calendar
Returns:
a string with can act as a filename prefix

filePrefix

public static java.lang.String filePrefix()

filePrefixLong

public static java.lang.String filePrefixLong(java.util.Calendar calendar)
create a date-time file prefix including milliseconds

Parameters:
calendar - the calendar
Returns:
a string with can act as a filename prefix

filePrefixLong

public static java.lang.String filePrefixLong()


Copyright © 2010. All Rights Reserved.