7.14. Date Management

Provides a function to centrally manage the system date and time (OS date and time) and business date used in applications.

7.14.1. Function overview

7.14.1.1. System date and time (OS date and time) and business date can be switched

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.

7.14.2. Module list

<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>

7.14.3. How to use

7.14.3.1. Configure settings to use the system date and time management function

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" />

7.14.3.2. Acquire system date and time

Use SystemTimeUtil to acquire the system date and time.

7.14.3.3. Configure settings to use the business date management function

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>

7.14.3.4. Acquire business date

Use BusinessDateUtil to acquire the business date.

7.14.3.5. Overwrite business date to an arbitrary date

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.

Tip

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”

-DBasicBusinessDateProvider.batch=20160317

7.14.3.6. Update business date

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);

7.14.4. Expansion example

7.14.4.1. Switch system date and time

To switch the system date and time when executing a unit test, perform the following procedure.

  1. Create a class that implements SystemTimeProvider .
  2. Configure in accordance with Configure settings to use the system date and time management function .

7.14.4.2. Switch business date

To switch the business date when executing a unit test, perform the following procedure.

  1. Create a class that implements BusinessDateProvider .
  2. Configure in accordance with Configure settings to use the business date management function .