Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
package jp.osscons.opensourcecobol.libcobj.common;

import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.Arrays;
import java.util.Calendar;
import java.util.Random;
Expand Down Expand Up @@ -1770,4 +1771,125 @@ public static AbstractCobolField funcConcatenate(
}
return currField;
}

/**
* cob_intr_date_to_yyyymmddの実装
*
* @param params
* @param fields
* @return
*/
public static AbstractCobolField funcDateToYyyymmdd(int params, AbstractCobolField... fields) {
int year;
int mmdd;
int interval;
int xqtyear;
int maxyear;
LocalDateTime timeptr;

CobolFieldAttribute attr =
new CobolFieldAttribute(CobolFieldAttribute.COB_TYPE_NUMERIC_BINARY, 8, 0, 0, null);
AbstractCobolField field = CobolFieldFactory.makeCobolField(4, (CobolDataStorage) null, attr);
makeFieldEntry(field);
year = fields[0].getInt();
mmdd = year % 10000;
year /= 10000;
if (params > 1) {
interval = fields[1].getInt();
} else {
interval = 50;
}
if (params > 2) {
xqtyear = fields[2].getInt();
} else {
timeptr = CobolUtil.localtime();
xqtyear = 1900 + timeptr.getDayOfYear();
}
if (year < 0 || year > 999999) {
CobolRuntimeException.setException(CobolExceptionId.COB_EC_ARGUMENT_FUNCTION);
currField.setInt(0);
return currField;
}
if (xqtyear < 1601 || xqtyear > 9999) {
CobolRuntimeException.setException(CobolExceptionId.COB_EC_ARGUMENT_FUNCTION);
currField.setInt(0);
return currField;
}
maxyear = xqtyear + interval;
if (maxyear < 1700 || maxyear > 9999) {
CobolRuntimeException.setException(CobolExceptionId.COB_EC_ARGUMENT_FUNCTION);
currField.setInt(0);
return currField;
}
if (maxyear % 100 >= year) {
year += 100 * (maxyear / 100);
} else {
year += 100 * ((maxyear / 100) - 1);
}
year *= 10000;
year += mmdd;
currField.setInt(year);
return currField;
}

/**
* cob_intr_day_to_yyyydddの実装
*
* @param params
* @param fields
* @return
*/
public static AbstractCobolField funcDayToYyyyddd(int params, AbstractCobolField... fields) {
int year;
int days;
int interval;
int xqtyear;
int maxyear;
LocalDateTime timeptr;

CobolFieldAttribute attr =
new CobolFieldAttribute(CobolFieldAttribute.COB_TYPE_NUMERIC_BINARY, 8, 0, 0, null);
AbstractCobolField field = CobolFieldFactory.makeCobolField(4, (CobolDataStorage) null, attr);
makeFieldEntry(field);
year = fields[0].getInt();
days = year % 1000;
year /= 1000;
if (params > 1) {
interval = fields[1].getInt();
} else {
interval = 50;
}
if (params > 2) {
xqtyear = fields[2].getInt();
} else {
timeptr = CobolUtil.localtime();
xqtyear = 1900 + timeptr.getDayOfYear();
}

if (year < 0 || year > 999999) {
CobolRuntimeException.setException(CobolExceptionId.COB_EC_ARGUMENT_FUNCTION);
currField.setInt(0);
return currField;
}
if (xqtyear < 1601 || xqtyear > 9999) {
CobolRuntimeException.setException(CobolExceptionId.COB_EC_ARGUMENT_FUNCTION);
currField.setInt(0);
return currField;
}
maxyear = xqtyear + interval;
if (maxyear < 1700 || maxyear > 9999) {
CobolRuntimeException.setException(CobolExceptionId.COB_EC_ARGUMENT_FUNCTION);
currField.setInt(0);
return currField;
}
if (maxyear % 100 >= year) {
year += 100 * (maxyear / 100);
} else {
year += 100 * ((maxyear / 100) - 1);
}
year *= 1000;
year += days;
currField.setInt(year);
return currField;
}
}
2 changes: 0 additions & 2 deletions tests/run.src/functions.at
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,6 @@ AT_CHECK([java prog], [0],
AT_CLEANUP

AT_SETUP([FUNCTION DATE-TO-YYYYMMDD])
AT_CHECK([${SKIP_TEST}])

AT_DATA([prog.cob], [
IDENTIFICATION DIVISION.
Expand Down Expand Up @@ -335,7 +334,6 @@ AT_CHECK([java prog], [0],
AT_CLEANUP

AT_SETUP([FUNCTION DAY-TO-YYYYDDD])
AT_CHECK([${SKIP_TEST}])

AT_DATA([prog.cob], [
IDENTIFICATION DIVISION.
Expand Down