Top Description Fields Constructors Methods
org.apache.poi.ss.formula.atp

public Class WorkdayCalculator

extends Object
Class Inheritance
Imports
java.util.Arrays, .Calendar, .Collections, .Date, .HashMap, .HashSet, .Map, .Set, org.apache.poi.ss.usermodel.DateUtil, org.apache.poi.util.LocaleUtil

A calculator for workdays, considering dates as excel representations.

Field Summary

Modifier and TypeField and Description
private static final Set<Integer>
private static final Set<Integer>
public static final WorkdayCalculator
private static final Set<Integer>
private static final Set<Integer>
private static final Set<Integer>
private static final Set<Integer>
private static final Set<Integer>
private static final Set<Integer>
private static final Set<Integer>
private static final Set<Integer>
private static final Set<Integer>
private static final Set<Integer>
private static final Set<Integer>
private static final Set<Integer>
private static final Map<Integer, Set<Integer>>

Constructor Summary

AccessConstructor and Description
private
WorkdayCalculator()

Constructor.

Method Summary

Modifier and TypeMethod and Description
protected int

Returns:

number of holidays that occur in workdays, between start and end dates.
calculateNonWeekendHolidays
(double
start date.
start
,
double
end date.
end
,
double[]
an array of holidays.
holidays
)

Calculates how many holidays in a list are workdays, considering an interval of dates.

public int

Returns:

number of workdays between start and end dates, including both dates.
calculateWorkdays
(double
start date.
start
,
double
end date.
end
,
double[]
an array of holidays.
holidays
)

Calculate how many workdays are there between a start and an end date, as excel representations, considering a range of holidays.

public Date

Returns:

date past x workdays.
calculateWorkdays
(double
start date.
start
,
int
number of workdays to be past from starting date.
workdays
,
double[]
an array of holidays.
holidays
)

Calculate the workday past x workdays from a starting date, considering a range of holidays.

public Date

Returns:

date past x workdays.
calculateWorkdays
(double
start date.
start
,
int
number of workdays to be past from starting date.
workdays
,
int
weekend parameter (see https://support.microsoft.com/en-us/office/workday-intl-function-a378391c-9ba7-4678-8a39-39611a9bf81d)
weekendType
,
double[]
an array of holidays.
holidays
)

Calculate the workday past x workdays from a starting date, considering a range of holidays.

public Set<Integer>
protected boolean

Returns:

true if date is a holiday, false otherwise.
isHoliday
(double
a given date.
aDate
,
double[]
an array of holidays.
holidays
)

protected boolean

Returns:

true if aDate is between start and end dates, false otherwise.
isInARange
(double
start date.
start
,
double
end date.
end
,
double
a date to be analyzed.
aDate
)

protected boolean

Returns:

true if date is weekend, false otherwise.
isWeekend
(double
a given date.
aDate
)

private boolean
private boolean
isWeekend(Calendar date, Set<Integer> weekendDays)

protected int

Returns:

how many days of week past in this interval.
pastDaysOfWeek
(double
start date.
start
,
double
end date.
end
,
int
a day of week as represented by Calendar constants.
dayOfWeek
)

Calculates how many days of week past between a start and an end date.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

friSatWeekendback to summary
private static final Set<Integer> friSatWeekend
friWeekendback to summary
private static final Set<Integer> friWeekend
instanceback to summary
public static final WorkdayCalculator instance
monTuesWeekendback to summary
private static final Set<Integer> monTuesWeekend
monWeekendback to summary
private static final Set<Integer> monWeekend
satWeekendback to summary
private static final Set<Integer> satWeekend
standardWeekendback to summary
private static final Set<Integer> standardWeekend
sunMonWeekendback to summary
private static final Set<Integer> sunMonWeekend
sunWeekendback to summary
private static final Set<Integer> sunWeekend
thursFriWeekendback to summary
private static final Set<Integer> thursFriWeekend
thursWeekendback to summary
private static final Set<Integer> thursWeekend
tuesWedsWeekendback to summary
private static final Set<Integer> tuesWedsWeekend
tuesWeekendback to summary
private static final Set<Integer> tuesWeekend
wedsThursWeekendback to summary
private static final Set<Integer> wedsThursWeekend
wedsWeekendback to summary
private static final Set<Integer> wedsWeekend
weekendTypeMapback to summary
private static final Map<Integer, Set<Integer>> weekendTypeMap

Constructor Detail

WorkdayCalculatorback to summary
private WorkdayCalculator()

Constructor.

Method Detail

calculateNonWeekendHolidaysback to summary
protected int calculateNonWeekendHolidays(double start, double end, double[] holidays)

Calculates how many holidays in a list are workdays, considering an interval of dates.

Parameters
start:double

start date.

end:double

end date.

holidays:double[]

an array of holidays.

Returns:int

number of holidays that occur in workdays, between start and end dates.

calculateWorkdaysback to summary
public int calculateWorkdays(double start, double end, double[] holidays)

Calculate how many workdays are there between a start and an end date, as excel representations, considering a range of holidays.

Parameters
start:double

start date.

end:double

end date.

holidays:double[]

an array of holidays.

Returns:int

number of workdays between start and end dates, including both dates.

calculateWorkdaysback to summary
public Date calculateWorkdays(double start, int workdays, double[] holidays)

Calculate the workday past x workdays from a starting date, considering a range of holidays. Uses Sat/Sun weekend.

Parameters
start:double

start date.

workdays:int

number of workdays to be past from starting date.

holidays:double[]

an array of holidays.

Returns:Date

date past x workdays.

calculateWorkdaysback to summary
public Date calculateWorkdays(double start, int workdays, int weekendType, double[] holidays)

Calculate the workday past x workdays from a starting date, considering a range of holidays.

Parameters
start:double

start date.

workdays:int

number of workdays to be past from starting date.

weekendType:int

weekend parameter (see https://support.microsoft.com/en-us/office/workday-intl-function-a378391c-9ba7-4678-8a39-39611a9bf81d)

holidays:double[]

an array of holidays.

Returns:Date

date past x workdays.

getValidWeekendTypesback to summary
public Set<Integer> getValidWeekendTypes()
isHolidayback to summary
protected boolean isHoliday(double aDate, double[] holidays)
Parameters
aDate:double

a given date.

holidays:double[]

an array of holidays.

Returns:boolean

true if date is a holiday, false otherwise.

isInARangeback to summary
protected boolean isInARange(double start, double end, double aDate)
Parameters
start:double

start date.

end:double

end date.

aDate:double

a date to be analyzed.

Returns:boolean

true if aDate is between start and end dates, false otherwise.

isWeekendback to summary
protected boolean isWeekend(double aDate)
Parameters
aDate:double

a given date.

Returns:boolean

true if date is weekend, false otherwise.

isWeekendback to summary
private boolean isWeekend(Calendar date)
isWeekendback to summary
private boolean isWeekend(Calendar date, Set<Integer> weekendDays)
pastDaysOfWeekback to summary
protected int pastDaysOfWeek(double start, double end, int dayOfWeek)

Calculates how many days of week past between a start and an end date.

Parameters
start:double

start date.

end:double

end date.

dayOfWeek:int

a day of week as represented by Calendar constants.

Returns:int

how many days of week past in this interval.