---
title: "Implementing a Custom Date Period"
canonical: "https://wiki.yellowfinbi.com/space/yfcurrent/2195780/Implementing%20a%20Custom%20Date%20Period"
format: markdown
---
A custom date period is an extension of the class com.hof.mi.interfaces.CustomDatePeriod. The following functions must be implemented in this class:

- public abstract String getName();
- public abstract String getUniqueID();
- public abstract FilterUnit getUnit();
- public abstract DatePeriodType getDatePeriodType();
- public abstract List<CalendarCommand> getLeftPredicate();
- public abstract List<CalendarCommand> getRightPredicate();

## Function Definitions

#### public abstract String getName();

This method returns the display name of your custom date period. This value will be what users see in Yellowfin.

```
@Override
public String getName() {
    return "My custom date period";
}
```

#### public abstract String getUniqueID();

This method returns the unique ID for Yellowfin to define your custom date period. The unique ID must only have upper case letters.

```
@Override
public String getUniqueID() {
    return "MY_CUSTOM_DATE";
}
```

#### public abstract FilterUnit getFilterUnit();

This method returns which time period the custom date filter is linked to.  
The possible values can be selected from the FilterUnit enumeration:

```
public enum FilterUnit {
    SECONDS, MINUTES, HOURS, DAY, WEEK, MONTH, QUARTER, YEAR
}
```

```
@Override
public FilterUnit getUnit() {
    return FilterUnit.DAY;
}
```

#### public abstract DatePeriodType getDatePeriodType();

This method returns a DatePeriodType enum value and tells Yellowfin what type of comparison filter is being applied.  
The values are defined in the DatePeriod class.

```
public enum DatePeriodType {
    PREDEF_SINGLE_DATES, PREDEF_BETWEEN_DATES, PREDEF_BETWEEN_TIMES
}
```

The most common comparison filter is to use predefBetweenDates.

```
@Override
public DatePeriodType getDatePeriodType() {
	return DatePeriodType.PREDEF_BETWEEN_DATES;
}
```

#### public abstract List<CalendarCommand> getLeftPredicate();

This method returns a List of CalendarCommand classes that define the minimum date/time for the filter. To create a calendar command, please use the buildCommand() method as well as view the helper functions below.

```
@Override
public List<CalendarCommand> getLeftPredicate() {
    List<CalendarCommand> left = getBeginningOfToday();
    left.add(buildCommand(CalendarCommand.CmdType.ADD_AMOUNT, Calendar.YEAR, -10));
    return left;
}
```

To learn how to use Calendar Commands, please refer to [this](https://docs.oracle.com/javase/8/docs/api/java/util/Calendar.html) guide.

#### public abstract List<CalendarCommand> getRightPredicate();

This method returns a List of CalendarCommand classes that define the date/time for the filter. To create a calendar command, please use the buildCommand() method as well as view the helper functions below.

```
@Override
public List<CalendarCommand> getRightPredicate() {
    List<CalendarCommand> right = getEndOfToday();
    return right;
}
```

To learn how to use Calendar Commands, please refer to [this](https://docs.oracle.com/javase/8/docs/api/java/util/Calendar.html) guide.

## Helper Functions

#### public final List<CalendarCommand> getBeginningOfToday();

This method returns a List of CalendarCommands which map to the beginning of today’s date.

```
List<CalendarCommand> startOfToday = getBeginningOfToday();
```

#### public final List<CalendarCommand> getEndOfToday();

This method returns a List of CalendarCommands which map to the end of today’s date.

```
List<CalendarCommand> endOfToday = getEndOfToday();
```

#### public final CalendarCommand buildCommand(CalendarCommand.CmdType valType, int calendarField);

#### public final CalendarCommand buildCommand(CalendarCommand.CmdType valType, int calendarField, Integer amount);

This method returns a CalendarCommand object which adds a calculation to a predicate. This function is primarily used to calculate new values for the left and right predicate.

Parameters:

- **CalendarCommand.CmdType valType**: This value represents an enum value CmdType which tells Yellowfin which specific calculation type to use.

 The possible CmdTypes are listed below:

```
public enum CmdType
{
    ADD_MIN, ADD_MAX, ADD_AMOUNT, SET_MIN, SET_MAX, SET_AMOUNT, 
    SET_QUARTER_START, SET_QUARTER_END,
    SET_FIN_QUARTER_START, SET_FIN_QUARTER_END,
    SET_FIN_YEAR_START, SET_FIN_YEAR_END,
    SET_WEEK_START, SET_WEEK_END,
}
```

- **int calendarField**: This value represents one of the integer values corresponding to Java’s calendar class [(java.util.Calendar)](https://docs.oracle.com/javase/8/docs/api/java/util/Calendar.html) and tells yellowfin which date/time value to use in the calculation.

*Note: The valTypes SET_QUARTER_START, SET_QUARTER_END, SET_FIN_QUARTER_START, SET_FIN_QUARTER_END, SET_FIN_YEAR_START, SET_FIN_YEAR_END, SET_WEEK_START and SET_WEEK_END do not require a specific calendarField. Any value may be entered instead.*

- **Integer amount** (optional): This is required when using ADD_AMOUNT or SET_AMOUNT as the valtype. This value defines the amount to add or set.

```
ArrayList<CalendarCommand> commands = new ArrayList<>();
commands.add(buildCommand(CalendarCommand.CmdType.ADD_AMOUNT, Calendar.YEAR, -10));
commands.add(buildCommand(CalendarCommand.CmdType.SET_MIN, Calendar.MONTH));
```