Fiscal-Year
Your company doesn’t work from January 1 to December 31? Try fiscal-year, a small Java library which converts calendar-year based dates to corresponding dates in a fiscal year.
Features
-
Immutable data structure
-
Convert from/to Java 8
LocalDate
-
Math operations like
plusDays
,minusWeeks
-
Factories to create/configure
Development Status
All currently required feature are implemented. This project is in maintenance mode.
Usage
First create a FiscalYearFactory
which holds the configuration of your company’s fiscal year:
// fiscal year starts at month 11 of the 'previous' year
FiscalYearFactory earlyYearFactory = FiscalYears.earlyFiscalYear(11);
// fiscal year starts at month 3 in the 'current' year
FiscalYearFactory lateYearFactory = FiscalYears.lateFiscalYear(3);
Then use this factory to convert a calendar-year based LocalDate
to a corresponding FiscalDate
:
LocalDate calendarDate = LocalDate.now();
FiscalDate fiscalDate = factory.createFromCalendarDate(calendarDate);
Use fiscal-year based values directly to create an instance of FiscalDate
:
FiscalDate fiscalDate = factory.create(2015, 3, 25);
Query the newly created FiscalDate
to retrieve the usual suspects of attributes:
int fiscalYear = fiscalDate.getFiscalYear();
int fiscalMonth = fiscalDate.getFiscalMonth();
int fiscalDayOfYear = fiscalDate.getFiscalDayOfYear();
int fiscalWeekOfWeekyear = fiscalDate.getFiscalWeekOfWeekyear();
int calendarYear = fiscalDate.getCalendarYear();
int calendarMonth = fiscalDate.getCalendarMonth();
int calendarDayOfMonth = fiscalDate.getCalendarDayOfMonth();
int calendarDayOfYear = fiscalDate.getCalendarDayOfYear();
int calendarWeekOfWeekyear = fiscalDate.getCalendarWeekOfWeekyear();
Do some math with dates as follows:
FiscalDate newDate = fiscalDate.plusYears(int years);
FiscalDate newDate = fiscalDate.plusMonths(int months);
FiscalDate newDate = fiscalDate.plusWeeks(int weeks);
FiscalDate newDate = fiscalDate.plusDays(int days);
FiscalDate newDate = fiscalDate.minusYears(int years);
FiscalDate newDate = fiscalDate.minusMonths(int months);
FiscalDate newDate = fiscalDate.minusWeeks(int weeks);
FiscalDate newDate = fiscalDate.minusDays(int days);
Or finally convert it back to a LocalDate
:
LocalDate calendarDate = fiscalDate.asLocalDate();
Integration
To use this project just declare the following dependency inside your POM:
<dependency>
<groupId>de.xn--ho-hia.utils.fiscal_year</groupId>
<artifactId>fiscal-year</artifactId>
<version>${version.fiscal-year}</version>
</dependency>
Replace ${version.fiscal-year}
with the latest release. This project follows the semantic versioning guidelines.
Compatibility
This project is compatible with the following Java versions:
1.X.Y | 2.X.Y | 3.X.Y | |
---|---|---|---|
Java 8 |
✓ |
✓ |
✓ |
License
To the extent possible under law, the author(s) have dedicated all copyright and related and neighboring rights to this software to the public domain worldwide. This software is distributed without any warranty.
You should have received a copy of the CC0 Public Domain Dedication along with this software. If not, see http://creativecommons.org/publicdomain/zero/1.0/.