@@ -17,66 +17,66 @@ public class Dates extends MockUnitBase {
1717 * ahead of the start date
1818 * @param startDate start date
1919 * @param daysToAdd days to add to start date
20- * @param dateFormat date format (e.g. "dd/MM/yyyy")
20+ * @param dateFormat date format (e.g. "dd/MM/yyyy","dd/MM/yyyy HH:mm" )
2121 * @return String representing resulting date
2222 */
2323 public static String futureDate (String startDate , int daysToAdd , String dateFormat ) {
2424 DateTimeFormatter dateTimeFormatter = DateTimeFormat .forPattern (dateFormat );
25- LocalDate date = DateTime .parse (startDate , dateTimeFormatter ).plusDays (daysToAdd ).toLocalDate ();
26- return date .toString (dateTimeFormatter );
25+ DateTime dateTime = DateTime .parse (startDate , dateTimeFormatter ).plusDays (daysToAdd ).toDateTime ();
26+ return dateTime .toString (dateTimeFormatter );
2727 }
2828
2929 /**
3030 * Returns a string that represents the date that is the given days
3131 * behind of the start date
3232 * @param startDate start date
3333 * @param daysToRemove days to remove from start date
34- * @param dateFormat date format (e.g. "dd/MM/yyyy")
34+ * @param dateFormat date format (e.g. "dd/MM/yyyy","dd/MM/yyyy HH:mm" )
3535 * @return String representing resulting date
3636 */
3737 public static String pastDate (String startDate , int daysToRemove , String dateFormat ) {
3838 DateTimeFormatter dateTimeFormatter = DateTimeFormat .forPattern (dateFormat );
39- LocalDate date = DateTime .parse (startDate , dateTimeFormatter ).minusDays (daysToRemove ).toLocalDate ();
40- return date .toString (dateTimeFormatter );
39+ DateTime dateTime = DateTime .parse (startDate , dateTimeFormatter ).minusDays (daysToRemove ).toDateTime ();
40+ return dateTime .toString (dateTimeFormatter );
4141 }
4242
4343 /**
4444 * Returns the current date for today
45- * @param dateFormat date format (e.g. "dd/MM/yyyy")
45+ * @param dateFormat date format (e.g. "dd/MM/yyyy","dd/MM/yyyy HH:mm" )
4646 * @return String representing resulting date
4747 */
4848 public static String now (String dateFormat ) {
4949 DateTimeFormatter dateTimeFormatter = DateTimeFormat .forPattern (dateFormat );
50- LocalDate date = DateTime .now ().toLocalDate ();
51- return date .toString (dateTimeFormatter );
50+ DateTime dateTime = DateTime .now ().toDateTime ();
51+ return dateTime .toString (dateTimeFormatter );
5252 }
5353
5454 /**
5555 *
5656 * @param startDate the date to start with
5757 * @param numberOfBusinessDaysToAdd Days to add, avoiding weekends
58- * @param dateFormat date format (e.g. "dd/MM/yyyy")
58+ * @param dateFormat date format (e.g. "dd/MM/yyyy","dd/MM/yyyy HH:mm"" )
5959 * @return String representing resulting date
6060 */
6161 public static String futureDateAvoidingWeekends (String startDate , int numberOfBusinessDaysToAdd , String dateFormat ) {
6262 DateTimeFormatter dateTimeFormatter = DateTimeFormat .forPattern (dateFormat );
63- LocalDate futureDate = DateTime .parse (startDate , dateTimeFormatter ).toLocalDate ();
63+ DateTime futureDateTime = DateTime .parse (startDate , dateTimeFormatter ).toDateTime ();
6464 int addedDays = 0 ;
6565 while (addedDays < numberOfBusinessDaysToAdd ) {
66- futureDate = futureDate .plusDays (1 );
67- if (!((futureDate .getDayOfWeek () == 6 ) || (futureDate .getDayOfWeek () == 7 ))) {
66+ futureDateTime = futureDateTime .plusDays (1 );
67+ if (!((futureDateTime .getDayOfWeek () == 6 ) || (futureDateTime .getDayOfWeek () == 7 ))) {
6868 ++addedDays ;
6969 }
7070 }
71- return futureDate .toString (dateTimeFormatter );
71+ return futureDateTime .toString (dateTimeFormatter );
7272 }
7373
7474 /**
7575 *
7676 * @param locale the location for UK bank holidays (see @link Dates)
7777 * @param startDate the date to start with
7878 * @param numberOfBusinessDaysToAdd Days to add, avoiding weekends and UK bank holidays
79- * @param dateFormat date format (e.g. "dd/MM/yyyy")
79+ * @param dateFormat date format (e.g. "dd/MM/yyyy","dd/MM/yyyy HH:mm" )
8080 * @return String representing resulting date
8181 * @throws JsonProcessingException if the JSON source for bank holidays cannot be read
8282 */
@@ -86,19 +86,20 @@ public static String futureDataAvoidingWeekendsAndBankHolidays(
8686 BankHolidays bankHolidays = JsonUtils .fromString (
8787 get ("https://www.gov.uk/bank-holidays.json" ).body ().asString (), BankHolidays .class );
8888 DateTimeFormatter dateTimeFormatter = DateTimeFormat .forPattern (dateFormat );
89- LocalDate now = DateTime .parse (startDate , dateTimeFormatter ).toLocalDate ();
90- LocalDate futureDate = DateTime .parse (
89+ DateTime now = DateTime .parse (startDate , dateTimeFormatter ).toDateTime ();
90+ DateTime futureDateTime = DateTime .parse (
9191 futureDateAvoidingWeekends (
9292 startDate ,
9393 numberOfBusinessDaysToAdd ,
94- dateFormat ), dateTimeFormatter ).toLocalDate ();
94+ dateFormat ), dateTimeFormatter ).toDateTime ();
9595 int bankHolidayCount = 0 ;
9696 for (BankHoliday bankHoliday : bankHolidays .get (locale )) {
97- if (!bankHoliday .getLocalDate ().isBefore (now ) && !bankHoliday .getLocalDate ().isAfter (futureDate )) {
97+ if (!bankHoliday .getLocalDate ().isBefore (new LocalDate ( now )) && !bankHoliday .getLocalDate ().isAfter (new LocalDate ( futureDateTime ) )) {
9898 bankHolidayCount ++;
9999 }
100100 }
101- futureDate = futureDate .plusDays (bankHolidayCount );
102- return futureDate .toString (dateTimeFormatter );
101+ futureDateTime = futureDateTime .plusDays (bankHolidayCount );
102+ return futureDateTime .toString (dateTimeFormatter );
103103 }
104+
104105}
0 commit comments