diff --git a/invoice/src/main/java/com/ning/billing/invoice/generator/InvoiceDateUtils.java b/invoice/src/main/java/com/ning/billing/invoice/generator/InvoiceDateUtils.java
index a2f255f..f35d53e 100644
--- a/invoice/src/main/java/com/ning/billing/invoice/generator/InvoiceDateUtils.java
+++ b/invoice/src/main/java/com/ning/billing/invoice/generator/InvoiceDateUtils.java
@@ -137,7 +137,7 @@ public class InvoiceDateUtils {
public static LocalDate calculateBillingCycleDateOnOrAfter(final LocalDate date, final DateTimeZone accountTimeZone,
final int billingCycleDayLocal) {
- final DateTime tmp = new DateTime(date.toDateTimeAtStartOfDay(), accountTimeZone);
+ final DateTime tmp = date.toDateTimeAtStartOfDay(accountTimeZone);
final DateTime proposedDateTime = calculateBillingCycleDateOnOrAfter(tmp, billingCycleDayLocal);
return new LocalDate(proposedDateTime, accountTimeZone);
@@ -145,7 +145,7 @@ public class InvoiceDateUtils {
public static LocalDate calculateBillingCycleDateAfter(final LocalDate date, final DateTimeZone accountTimeZone,
final int billingCycleDayLocal) {
- final DateTime tmp = new DateTime(date.toDateTimeAtStartOfDay(), accountTimeZone);
+ final DateTime tmp = date.toDateTimeAtStartOfDay(accountTimeZone);
final DateTime proposedDateTime = calculateBillingCycleDateAfter(tmp, billingCycleDayLocal);
return new LocalDate(proposedDateTime, accountTimeZone);
diff --git a/invoice/src/test/java/com/ning/billing/invoice/generator/TestInvoiceDateUtils.java b/invoice/src/test/java/com/ning/billing/invoice/generator/TestInvoiceDateUtils.java
index e9d3f46..a496d14 100644
--- a/invoice/src/test/java/com/ning/billing/invoice/generator/TestInvoiceDateUtils.java
+++ b/invoice/src/test/java/com/ning/billing/invoice/generator/TestInvoiceDateUtils.java
@@ -28,6 +28,21 @@ import com.ning.billing.catalog.api.BillingPeriod;
public class TestInvoiceDateUtils {
@Test(groups = "fast")
+ public void testLastBCDShouldBeInThePast() throws Exception {
+ final LocalDate from = new LocalDate("2012-07-16");
+ final LocalDate previousBCD = new LocalDate("2012-08-15");
+ final int bcdLocal = 15;
+ final LocalDate lastBCD = InvoiceDateUtils.calculateLastBillingCycleDateBefore(from, previousBCD, bcdLocal, BillingPeriod.MONTHLY);
+ Assert.assertEquals(lastBCD, new LocalDate("2012-07-15"));
+ }
+ @Test(groups = "fast")
+ public void testNextBCDShouldNotBeInThePast() throws Exception {
+ final LocalDate from = new LocalDate("2012-07-16");
+ final LocalDate to = InvoiceDateUtils.calculateBillingCycleDateOnOrAfter(from, DateTimeZone.forID("Pacific/Pitcairn"), 15);
+ Assert.assertEquals(to, new LocalDate("2012-08-15"));
+ }
+
+ @Test(groups = "fast")
public void testProRationAfterLastBillingCycleDate() throws Exception {
final LocalDate endDate = new LocalDate("2012-06-02");
final LocalDate previousBillThroughDate = new LocalDate("2012-03-02");
diff --git a/invoice/src/test/java/com/ning/billing/invoice/model/TestInAdvanceBillingMode.java b/invoice/src/test/java/com/ning/billing/invoice/model/TestInAdvanceBillingMode.java
index 7811ec5..10ded27 100644
--- a/invoice/src/test/java/com/ning/billing/invoice/model/TestInAdvanceBillingMode.java
+++ b/invoice/src/test/java/com/ning/billing/invoice/model/TestInAdvanceBillingMode.java
@@ -20,6 +20,7 @@ import java.math.BigDecimal;
import java.util.LinkedHashMap;
import java.util.List;
+import org.joda.time.DateTime;
import org.joda.time.DateTimeZone;
import org.joda.time.LocalDate;
import org.testng.Assert;
@@ -33,6 +34,32 @@ public class TestInAdvanceBillingMode {
public static final BillingPeriod BILLING_PERIOD = BillingPeriod.MONTHLY;
@Test(groups = "fast")
+ public void testItemShouldNotStartInThePast() throws Exception {
+ final LocalDate startDate = new LocalDate(2012, 7, 16);
+ final LocalDate endDate = new LocalDate(2012, 7, 16);
+ final LocalDate targetDate = new LocalDate(2012, 7, 16);
+ final int billingCycleDayLocal = 15;
+
+ final LinkedHashMap<LocalDate, LocalDate> expectedDates = new LinkedHashMap<LocalDate, LocalDate>();
+ expectedDates.put(new LocalDate(2012, 7, 16), new LocalDate(2012, 8, 15));
+
+ verifyInvoiceItems(startDate, endDate, targetDate, TIMEZONE, billingCycleDayLocal, BILLING_PERIOD, expectedDates);
+ }
+
+ @Test(groups = "fast")
+ public void testCalculateSimpleInvoiceItemWithNoEndDate() throws Exception {
+ final LocalDate startDate = new LocalDate(new DateTime("2012-07-17T02:25:33.000Z", DateTimeZone.UTC), TIMEZONE);
+ final LocalDate endDate = null;
+ final LocalDate targetDate = new LocalDate(2012, 7, 16);
+ final int billingCycleDayLocal = 15;
+
+ final LinkedHashMap<LocalDate, LocalDate> expectedDates = new LinkedHashMap<LocalDate, LocalDate>();
+ expectedDates.put(new LocalDate(2012, 7, 16), new LocalDate(2012, 8, 15));
+
+ verifyInvoiceItems(startDate, endDate, targetDate, TIMEZONE, billingCycleDayLocal, BILLING_PERIOD, expectedDates);
+ }
+
+ @Test(groups = "fast")
public void testCalculateSimpleInvoiceItemWithBCDBeforeStartDay() throws Exception {
final LocalDate startDate = new LocalDate(2012, 7, 16);
final LocalDate endDate = new LocalDate(2012, 8, 16);