Use latest parent
[fiscal-year.java.git] / README.textile
blob64ad30479d38a9e23d329164379a5d984cf38eb2
1 h1. Fiscal-Year "!https://secure.travis-ci.org/sebhoss/fiscal-year.png!":http://travis-ci.org/sebhoss/fiscal-year "!https://www.ohloh.net/p/fiscal-year/widgets/project_thin_badge.gif!":https://www.ohloh.net/p/fiscal-year/
3 p. 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":http://en.wikipedia.org/wiki/Fiscal_year.
5 h2. Usage
7 p. First create a @FiscalYearFactory@ which holds the configuration of your company's fiscal year:
9 bc. // fiscal year starts at month 11 of the 'previous' year
10 FiscalYearFactory earlyYearFactory = FiscalYears.earlyFiscalYear(11);
11 // fiscal year starts at month 3 in the 'current' year
12 FiscalYearFactory lateYearFactory = FiscalYears.lateFiscalYear(3);
14 p. Then use this factory to convert a calendar-year based @LocalDate@ to a corresponding @FiscalDate@:
16 bc. LocalDate calendarDate = LocalDate.now();
17 FiscalDate fiscalDate = factory.createFromCalendarDate(calendarDate);
19 p. Use fiscal-year based values directly to create an instance of @FiscalDate@:
21 bc. FiscalDate fiscalDate = factory.create(2015, 3, 25);
23 p. Query the newly created @FiscalDate@ to retrieve the usual suspects of attributes:
25 bc.. int fiscalYear = fiscalDate.getFiscalYear();
26 int fiscalMonth = fiscalDate.getFiscalMonth();
27 int fiscalDayOfYear = fiscalDate.getFiscalDayOfYear();
28 int fiscalWeekOfWeekyear = fiscalDate.getFiscalWeekOfWeekyear();
30 int calendarYear = fiscalDate.getCalendarYear();
31 int calendarMonth = fiscalDate.getCalendarMonth();
32 int calendarDayOfMonth = fiscalDate.getCalendarDayOfMonth();
33 int calendarDayOfYear = fiscalDate.getCalendarDayOfYear();
34 int calendarWeekOfWeekyear = fiscalDate.getCalendarWeekOfWeekyear();
36 p. Do some math with dates as follows:
38 bc. FiscalDate newDate = fiscalDate.plusYears(int years);
39 FiscalDate newDate = fiscalDate.plusMonths(int months);
40 FiscalDate newDate = fiscalDate.plusWeeks(int weeks);
41 FiscalDate newDate = fiscalDate.plusDays(int days);
42 FiscalDate newDate = fiscalDate.minusYears(int years);
43 FiscalDate newDate = fiscalDate.minusMonths(int months);
44 FiscalDate newDate = fiscalDate.minusWeeks(int weeks);
45 FiscalDate newDate = fiscalDate.minusDays(int days);
46     
47 p. Or finally convert it back to a @LocalDate@:
49 bc. LocalDate calendarDate = fiscalDate.asLocalDate();
51 p. All classes are immutable and therefore thread-safe. The library currently relies on "Joda Time":http://joda-time.sourceforge.net/ but will be updated to use the new "JSR 310":http://jcp.org/en/jsr/detail?id=310 based Date API once it is released. 
53 h2. Integration
55 bc. 
56 <dependency>
57   <groupId>com.github.sebhoss</groupId>
58   <artifactId>fiscal-year</artifactId>
59   <version>[1.0.0,2.0.0)</version>
60 </dependency>
63 h2. Development
65 h3. License
67 p. This program is free software. It comes without any warranty, to the extent permitted by applicable law. You can redistribute it and/or modify it under the terms of the Do What The Fuck You Want To Public License, Version 2, as published by Sam Hocevar. See LICENSE or "http://www.wtfpl.net/":http://www.wtfpl.net/ for more details.
69 h3. Setup
71 p. This projects uses "Java":http://www.java.com/, "Maven":http://maven.apache.org/ and "Git":http://git-scm.com/ as the main development tools. To build the project yourself just download & install at least Maven 3.0 and call *mvn install* inside the project folder. Maven should then proceed to clean, build, package and install this project.
73 h3. Versioning
75 p. This project follows the "semantic versioning":http://semver.org/ guidelines.