7.14. Date Management¶
Table of contents
- Function overview
- Module list
- How to use
- Expansion example
Provides a function to centrally manage the system date and time (OS date and time) and business date used in applications.
With this function, the system date and time (OS date and time) and business date are acquired using the class specified in the component definition. Therefore, the acquisition method of system date and time (OS date and time) and business date used by the application can be switched simply by replacing the class specified in the component definition. This switching can be used to temporarily switch the system date/time (OS date/time) or business date in a test, etc.
<dependency> <groupId>com.nablarch.framework</groupId> <artifactId>nablarch-core</artifactId> </dependency> <!-- Only when using business date management function--> <dependency> <groupId>com.nablarch.framework</groupId> <artifactId>nablarch-common-jdbc</artifactId> </dependency>
To use the system date and time management function, add BasicSystemTimeProvider configuration to the component definition. Specify the component name as systemTimeProvider .
<component name="systemTimeProvider" class="nablarch.core.date.BasicSystemTimeProvider" />
The business date management function uses a database to manage multiple business dates. The table layout is as follows.
|Category (PK)||A value for identifying the business date. String type|
|Date||Business date. String type and value in yyyyMMdd format|
To use the business date management function, add BasicBusinessDateProvider configuration to the component definition. Specify the component name as businessDateProvider.
<component name="businessDateProvider" class="nablarch.core.date.BasicBusinessDateProvider"> <!-- Table name --> <property name="tableName" value="BUSINESS_DATE" /> <!-- Column name of category --> <property name="segmentColumnName" value="SEGMENT"/> <!-- Column name of date --> <property name="dateColumnName" value="BIZ_DATE"/> <!-- Category used when business date is obtained by omitting the category --> <property name="defaultSegment" value="00"/> <!-- Transaction manager used for database access --> <property name="transactionManager" ref="transactionManager" /> </component>
When re-executed during failure in batch process, using the past date as the business date during batch execution may be preferred in some cases. In such a case, only the re-execution process can execute with an arbitrary date as the business date.
If all functions are executed in one process like a web application, simply change the date managed in the database.
Business date is overwritten by using Overwrite environment dependent values using system properties . Specify as a system property in the following format.
- Format of system property
BasicBusinessDateProvider. <Category> = date
*Date is in yyyyMMdd format
- Example of system property file
When overwriting the date of category “batch” to “2016/03/17”
Business date is updated by using BasicBusinessDateProvider .
// Acquire BasicBusinessDateProvider from the system repository BusinessDateProvider provider = SystemRepository.get("businessDateProvider"); // Call setDate method and update provider.setDate(segment, date);
To switch the system date and time when executing a unit test, perform the following procedure.
- Create a class that implements SystemTimeProvider .
- Configure in accordance with Configure settings to use the system date and time management function .
To switch the business date when executing a unit test, perform the following procedure.
- Create a class that implements BusinessDateProvider .
- Configure in accordance with Configure settings to use the business date management function .