File tree Expand file tree Collapse file tree 2 files changed +25
-2
lines changed
main/java/uk/co/evoco/webdriver/utils/data
test/java/uk/co/evoco/webdriver/utils/data Expand file tree Collapse file tree 2 files changed +25
-2
lines changed Original file line number Diff line number Diff line change @@ -45,4 +45,23 @@ public static String now() {
4545 LocalDate date = DateTime .now ().toLocalDate ();
4646 return date .toString (dateTimeFormatter );
4747 }
48+
49+ /**
50+ *
51+ * @param startDate the date to start with
52+ * @param numberOfBusinessDaysToAdd Days to add, avoiding weekends
53+ * @return String representing resulting date
54+ */
55+ public static String futureDateBusinessDays (String startDate , int numberOfBusinessDaysToAdd ) {
56+ DateTimeFormatter dateTimeFormatter = DateTimeFormat .forPattern (DATE_FORMAT );
57+ LocalDate futureDate = DateTime .parse (startDate , dateTimeFormatter ).toLocalDate ();
58+ int addedDays = 0 ;
59+ while (addedDays < numberOfBusinessDaysToAdd ) {
60+ futureDate = futureDate .plusDays (1 );
61+ if (!((futureDate .getDayOfWeek () == 6 ) || (futureDate .getDayOfWeek () == 7 ))) {
62+ ++addedDays ;
63+ }
64+ }
65+ return futureDate .toString (dateTimeFormatter );
66+ }
4867}
Original file line number Diff line number Diff line change 44
55import static org .hamcrest .CoreMatchers .is ;
66import static org .hamcrest .MatcherAssert .assertThat ;
7- import static uk .co .evoco .webdriver .utils .data .Dates .futureDate ;
8- import static uk .co .evoco .webdriver .utils .data .Dates .pastDate ;
7+ import static uk .co .evoco .webdriver .utils .data .Dates .*;
98
109public class DatesTests {
1110
@@ -18,4 +17,9 @@ public void testCanGetDateInFuture() {
1817 public void testCanGetDateInPast () {
1918 assertThat (pastDate ("06/06/2019" , 5 ), is ("01/06/2019" ));
2019 }
20+
21+ @ Test
22+ public void testCanDataInFutureAvoidingWeekend () {
23+ assertThat (futureDateBusinessDays ("06/06/2019" , 5 ), is ("13/06/2019" ));
24+ }
2125}
You can’t perform that action at this time.
0 commit comments