Holger's Java API

## com.antelmann.calendar
Class CalendarHelper

    java.lang.Object
      com.antelmann.calendar.CalendarHelper

All Implemented Interfaces:
  Serializable

    public final class CalendarHelper

extends Object
implements Serializable

methods that require a calendar for calculation are synchronized, so they do not perform simultaneously

Author:
  Holger Antelmann
See Also:
  Serialized Form

Field Summary
`static SimpleDateFormat` `IETF_DATE_FORMAT` the IETF date format is used in HTTP headers for displaying the date.

Constructor Summary
`CalendarHelper()`
`CalendarHelper(Calendar calendar)`

Method Summary
`Date` `addDays(Date date, int n)`
`int` `age(Date birthday)`
`static Comparator<Date>` `createBirthdayComparator()` returns a newly created comparator that will compare the dates by ignoring the year
`Date` `dayBegin(Date d)` returns a date that is set to the begin of the given day (daytime 12:00 a.m.)
`Date` `dayEnd(Date d)`
`int` `dayInMonth(Date d)`
`int` `dayOfWeek(Date date)`
`int` `daysBetween(Date a, Date b)` based on 24h difference adjusted by daylight savings time
`int` `daysInMonth(Date d)`
`int` `differenceInDays(Date a, Date b)` based on the date rather than the exact time in between
`int` `getBusinessYear(Date date, int monthOfYearBegin)`
`int` `getBusinessYear(Date date, Month monthOfYearBegin)`
`Calendar` `getCalendar()` returns the currently used Calendar instance
`Date` `getDateForYear(int year)`
`int` `getYear(Date date)`
`boolean` `isAnniversary(Date anniversary, Date referenceDate)`
`boolean` `isLastDayInMonth(Date d)`
`boolean` `isWeekend(Date date)`
`int` `month(Date d)`
`Date` `monthBegin(Date d)`
`Date` `monthEnd(Date d)`
`Date` `nextDay(Date d)` returns a date that is exactly a day later
`Date` `nextMonth(Date d)` returns a date that is exactly a month later
`Date` `nextQuarter(Date d)` returns a date that is exactly 3 months later
`Date` `nextWeek(Date d)` returns a date that is exactly a week later
`Date` `nextYear(Date d)` returns a date that is exactly a year later
`int` `offset(Date date)` returns the offset that must be adjusted due to timezone specific daylight saving times
`Date` `previousDay(Date d)`
`Date` `previousMonth(Date d)`
`Date` `previousQuarter(Date d)`
`Date` `previousWeek(Date d)`
`Date` `previousYear(Date d)`
`Date` `quarterBegin(Date d)`
`boolean` `sameDay(Date d1, Date d2)` returns true only if the two dates are within the same day given the default time zone
`boolean` `sameDayOfWeek(Date d1, Date d2)`
`boolean` `sameMonth(Date d1, Date d2)`
`boolean` `sameWeek(Date d1, Date d2)`
`boolean` `sameYear(Date d1, Date d2)`
`void` `setCalendar(Calendar calendar)` by default, the standard GregorianCalendar is used
`int` `timeInDay(Date date)` returns milliseconds from the beginning of the day
`Date` `weekBegin(Date d)` week begins Monday here
`int` `weekInMonth(Date d)`
`int` `weekInYear(Date d)`
`int` `y2k(int twoDigitYear)` returns an educated guess for the actual year that was meant
`Date` `yearBegin(Date d)`
`Date` `yearEnd(Date d)`
`Date` `yearToDate(int year)`
`long` `zoneDiff(TimeZone tz, long timeInMillis)` returns the difference in times from the currently used calendar to the given zone at the specified point in time

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Field Detail

### IETF_DATE_FORMAT

    public static final SimpleDateFormat IETF_DATE_FORMAT

  the IETF date format is used in HTTP headers for displaying the date. Since Java deprecated `java.util.Date.parse(String)`, this offers an easy way to make the IETF date format work in any non-deprecated API.

Constructor Detail

### CalendarHelper

    public CalendarHelper()

### CalendarHelper

    public CalendarHelper(Calendar calendar)

Method Detail

### getCalendar

    public Calendar getCalendar()

  returns the currently used Calendar instance

### setCalendar

    public void setCalendar(Calendar calendar)

  by default, the standard GregorianCalendar is used

### getYear

    public int getYear(Date date)

### getBusinessYear

    public int getBusinessYear(Date date,
                               Month monthOfYearBegin)

### getBusinessYear

    public int getBusinessYear(Date date,
                               int monthOfYearBegin)

### isWeekend

    public boolean isWeekend(Date date)

### dayOfWeek

    public int dayOfWeek(Date date)

  See Also:
    `Calendar.DAY_OF_WEEK`

### timeInDay

    public int timeInDay(Date date)

  returns milliseconds from the beginning of the day

  See Also:
    `TimeInDay`

### zoneDiff

    public long zoneDiff(TimeZone tz,
                         long timeInMillis)

  returns the difference in times from the currently used calendar to the given zone at the specified point in time

### offset

    public int offset(Date date)

  returns the offset that must be adjusted due to timezone specific daylight saving times

### isAnniversary

    public boolean isAnniversary(Date anniversary,
                                 Date referenceDate)

### sameDay

    public boolean sameDay(Date d1,
                           Date d2)

  returns true only if the two dates are within the same day given the default time zone

### sameDayOfWeek

    public boolean sameDayOfWeek(Date d1,
                                 Date d2)

### sameYear

    public boolean sameYear(Date d1,
                            Date d2)

### sameWeek

    public boolean sameWeek(Date d1,
                            Date d2)

### sameMonth

    public boolean sameMonth(Date d1,
                             Date d2)

### dayEnd

    public Date dayEnd(Date d)

### dayBegin

    public Date dayBegin(Date d)

  returns a date that is set to the begin of the given day (daytime 12:00 a.m.)

### weekBegin

    public Date weekBegin(Date d)

  week begins Monday here

### monthBegin

    public Date monthBegin(Date d)

### monthEnd

    public Date monthEnd(Date d)

### quarterBegin

    public Date quarterBegin(Date d)

### yearBegin

    public Date yearBegin(Date d)

### yearEnd

    public Date yearEnd(Date d)

### yearToDate

    public Date yearToDate(int year)

### nextDay

    public Date nextDay(Date d)

  returns a date that is exactly a day later

### addDays

    public Date addDays(Date date,
                        int n)

### nextWeek

    public Date nextWeek(Date d)

  returns a date that is exactly a week later

### nextMonth

    public Date nextMonth(Date d)

  returns a date that is exactly a month later

### nextQuarter

    public Date nextQuarter(Date d)

  returns a date that is exactly 3 months later

### nextYear

    public Date nextYear(Date d)

  returns a date that is exactly a year later

### previousDay

    public Date previousDay(Date d)

### previousMonth

    public Date previousMonth(Date d)

### previousQuarter

    public Date previousQuarter(Date d)

### previousYear

    public Date previousYear(Date d)

### previousWeek

    public Date previousWeek(Date d)

### weekInYear

    public int weekInYear(Date d)

### weekInMonth

    public int weekInMonth(Date d)

### dayInMonth

    public int dayInMonth(Date d)

### daysInMonth

    public int daysInMonth(Date d)

### month

    public int month(Date d)

### isLastDayInMonth

    public boolean isLastDayInMonth(Date d)

### age

    public int age(Date birthday)

### createBirthdayComparator

    public static Comparator<Date> createBirthdayComparator()

  returns a newly created comparator that will compare the dates by ignoring the year

### daysBetween

    public int daysBetween(Date a,
                           Date b)

  based on 24h difference adjusted by daylight savings time

### differenceInDays

    public int differenceInDays(Date a,
                                Date b)

  based on the date rather than the exact time in between

### getDateForYear

    public Date getDateForYear(int year)

### y2k

    public int y2k(int twoDigitYear)

  returns an educated guess for the actual year that was meant

(c) Holger Antelmann since 2001- all rights reserved (contact: info@antelmann.com)
see www.antelmann.com/developer for further details and available downloads