some timezone related fixes
This commit is contained in:
-5
@@ -11,10 +11,6 @@ import static org.hamcrest.Matchers.is;
|
|||||||
import static org.junit.Assert.assertThat;
|
import static org.junit.Assert.assertThat;
|
||||||
import static org.junit.Assert.fail;
|
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.DateFormat;
|
||||||
import java.text.ParseException;
|
import java.text.ParseException;
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
@@ -27,7 +23,6 @@ import org.apache.commons.lang.StringUtils;
|
|||||||
import org.apache.http.conn.HttpHostConnectException;
|
import org.apache.http.conn.HttpHostConnectException;
|
||||||
import org.joda.time.DateTimeZone;
|
import org.joda.time.DateTimeZone;
|
||||||
import org.joda.time.LocalDate;
|
import org.joda.time.LocalDate;
|
||||||
import org.mifosplatform.infrastructure.core.service.DateUtils;
|
|
||||||
|
|
||||||
import com.jayway.restassured.RestAssured;
|
import com.jayway.restassured.RestAssured;
|
||||||
import com.jayway.restassured.path.json.JsonPath;
|
import com.jayway.restassured.path.json.JsonPath;
|
||||||
|
|||||||
+31
-18
@@ -10,6 +10,7 @@ import java.text.SimpleDateFormat;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.TimeZone;
|
||||||
|
|
||||||
import org.joda.time.DateTime;
|
import org.joda.time.DateTime;
|
||||||
import org.joda.time.DateTimeZone;
|
import org.joda.time.DateTimeZone;
|
||||||
@@ -23,6 +24,25 @@ import org.mifosplatform.infrastructure.core.exception.PlatformApiDataValidation
|
|||||||
|
|
||||||
public class DateUtils {
|
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() {
|
public static Date getDateOfTenant() {
|
||||||
return getLocalDateOfTenant().toDateTimeAtStartOfDay().toDate();
|
return getLocalDateOfTenant().toDateTimeAtStartOfDay().toDate();
|
||||||
}
|
}
|
||||||
@@ -31,13 +51,9 @@ public class DateUtils {
|
|||||||
|
|
||||||
LocalDate today = new LocalDate();
|
LocalDate today = new LocalDate();
|
||||||
|
|
||||||
final MifosPlatformTenant tenant = ThreadLocalContextUtil.getTenant();
|
final DateTimeZone zone = getDateTimeZoneOfTenant();
|
||||||
|
if (zone != null) {
|
||||||
if (tenant != null) {
|
today = new LocalDate(zone);
|
||||||
final DateTimeZone zone = DateTimeZone.forID(tenant.getTimezoneId());
|
|
||||||
if (zone != null) {
|
|
||||||
today = new LocalDate(zone);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return today;
|
return today;
|
||||||
@@ -45,25 +61,21 @@ public class DateUtils {
|
|||||||
|
|
||||||
public static LocalDateTime getLocalDateTimeOfTenant() {
|
public static LocalDateTime getLocalDateTimeOfTenant() {
|
||||||
|
|
||||||
LocalDateTime today = new LocalDateTime();
|
LocalDateTime today = new LocalDateTime();
|
||||||
|
|
||||||
final MifosPlatformTenant tenant = ThreadLocalContextUtil.getTenant();
|
final DateTimeZone zone = getDateTimeZoneOfTenant();
|
||||||
|
if (zone != null) {
|
||||||
|
today = new LocalDateTime(zone);
|
||||||
|
}
|
||||||
|
|
||||||
if (tenant != null) {
|
return today;
|
||||||
final DateTimeZone zone = DateTimeZone.forID(tenant.getTimezoneId());
|
|
||||||
if (zone != null) {
|
|
||||||
today = new LocalDateTime(zone);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return today;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static LocalDate parseLocalDate(final String stringDate, final String pattern) {
|
public static LocalDate parseLocalDate(final String stringDate, final String pattern) {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
final DateTimeFormatter dateStringFormat = DateTimeFormat.forPattern(pattern);
|
final DateTimeFormatter dateStringFormat = DateTimeFormat.forPattern(pattern);
|
||||||
|
dateStringFormat.withZone(getDateTimeZoneOfTenant());
|
||||||
final DateTime dateTime = dateStringFormat.parseDateTime(stringDate);
|
final DateTime dateTime = dateStringFormat.parseDateTime(stringDate);
|
||||||
return dateTime.toLocalDate();
|
return dateTime.toLocalDate();
|
||||||
} catch (final IllegalArgumentException e) {
|
} catch (final IllegalArgumentException e) {
|
||||||
@@ -78,6 +90,7 @@ public class DateUtils {
|
|||||||
|
|
||||||
public static String formatToSqlDate(final Date date) {
|
public static String formatToSqlDate(final Date date) {
|
||||||
final DateFormat df = new SimpleDateFormat("yyyy-MM-dd");
|
final DateFormat df = new SimpleDateFormat("yyyy-MM-dd");
|
||||||
|
df.setTimeZone(getTimeZoneOfTenant());
|
||||||
final String formattedSqlDate = df.format(date);
|
final String formattedSqlDate = df.format(date);
|
||||||
return formattedSqlDate;
|
return formattedSqlDate;
|
||||||
}
|
}
|
||||||
|
|||||||
+1
@@ -970,6 +970,7 @@ public class SavingsAccountWritePlatformServiceJpaRepositoryImpl implements Savi
|
|||||||
savingsAccountChargeId, accountId);
|
savingsAccountChargeId, accountId);
|
||||||
|
|
||||||
final DateTimeFormatter fmt = DateTimeFormat.forPattern("dd MM yyyy");
|
final DateTimeFormatter fmt = DateTimeFormat.forPattern("dd MM yyyy");
|
||||||
|
fmt.withZone(DateUtils.getDateTimeZoneOfTenant());
|
||||||
|
|
||||||
while (transactionDate.isAfter(savingsAccountCharge.getDueLocalDate()) && savingsAccountCharge.isNotFullyPaid()) {
|
while (transactionDate.isAfter(savingsAccountCharge.getDueLocalDate()) && savingsAccountCharge.isNotFullyPaid()) {
|
||||||
payCharge(savingsAccountCharge, transactionDate, savingsAccountCharge.amoutOutstanding(), fmt, user);
|
payCharge(savingsAccountCharge, transactionDate, savingsAccountCharge.amoutOutstanding(), fmt, user);
|
||||||
|
|||||||
Reference in New Issue
Block a user