Files
cobol-tna-system/JavaSrc/src/Sub05TimSub.java
T

57 lines
2.3 KiB
Java
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import dto.ZantimacPar;
/**
* ============================================================
* 【COBOL→Java】SUB05TIM 時刻丸め計算サブ
* ============================================================
* PROGRAM-ID. SUB05TIM → 类 Sub05TimSub
* LINKAGE: T01TIMPARCOPY ZANTIMAC → dto.ZantimacPar
* 処理概要: 時間値(T01TIMHRS、1桁小数)を指定単位で丸め、T01TIMOUT に格納。
*
* T01TIMRRC=0: 0.5時間単位・切上(30分単位)
* T01TIMRRC=1: 0.1時間単位・切上(6分単位)← KIN07DAI 使用
* T01TIMRRC=2: 0.1時間単位・切捨(6分単位)
* T01TIMRRC=3: 単純四捨五入(0.1h単位、+0.05 して V9(1) 切捨)
* OTHER : そのまま出力
*
* ※T01TIMHRS は 9(4)V9(1)1桁小数)であるため、内部では「0.1h単位の整数(tenth)」
* に変換して整数演算で丸め、再び 1桁小数へ戻す(浮動小数点誤差回避)。
*/
public class Sub05TimSub {
/**
* PROCEDURE DIVISION USING T01TIMPAR 0000MAINSOR。
*/
public static void execute(final ZantimacPar par) {
// 9(4)V9(1) → 0.1h単位整数への変換。設計(mode2=切捨)に合わせ床関数で切捨。
// ※ZAN05CAL の OVT-HOURS は 0.1h 単位切捨(floor)が仕様。round だと境界で +0.1h ずれる。
int tenth = (int) Math.floor(par.getT01Timhrs() * 10.0);
int outTenth;
switch (par.getT01Timrrc()) {
case 0:
// 0.5h単位(=5/10h)で切上
outTenth = ((tenth + 4) / 5) * 5;
break;
case 1:
// 0.1h単位で切上 → 既に 0.1h 単位のためそのまま(ceil(tenth/1)
outTenth = tenth;
break;
case 2:
// 0.1h単位で切捨 → そのまま
outTenth = tenth;
break;
case 3:
// 0.1h単位四捨五入((hrs+0.05) して V9(1) 切捨)→ 1桁小数入力では no-op
outTenth = tenth;
break;
default:
// モード指定なし → そのまま
outTenth = tenth;
break;
}
par.setT01Timout(outTenth / 10.0);
}
}