Fix transaction cannot be in future check
This commit is contained in:
committed by
Arnold Gálovics
parent
a73c593eb8
commit
7fb61d028e
+1
-1
@@ -53,7 +53,7 @@ public class ProvisioningEntriesReadPlatformServiceImpl implements ProvisioningE
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Collection<LoanProductProvisioningEntryData> retrieveLoanProductsProvisioningData(LocalDate date) {
|
public Collection<LoanProductProvisioningEntryData> retrieveLoanProductsProvisioningData(LocalDate date) {
|
||||||
String formattedDate = DateUtils.DEFAULT_DATE_FORMATER.format(date);
|
String formattedDate = DateUtils.DEFAULT_DATE_FORMATTER.format(date);
|
||||||
LoanProductProvisioningEntryMapper mapper = new LoanProductProvisioningEntryMapper(sqlGenerator);
|
LoanProductProvisioningEntryMapper mapper = new LoanProductProvisioningEntryMapper(sqlGenerator);
|
||||||
final String sql = mapper.schema();
|
final String sql = mapper.schema();
|
||||||
return this.jdbcTemplate.query(sql, mapper, formattedDate, formattedDate, formattedDate);
|
return this.jdbcTemplate.query(sql, mapper, formattedDate, formattedDate, formattedDate);
|
||||||
|
|||||||
+2
-2
@@ -181,8 +181,8 @@ public class EmailReadPlatformServiceImpl implements EmailReadPlatformService {
|
|||||||
String fromDateString = null;
|
String fromDateString = null;
|
||||||
String toDateString = null;
|
String toDateString = null;
|
||||||
if (dateFrom != null && dateTo != null) {
|
if (dateFrom != null && dateTo != null) {
|
||||||
fromDateString = DateUtils.DEFAULT_DATE_FORMATER.format(dateFrom);
|
fromDateString = DateUtils.DEFAULT_DATE_FORMATTER.format(dateFrom);
|
||||||
toDateString = DateUtils.DEFAULT_DATE_FORMATER.format(dateTo);
|
toDateString = DateUtils.DEFAULT_DATE_FORMATTER.format(dateTo);
|
||||||
sqlBuilder.append(" and emo.submittedon_date >= ? and emo.submittedon_date <= ? ");
|
sqlBuilder.append(" and emo.submittedon_date >= ? and emo.submittedon_date <= ? ");
|
||||||
}
|
}
|
||||||
final String sqlPlusLimit = (limit > 0) ? " " + sqlGenerator.limit(limit) : "";
|
final String sqlPlusLimit = (limit > 0) ? " " + sqlGenerator.limit(limit) : "";
|
||||||
|
|||||||
+2
-2
@@ -31,9 +31,9 @@ public final class DateUtils {
|
|||||||
|
|
||||||
public static final String DEFAULT_DATE_FORMAT = "yyyy-MM-dd";
|
public static final String DEFAULT_DATE_FORMAT = "yyyy-MM-dd";
|
||||||
public static final String DEFAULT_DATETIME_FORMAT = DEFAULT_DATE_FORMAT + " HH:mm:ss";
|
public static final String DEFAULT_DATETIME_FORMAT = DEFAULT_DATE_FORMAT + " HH:mm:ss";
|
||||||
public static final DateTimeFormatter DEFAULT_DATETIME_FORMATER = new DateTimeFormatterBuilder().appendPattern(DEFAULT_DATETIME_FORMAT)
|
public static final DateTimeFormatter DEFAULT_DATETIME_FORMATTER = new DateTimeFormatterBuilder().appendPattern(DEFAULT_DATETIME_FORMAT)
|
||||||
.toFormatter();
|
.toFormatter();
|
||||||
public static final DateTimeFormatter DEFAULT_DATE_FORMATER = new DateTimeFormatterBuilder().appendPattern(DEFAULT_DATE_FORMAT)
|
public static final DateTimeFormatter DEFAULT_DATE_FORMATTER = new DateTimeFormatterBuilder().appendPattern(DEFAULT_DATE_FORMAT)
|
||||||
.toFormatter();
|
.toFormatter();
|
||||||
|
|
||||||
private DateUtils() {
|
private DateUtils() {
|
||||||
|
|||||||
+6
-6
@@ -90,9 +90,9 @@ public class DatabaseSpecificSQLGenerator {
|
|||||||
|
|
||||||
public String currentBusinessDate() {
|
public String currentBusinessDate() {
|
||||||
if (databaseTypeResolver.isMySQL()) {
|
if (databaseTypeResolver.isMySQL()) {
|
||||||
return format("DATE('%s')", DateUtils.getBusinessLocalDate().format(DateUtils.DEFAULT_DATE_FORMATER));
|
return format("DATE('%s')", DateUtils.getBusinessLocalDate().format(DateUtils.DEFAULT_DATE_FORMATTER));
|
||||||
} else if (databaseTypeResolver.isPostgreSQL()) {
|
} else if (databaseTypeResolver.isPostgreSQL()) {
|
||||||
return format("DATE '%s'", DateUtils.getBusinessLocalDate().format(DateUtils.DEFAULT_DATE_FORMATER));
|
return format("DATE '%s'", DateUtils.getBusinessLocalDate().format(DateUtils.DEFAULT_DATE_FORMATTER));
|
||||||
} else {
|
} else {
|
||||||
throw new IllegalStateException("Database type is not supported for current date " + databaseTypeResolver.databaseType());
|
throw new IllegalStateException("Database type is not supported for current date " + databaseTypeResolver.databaseType());
|
||||||
}
|
}
|
||||||
@@ -100,9 +100,9 @@ public class DatabaseSpecificSQLGenerator {
|
|||||||
|
|
||||||
public String currentTenantDate() {
|
public String currentTenantDate() {
|
||||||
if (databaseTypeResolver.isMySQL()) {
|
if (databaseTypeResolver.isMySQL()) {
|
||||||
return format("DATE('%s')", DateUtils.getLocalDateOfTenant().format(DateUtils.DEFAULT_DATE_FORMATER));
|
return format("DATE('%s')", DateUtils.getLocalDateOfTenant().format(DateUtils.DEFAULT_DATE_FORMATTER));
|
||||||
} else if (databaseTypeResolver.isPostgreSQL()) {
|
} else if (databaseTypeResolver.isPostgreSQL()) {
|
||||||
return format("DATE '%s'", DateUtils.getLocalDateOfTenant().format(DateUtils.DEFAULT_DATE_FORMATER));
|
return format("DATE '%s'", DateUtils.getLocalDateOfTenant().format(DateUtils.DEFAULT_DATE_FORMATTER));
|
||||||
} else {
|
} else {
|
||||||
throw new IllegalStateException("Database type is not supported for current date " + databaseTypeResolver.databaseType());
|
throw new IllegalStateException("Database type is not supported for current date " + databaseTypeResolver.databaseType());
|
||||||
}
|
}
|
||||||
@@ -110,9 +110,9 @@ public class DatabaseSpecificSQLGenerator {
|
|||||||
|
|
||||||
public String currentTenantDateTime() {
|
public String currentTenantDateTime() {
|
||||||
if (databaseTypeResolver.isMySQL()) {
|
if (databaseTypeResolver.isMySQL()) {
|
||||||
return format("TIMESTAMP('%s')", DateUtils.getLocalDateTimeOfTenant().format(DateUtils.DEFAULT_DATETIME_FORMATER));
|
return format("TIMESTAMP('%s')", DateUtils.getLocalDateTimeOfTenant().format(DateUtils.DEFAULT_DATETIME_FORMATTER));
|
||||||
} else if (databaseTypeResolver.isPostgreSQL()) {
|
} else if (databaseTypeResolver.isPostgreSQL()) {
|
||||||
return format("TIMESTAMP '%s'", DateUtils.getLocalDateTimeOfTenant().format(DateUtils.DEFAULT_DATETIME_FORMATER));
|
return format("TIMESTAMP '%s'", DateUtils.getLocalDateTimeOfTenant().format(DateUtils.DEFAULT_DATETIME_FORMATTER));
|
||||||
} else {
|
} else {
|
||||||
throw new IllegalStateException("Database type is not supported for current date time" + databaseTypeResolver.databaseType());
|
throw new IllegalStateException("Database type is not supported for current date time" + databaseTypeResolver.databaseType());
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -171,7 +171,7 @@ public class GenericDataServiceImpl implements GenericDataService {
|
|||||||
"[" + localDate.getYear() + ", " + localDate.getMonthValue() + ", " + localDate.getDayOfMonth() + "]");
|
"[" + localDate.getYear() + ", " + localDate.getMonthValue() + ", " + localDate.getDayOfMonth() + "]");
|
||||||
} else if (currColType.equals("DATETIME")) {
|
} else if (currColType.equals("DATETIME")) {
|
||||||
final LocalDateTime localDateTime = LocalDateTime.parse(formatDateTimeValue(currVal),
|
final LocalDateTime localDateTime = LocalDateTime.parse(formatDateTimeValue(currVal),
|
||||||
DateUtils.DEFAULT_DATETIME_FORMATER);
|
DateUtils.DEFAULT_DATETIME_FORMATTER);
|
||||||
writer.append("[" + localDateTime.getYear() + ", " + localDateTime.getMonthValue() + ", "
|
writer.append("[" + localDateTime.getYear() + ", " + localDateTime.getMonthValue() + ", "
|
||||||
+ localDateTime.getDayOfMonth() + ", " + localDateTime.getHour() + ", " + localDateTime.getMinute()
|
+ localDateTime.getDayOfMonth() + ", " + localDateTime.getHour() + ", " + localDateTime.getMinute()
|
||||||
+ ", " + localDateTime.getSecond() + ", " + localDateTime.get(ChronoField.MILLI_OF_SECOND) + "]");
|
+ ", " + localDateTime.getSecond() + ", " + localDateTime.get(ChronoField.MILLI_OF_SECOND) + "]");
|
||||||
|
|||||||
+3
-3
@@ -33,21 +33,21 @@ public final class ReportMailingJobDateUtil {
|
|||||||
* get the current date as string using the mysql date format yyyy-MM-dd
|
* get the current date as string using the mysql date format yyyy-MM-dd
|
||||||
**/
|
**/
|
||||||
public static String getTodayDateAsString() {
|
public static String getTodayDateAsString() {
|
||||||
return DateUtils.getLocalDateOfTenant().format(DateUtils.DEFAULT_DATE_FORMATER);
|
return DateUtils.getLocalDateOfTenant().format(DateUtils.DEFAULT_DATE_FORMATTER);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* get the yesterday's date as string using the mysql date format yyyy-MM-dd
|
* get the yesterday's date as string using the mysql date format yyyy-MM-dd
|
||||||
**/
|
**/
|
||||||
public static String getYesterdayDateAsString() {
|
public static String getYesterdayDateAsString() {
|
||||||
return DateUtils.getLocalDateOfTenant().minusDays(1).format(DateUtils.DEFAULT_DATE_FORMATER);
|
return DateUtils.getLocalDateOfTenant().minusDays(1).format(DateUtils.DEFAULT_DATE_FORMATTER);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* get the tomorrow's date as string using the mysql date format yyyy-MM-dd
|
* get the tomorrow's date as string using the mysql date format yyyy-MM-dd
|
||||||
**/
|
**/
|
||||||
public static String getTomorrowDateAsString() {
|
public static String getTomorrowDateAsString() {
|
||||||
return DateUtils.getLocalDateOfTenant().plusDays(1).format(DateUtils.DEFAULT_DATE_FORMATER);
|
return DateUtils.getLocalDateOfTenant().plusDays(1).format(DateUtils.DEFAULT_DATE_FORMATTER);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
+2
-2
@@ -216,8 +216,8 @@ public class SmsReadPlatformServiceImpl implements SmsReadPlatformService {
|
|||||||
String fromDateString = null;
|
String fromDateString = null;
|
||||||
String toDateString = null;
|
String toDateString = null;
|
||||||
if (dateFrom != null && dateTo != null) {
|
if (dateFrom != null && dateTo != null) {
|
||||||
fromDateString = DateUtils.DEFAULT_DATE_FORMATER.format(dateFrom);
|
fromDateString = DateUtils.DEFAULT_DATE_FORMATTER.format(dateFrom);
|
||||||
toDateString = DateUtils.DEFAULT_DATE_FORMATER.format(dateTo);
|
toDateString = DateUtils.DEFAULT_DATE_FORMATTER.format(dateTo);
|
||||||
sqlBuilder.append(" and smo.submittedon_date >= ? and smo.submittedon_date <= ? ");
|
sqlBuilder.append(" and smo.submittedon_date >= ? and smo.submittedon_date <= ? ");
|
||||||
objectArray[arrayPos] = fromDateString;
|
objectArray[arrayPos] = fromDateString;
|
||||||
arrayPos = arrayPos + 1;
|
arrayPos = arrayPos + 1;
|
||||||
|
|||||||
+1
-1
@@ -89,7 +89,7 @@ public class HolidayReadPlatformServiceImpl implements HolidayReadPlatformServic
|
|||||||
final LocalDate toDate) {
|
final LocalDate toDate) {
|
||||||
this.context.authenticatedUser();
|
this.context.authenticatedUser();
|
||||||
|
|
||||||
final DateTimeFormatter df = DateUtils.DEFAULT_DATE_FORMATER;
|
final DateTimeFormatter df = DateUtils.DEFAULT_DATE_FORMATTER;
|
||||||
|
|
||||||
final Object[] objectArray = new Object[3];
|
final Object[] objectArray = new Object[3];
|
||||||
int arrayPos = 0;
|
int arrayPos = 0;
|
||||||
|
|||||||
+3
-3
@@ -60,7 +60,7 @@ public class DateRange {
|
|||||||
|
|
||||||
final String testee;
|
final String testee;
|
||||||
if (dateToParse == null) {
|
if (dateToParse == null) {
|
||||||
testee = DateUtils.DEFAULT_DATE_FORMATER.format(DateUtils.getBusinessLocalDate());
|
testee = DateUtils.DEFAULT_DATE_FORMATTER.format(DateUtils.getBusinessLocalDate());
|
||||||
} else {
|
} else {
|
||||||
testee = dateToParse;
|
testee = dateToParse;
|
||||||
}
|
}
|
||||||
@@ -68,14 +68,14 @@ public class DateRange {
|
|||||||
final StringTokenizer tokenizer = new StringTokenizer(testee, DateRange.RANGE_DELIMITER);
|
final StringTokenizer tokenizer = new StringTokenizer(testee, DateRange.RANGE_DELIMITER);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
dateRange.setStartDate(LocalDate.parse(tokenizer.nextToken(), DateUtils.DEFAULT_DATE_FORMATER));
|
dateRange.setStartDate(LocalDate.parse(tokenizer.nextToken(), DateUtils.DEFAULT_DATE_FORMATTER));
|
||||||
} catch (DateTimeParseException ex) {
|
} catch (DateTimeParseException ex) {
|
||||||
LOG.error("Problem occurred in DateRange function Could not parse the date recieved.", ex);
|
LOG.error("Problem occurred in DateRange function Could not parse the date recieved.", ex);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tokenizer.hasMoreTokens()) {
|
if (tokenizer.hasMoreTokens()) {
|
||||||
try {
|
try {
|
||||||
dateRange.setEndDate(LocalDate.parse(tokenizer.nextToken(), DateUtils.DEFAULT_DATE_FORMATER));
|
dateRange.setEndDate(LocalDate.parse(tokenizer.nextToken(), DateUtils.DEFAULT_DATE_FORMATTER));
|
||||||
} catch (DateTimeParseException ex) {
|
} catch (DateTimeParseException ex) {
|
||||||
LOG.error("Problem occurred in DateRange function Could not parse the date recieved.", ex);
|
LOG.error("Problem occurred in DateRange function Could not parse the date recieved.", ex);
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-2
@@ -126,7 +126,7 @@ public class StandingInstructionHistoryReadPlatformServiceImpl implements Standi
|
|||||||
sqlBuilder.append(" and ");
|
sqlBuilder.append(" and ");
|
||||||
}
|
}
|
||||||
sqlBuilder.append(" atsih.execution_time >= ? ");
|
sqlBuilder.append(" atsih.execution_time >= ? ");
|
||||||
paramObj.add(DateUtils.DEFAULT_DATE_FORMATER.format(standingInstructionDTO.startDateRange()));
|
paramObj.add(DateUtils.DEFAULT_DATE_FORMATTER.format(standingInstructionDTO.startDateRange()));
|
||||||
addAndCaluse = true;
|
addAndCaluse = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -135,7 +135,7 @@ public class StandingInstructionHistoryReadPlatformServiceImpl implements Standi
|
|||||||
sqlBuilder.append(" and ");
|
sqlBuilder.append(" and ");
|
||||||
}
|
}
|
||||||
sqlBuilder.append(" atsih.execution_time < ? ");
|
sqlBuilder.append(" atsih.execution_time < ? ");
|
||||||
paramObj.add(DateUtils.DEFAULT_DATE_FORMATER.format(standingInstructionDTO.endDateRange()));
|
paramObj.add(DateUtils.DEFAULT_DATE_FORMATTER.format(standingInstructionDTO.endDateRange()));
|
||||||
addAndCaluse = true;
|
addAndCaluse = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -138,7 +138,7 @@ public final class CalendarUtils {
|
|||||||
|
|
||||||
private static Date convertToiCal4JCompatibleDate(final LocalDateTime inputDate) {
|
private static Date convertToiCal4JCompatibleDate(final LocalDateTime inputDate) {
|
||||||
Date formattedDate = null;
|
Date formattedDate = null;
|
||||||
final String seedDateStr = DateUtils.DEFAULT_DATETIME_FORMATER.format(inputDate);
|
final String seedDateStr = DateUtils.DEFAULT_DATETIME_FORMATTER.format(inputDate);
|
||||||
try {
|
try {
|
||||||
formattedDate = new Date(seedDateStr, DateUtils.DEFAULT_DATETIME_FORMAT);
|
formattedDate = new Date(seedDateStr, DateUtils.DEFAULT_DATETIME_FORMAT);
|
||||||
} catch (final ParseException e) {
|
} catch (final ParseException e) {
|
||||||
|
|||||||
+3
-3
@@ -327,7 +327,7 @@ public class CollectionSheetReadPlatformServiceImpl implements CollectionSheetRe
|
|||||||
|
|
||||||
final Long calendarId = query.longValueOfParameterNamed(calendarIdParamName);
|
final Long calendarId = query.longValueOfParameterNamed(calendarIdParamName);
|
||||||
final LocalDate transactionDate = query.localDateValueOfParameterNamed(transactionDateParamName);
|
final LocalDate transactionDate = query.localDateValueOfParameterNamed(transactionDateParamName);
|
||||||
final String transactionDateStr = DateUtils.DEFAULT_DATE_FORMATER.format(transactionDate);
|
final String transactionDateStr = DateUtils.DEFAULT_DATE_FORMATTER.format(transactionDate);
|
||||||
|
|
||||||
final Calendar calendar = this.calendarRepositoryWrapper.findOneWithNotFoundDetection(calendarId);
|
final Calendar calendar = this.calendarRepositoryWrapper.findOneWithNotFoundDetection(calendarId);
|
||||||
// check if transaction against calendar effective from date
|
// check if transaction against calendar effective from date
|
||||||
@@ -462,7 +462,7 @@ public class CollectionSheetReadPlatformServiceImpl implements CollectionSheetRe
|
|||||||
final CenterData center = this.centerReadPlatformService.retrieveOne(centerId);
|
final CenterData center = this.centerReadPlatformService.retrieveOne(centerId);
|
||||||
|
|
||||||
final LocalDate transactionDate = query.localDateValueOfParameterNamed(transactionDateParamName);
|
final LocalDate transactionDate = query.localDateValueOfParameterNamed(transactionDateParamName);
|
||||||
final String dueDateStr = DateUtils.DEFAULT_DATE_FORMATER.format(transactionDate);
|
final String dueDateStr = DateUtils.DEFAULT_DATE_FORMATTER.format(transactionDate);
|
||||||
|
|
||||||
final JLGCollectionSheetFaltDataMapper mapper = new JLGCollectionSheetFaltDataMapper(sqlGenerator);
|
final JLGCollectionSheetFaltDataMapper mapper = new JLGCollectionSheetFaltDataMapper(sqlGenerator);
|
||||||
|
|
||||||
@@ -679,7 +679,7 @@ public class CollectionSheetReadPlatformServiceImpl implements CollectionSheetRe
|
|||||||
this.collectionSheetGenerateCommandFromApiJsonDeserializer.validateForGenerateCollectionSheetOfIndividuals(query.json());
|
this.collectionSheetGenerateCommandFromApiJsonDeserializer.validateForGenerateCollectionSheetOfIndividuals(query.json());
|
||||||
|
|
||||||
final LocalDate transactionDate = query.localDateValueOfParameterNamed(transactionDateParamName);
|
final LocalDate transactionDate = query.localDateValueOfParameterNamed(transactionDateParamName);
|
||||||
final String transactionDateStr = DateUtils.DEFAULT_DATE_FORMATER.format(transactionDate);
|
final String transactionDateStr = DateUtils.DEFAULT_DATE_FORMATTER.format(transactionDate);
|
||||||
|
|
||||||
final AppUser currentUser = this.context.authenticatedUser();
|
final AppUser currentUser = this.context.authenticatedUser();
|
||||||
final String hierarchy = currentUser.getOffice().getHierarchy();
|
final String hierarchy = currentUser.getOffice().getHierarchy();
|
||||||
|
|||||||
+1
-1
@@ -50,7 +50,7 @@ public class GenerateRdScheduleTasklet implements Tasklet {
|
|||||||
final Collection<Map<String, Object>> scheduleDetails = depositAccountReadPlatformService.retriveDataForRDScheduleCreation();
|
final Collection<Map<String, Object>> scheduleDetails = depositAccountReadPlatformService.retriveDataForRDScheduleCreation();
|
||||||
String insertSql = "INSERT INTO m_mandatory_savings_schedule (savings_account_id, duedate, installment, deposit_amount, completed_derived, created_date, lastmodified_date) VALUES ";
|
String insertSql = "INSERT INTO m_mandatory_savings_schedule (savings_account_id, duedate, installment, deposit_amount, completed_derived, created_date, lastmodified_date) VALUES ";
|
||||||
StringBuilder sb = new StringBuilder();
|
StringBuilder sb = new StringBuilder();
|
||||||
String currentDate = DateUtils.getLocalDateTimeOfTenant().format(DateUtils.DEFAULT_DATETIME_FORMATER);
|
String currentDate = DateUtils.getLocalDateTimeOfTenant().format(DateUtils.DEFAULT_DATETIME_FORMATTER);
|
||||||
int iterations = 0;
|
int iterations = 0;
|
||||||
for (Map<String, Object> details : scheduleDetails) {
|
for (Map<String, Object> details : scheduleDetails) {
|
||||||
Long count = (Long) details.get("futureInstallemts");
|
Long count = (Long) details.get("futureInstallemts");
|
||||||
|
|||||||
+88
@@ -0,0 +1,88 @@
|
|||||||
|
/**
|
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one
|
||||||
|
* or more contributor license agreements. See the NOTICE file
|
||||||
|
* distributed with this work for additional information
|
||||||
|
* regarding copyright ownership. The ASF licenses this file
|
||||||
|
* to you under the Apache License, Version 2.0 (the
|
||||||
|
* "License"); you may not use this file except in compliance
|
||||||
|
* with the License. You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing,
|
||||||
|
* software distributed under the License is distributed on an
|
||||||
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
* KIND, either express or implied. See the License for the
|
||||||
|
* specific language governing permissions and limitations
|
||||||
|
* under the License.
|
||||||
|
*/
|
||||||
|
package org.apache.fineract.infrastructure.core.service;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
|
||||||
|
import java.time.LocalDate;
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
import java.time.OffsetDateTime;
|
||||||
|
import java.time.ZoneId;
|
||||||
|
import java.time.temporal.ChronoUnit;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.TimeZone;
|
||||||
|
import org.apache.fineract.infrastructure.businessdate.domain.BusinessDateType;
|
||||||
|
import org.apache.fineract.infrastructure.core.domain.FineractPlatformTenant;
|
||||||
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
public class DateUtilsTest {
|
||||||
|
|
||||||
|
@BeforeEach
|
||||||
|
public void init() {
|
||||||
|
ThreadLocalContextUtil.setTenant(new FineractPlatformTenant(1L, "default", "Default", "Asia/Kolkata", null));
|
||||||
|
ThreadLocalContextUtil.setBusinessDates(new HashMap<>(Map.of(BusinessDateType.BUSINESS_DATE, LocalDate.of(2022, 6, 12))));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void getSystemZoneIdTest() {
|
||||||
|
TimeZone.setDefault(TimeZone.getTimeZone("GMT+02:00"));
|
||||||
|
assertEquals("GMT+02:00", DateUtils.getSystemZoneId().getId());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void getDateTimeZoneOfTenant() {
|
||||||
|
assertEquals(ZoneId.of("Asia/Kolkata"), DateUtils.getDateTimeZoneOfTenant());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void getLocalDateOfTenant() {
|
||||||
|
assertEquals(LocalDate.now(ZoneId.of("Asia/Kolkata")), DateUtils.getLocalDateOfTenant());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void getLocalDateTimeOfTenant() {
|
||||||
|
assertEquals(LocalDateTime.now(ZoneId.of("Asia/Kolkata")).truncatedTo(ChronoUnit.SECONDS), DateUtils.getLocalDateTimeOfTenant());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void getOffsetDateTimeOfTenant() {
|
||||||
|
assertEquals(OffsetDateTime.now(ZoneId.of("Asia/Kolkata")).truncatedTo(ChronoUnit.SECONDS), DateUtils.getOffsetDateTimeOfTenant());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void getLocalDateTimeOfSystem() {
|
||||||
|
assertEquals(LocalDateTime.now(ZoneId.systemDefault()).truncatedTo(ChronoUnit.SECONDS), DateUtils.getLocalDateTimeOfSystem());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void isDateInTheFuture() {
|
||||||
|
assertFalse(DateUtils.isDateInTheFuture(LocalDate.of(2022, 6, 11)));
|
||||||
|
assertFalse(DateUtils.isDateInTheFuture(LocalDate.of(2022, 6, 12)));
|
||||||
|
assertTrue(DateUtils.isDateInTheFuture(LocalDate.of(2022, 6, 13)));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void getBusinesLocalDate() {
|
||||||
|
assertEquals(LocalDate.of(2022, 6, 12), DateUtils.getBusinessLocalDate());
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user