nl.knowledgeplaza.util
Class CalendarUtil

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

public class CalendarUtil
extends Object

Quick format and quick parse (ISO) for Calendars

Version:
$Revision: 1.9 $
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 String SOURCECODE_VERSION
          Standard variable for determining version of a class file.
 
Constructor Summary
CalendarUtil()
           
 
Method Summary
static Calendar clearDate(Calendar c)
          Clear date (date becomes 1-1-1)
static Calendar clearTime(Calendar c)
          Clear time
static Calendar copyDate(Calendar from, Calendar to)
          copies the date fields from the first into the second parameter
static Calendar copyTime(Calendar from, Calendar to)
          copies the time fields from the first into the second parameter
static boolean dateAfter(Calendar c1, Calendar c2)
          does the date (ignoring time) fall after
static boolean dateAfterOrEqual(Calendar c1, Calendar c2)
          does the date (ignoring time) fall after or is equal to
static boolean dateBefore(Calendar c1, Calendar c2)
          does the date (ignoring time) fall before
static boolean dateBeforeOrEqual(Calendar c1, Calendar c2)
          does the date (ignoring time) fall before or is equal to
static long distanceInDays(Calendar c1, Calendar c2)
          Difference between two dates in days
static long distanceInMilliseconds(Calendar c1, Calendar c2)
          Difference between two dates in milliseconds
static String filePrefix()
           
static String filePrefix(Calendar calendar)
          create a date-time file prefix
static String filePrefixLong()
           
static String filePrefixLong(Calendar calendar)
          create a date-time file prefix including milliseconds
static String getDateSeparator()
          Return the date separator, e.g.
static String getDateSeparator(Locale locale)
          Return the date separator, e.g.
static long getJulianDay(Calendar c)
           
static long getUnixDay(Calendar c)
           
static Calendar gotoFirstDateOfHalfyear(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 Calendar gotoFirstDateOfLastFewMonths(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 Calendar gotoFirstDateOfMonth(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 Calendar gotoFirstDateOfQuarter(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 Calendar gotoFirstDateOfWeek(Calendar c)
          Move the provided calendar to the first date of the week.
static Calendar gotoFirstDateOfYear(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 Calendar gotoLastDateOfHalfyear(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 Calendar gotoLastDateOfLastFewMonths(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 Calendar gotoLastDateOfMonth(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 Calendar gotoLastDateOfQuarter(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 Calendar gotoLastDateOfWeek(Calendar c)
          Move the provided calendar to the last date of the week.
static Calendar gotoLastDateOfYear(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(Calendar c1, Calendar c2)
          See if two dates are on the same date (ignoring the time)
static boolean isSameMonth(Calendar c1, Calendar c2)
          See if two dates are on the same month (ignoring the time and day)
static boolean isSameTimeHMS(Calendar c1, Calendar c2)
          See if two dates are on the same time (ignoring the date and milliseconds)
static boolean isSameTimeHMSM(Calendar c1, Calendar c2)
          See if two dates are on the same time (ignoring the date, but including milliseconds)
static boolean isSameYear(Calendar c1, Calendar c2)
          See if two dates are in the same year (ignoring the time, day and month)
static String quickFormatCalendar(Calendar calendar)
          small utility method to format a calendar for logging according to YYYY-MM-DD [hh:mm:ss]
static String quickFormatCalendarDate(Calendar calendar)
          small utility method to format a calendar for logging according to YYYY-MM-DD
static String quickFormatCalendarDateTime(Calendar calendar)
          small utility method to format a calendar for logging according to YYYY-MM-DD hh:mm:ss
static String quickFormatCalendarTime(Calendar pCalendar)
          small utility method to format a calendar for logging according to hh:mm:ss
static GregorianCalendar quickParseGregorianCalendar(String value)
          small utility method to format a calendar for logging according to YYYY-MM-DD
static GregorianCalendar quickParseGregorianCalendarDate(String value)
          small utility method to format a calendar for logging according to YYYY-MM-DD
static GregorianCalendar quickParseGregorianCalendarFull(String value)
          small utility method to format a calendar for logging according to YYYY-MM-DD
static GregorianCalendar quickParseGregorianCalendarTime(String value)
          small utility method to format a calendar for logging according to YYYY-MM-DD
static Calendar setFromMilliseconds(Calendar calendar, long value)
          Set calendar from milliseconds
static Calendar setTimeToJustBeforeMidnight(Calendar c)
          23:59:59.999
static Calendar setTimeToMidnight(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 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 String quickFormatCalendar(Calendar calendar)
small utility method to format a calendar for logging according to YYYY-MM-DD [hh:mm:ss]

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

quickFormatCalendarDateTime

public static String quickFormatCalendarDateTime(Calendar calendar)
small utility method to format a calendar for logging according to YYYY-MM-DD hh:mm:ss

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

quickFormatCalendarDate

public static String quickFormatCalendarDate(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 String quickFormatCalendarTime(Calendar pCalendar)
small utility method to format a calendar for logging according to hh:mm:ss

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

quickParseGregorianCalendar

public static GregorianCalendar quickParseGregorianCalendar(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 GregorianCalendar quickParseGregorianCalendarFull(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 GregorianCalendar quickParseGregorianCalendarDate(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 GregorianCalendar quickParseGregorianCalendarTime(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 Calendar gotoFirstDateOfWeek(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 Calendar gotoLastDateOfWeek(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 Calendar gotoFirstDateOfMonth(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 Calendar gotoLastDateOfMonth(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 Calendar gotoFirstDateOfLastFewMonths(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 Calendar gotoLastDateOfLastFewMonths(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 Calendar gotoFirstDateOfQuarter(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 Calendar gotoLastDateOfQuarter(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 Calendar gotoFirstDateOfHalfyear(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 Calendar gotoLastDateOfHalfyear(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 Calendar gotoFirstDateOfYear(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 Calendar gotoLastDateOfYear(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 Calendar clearDate(Calendar c)
Clear date (date becomes 1-1-1)

Parameters:
c -

clearTime

public static Calendar clearTime(Calendar c)
Clear time

Parameters:
c -

setTimeToMidnight

public static Calendar setTimeToMidnight(Calendar c)
00:00:00.000

Parameters:
c -

setTimeToJustBeforeMidnight

public static Calendar setTimeToJustBeforeMidnight(Calendar c)
23:59:59.999

Parameters:
c -

copyDate

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

Parameters:
c -

copyTime

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

Parameters:
c -

isSameDate

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

Parameters:
c1 -
c2 -
Returns:

isSameMonth

public static boolean isSameMonth(Calendar c1,
                                  Calendar c2)
See if two dates are on the same month (ignoring the time and day)

Parameters:
c1 -
c2 -
Returns:

isSameYear

public static boolean isSameYear(Calendar c1,
                                 Calendar c2)
See if two dates are in the same year (ignoring the time, day and month)

Parameters:
c1 -
c2 -
Returns:

isSameTimeHMS

public static boolean isSameTimeHMS(Calendar c1,
                                    Calendar c2)
See if two dates are on the same time (ignoring the date and milliseconds)

Parameters:
c1 -
c2 -
Returns:

isSameTimeHMSM

public static boolean isSameTimeHMSM(Calendar c1,
                                     Calendar c2)
See if two dates are on the same time (ignoring the date, but including milliseconds)

Parameters:
c1 -
c2 -
Returns:

getDateSeparator

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

Returns:

getDateSeparator

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

Parameters:
locale -
Returns:

distanceInDays

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

Parameters:
c1 -
c2 -
Returns:

distanceInMilliseconds

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

Parameters:
c1 -
c2 -
Returns:

setFromMilliseconds

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

Parameters:
value -

getUnixDay

public static long getUnixDay(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(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 String filePrefix(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 String filePrefix()

filePrefixLong

public static String filePrefixLong(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 String filePrefixLong()

dateBefore

public static boolean dateBefore(Calendar c1,
                                 Calendar c2)
does the date (ignoring time) fall before


dateBeforeOrEqual

public static boolean dateBeforeOrEqual(Calendar c1,
                                        Calendar c2)
does the date (ignoring time) fall before or is equal to


dateAfter

public static boolean dateAfter(Calendar c1,
                                Calendar c2)
does the date (ignoring time) fall after


dateAfterOrEqual

public static boolean dateAfterOrEqual(Calendar c1,
                                       Calendar c2)
does the date (ignoring time) fall after or is equal to



Copyright © 2011 KnowledgePlaza. All Rights Reserved.