diff --git a/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/common/Utils.java b/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/common/Utils.java index 2640c54bb..eff5b032c 100644 --- a/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/common/Utils.java +++ b/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/common/Utils.java @@ -11,10 +11,6 @@ import static org.hamcrest.Matchers.is; import static org.junit.Assert.assertThat; import static org.junit.Assert.fail; -import java.io.File; -import java.io.FileNotFoundException; -import java.io.FileOutputStream; -import java.io.IOException; import java.text.DateFormat; import java.text.ParseException; import java.text.SimpleDateFormat; @@ -27,7 +23,6 @@ import org.apache.commons.lang.StringUtils; import org.apache.http.conn.HttpHostConnectException; import org.joda.time.DateTimeZone; import org.joda.time.LocalDate; -import org.mifosplatform.infrastructure.core.service.DateUtils; import com.jayway.restassured.RestAssured; import com.jayway.restassured.path.json.JsonPath; diff --git a/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/core/service/DateUtils.java b/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/core/service/DateUtils.java index 86117c0b6..20004918d 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/core/service/DateUtils.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/core/service/DateUtils.java @@ -10,6 +10,7 @@ import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Date; import java.util.List; +import java.util.TimeZone; import org.joda.time.DateTime; import org.joda.time.DateTimeZone; @@ -23,6 +24,25 @@ import org.mifosplatform.infrastructure.core.exception.PlatformApiDataValidation public class DateUtils { + public static DateTimeZone getDateTimeZoneOfTenant() { + final MifosPlatformTenant tenant = ThreadLocalContextUtil.getTenant(); + DateTimeZone zone = null; + if (tenant != null) { + zone = DateTimeZone.forID(tenant.getTimezoneId()); + TimeZone.getTimeZone(tenant.getTimezoneId()); + } + return zone; + } + + public static TimeZone getTimeZoneOfTenant() { + final MifosPlatformTenant tenant = ThreadLocalContextUtil.getTenant(); + TimeZone zone = null; + if (tenant != null) { + zone = TimeZone.getTimeZone(tenant.getTimezoneId()); + } + return zone; + } + public static Date getDateOfTenant() { return getLocalDateOfTenant().toDateTimeAtStartOfDay().toDate(); } @@ -31,39 +51,31 @@ public class DateUtils { LocalDate today = new LocalDate(); - final MifosPlatformTenant tenant = ThreadLocalContextUtil.getTenant(); - - if (tenant != null) { - final DateTimeZone zone = DateTimeZone.forID(tenant.getTimezoneId()); - if (zone != null) { - today = new LocalDate(zone); - } + final DateTimeZone zone = getDateTimeZoneOfTenant(); + if (zone != null) { + today = new LocalDate(zone); } return today; } - + public static LocalDateTime getLocalDateTimeOfTenant() { - - LocalDateTime today = new LocalDateTime(); - - final MifosPlatformTenant tenant = ThreadLocalContextUtil.getTenant(); - - if (tenant != null) { - final DateTimeZone zone = DateTimeZone.forID(tenant.getTimezoneId()); - if (zone != null) { - today = new LocalDateTime(zone); - } - } - - return today; + + LocalDateTime today = new LocalDateTime(); + + final DateTimeZone zone = getDateTimeZoneOfTenant(); + if (zone != null) { + today = new LocalDateTime(zone); + } + + return today; } - public static LocalDate parseLocalDate(final String stringDate, final String pattern) { try { final DateTimeFormatter dateStringFormat = DateTimeFormat.forPattern(pattern); + dateStringFormat.withZone(getDateTimeZoneOfTenant()); final DateTime dateTime = dateStringFormat.parseDateTime(stringDate); return dateTime.toLocalDate(); } catch (final IllegalArgumentException e) { @@ -78,6 +90,7 @@ public class DateUtils { public static String formatToSqlDate(final Date date) { final DateFormat df = new SimpleDateFormat("yyyy-MM-dd"); + df.setTimeZone(getTimeZoneOfTenant()); final String formattedSqlDate = df.format(date); return formattedSqlDate; } diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/service/SavingsAccountWritePlatformServiceJpaRepositoryImpl.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/service/SavingsAccountWritePlatformServiceJpaRepositoryImpl.java index 04e2a5721..86a8a990a 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/service/SavingsAccountWritePlatformServiceJpaRepositoryImpl.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/service/SavingsAccountWritePlatformServiceJpaRepositoryImpl.java @@ -970,6 +970,7 @@ public class SavingsAccountWritePlatformServiceJpaRepositoryImpl implements Savi savingsAccountChargeId, accountId); final DateTimeFormatter fmt = DateTimeFormat.forPattern("dd MM yyyy"); + fmt.withZone(DateUtils.getDateTimeZoneOfTenant()); while (transactionDate.isAfter(savingsAccountCharge.getDueLocalDate()) && savingsAccountCharge.isNotFullyPaid()) { payCharge(savingsAccountCharge, transactionDate, savingsAccountCharge.amoutOutstanding(), fmt, user);