Fixed that if date or time is not set nothing gets written to output (instead of 0 which is an invalid value so that message get discarded)

This commit is contained in:
dankl 2019-10-13 02:31:59 +02:00 committed by dankito
parent 9a6c3b0821
commit 3ccef79596
2 changed files with 23 additions and 1 deletions

View File

@ -17,10 +17,21 @@ open class Datum(date: Int, existenzstatus: Existenzstatus) : NumerischesDatenel
const val HbciDateFormatString = "yyyyMMdd" const val HbciDateFormatString = "yyyyMMdd"
val HbciDateFormat = SimpleDateFormat(HbciDateFormatString) val HbciDateFormat = SimpleDateFormat(HbciDateFormatString)
const val DateNotSet = Int.MIN_VALUE
} }
constructor(date: Date?, existenzstatus: Existenzstatus) constructor(date: Date?, existenzstatus: Existenzstatus)
: this(date?.let { HbciDateFormat.format(it).toInt() } ?: 0, existenzstatus) : this(date?.let { HbciDateFormat.format(it).toInt() } ?: DateNotSet, existenzstatus)
override fun format(): String {
if (value == DateNotSet) {
return "" // optional element and value not set -> write nothing to output
}
return super.format()
}
} }

View File

@ -18,10 +18,21 @@ open class Uhrzeit(time: Int, existenzstatus: Existenzstatus) : ZiffernDatenelem
const val HbciTimeFormatString = "HHmmss" const val HbciTimeFormatString = "HHmmss"
val HbciTimeFormat = SimpleDateFormat(HbciTimeFormatString) val HbciTimeFormat = SimpleDateFormat(HbciTimeFormatString)
const val TimeNotSet = Int.MIN_VALUE
} }
constructor(time: Date?, existenzstatus: Existenzstatus) constructor(time: Date?, existenzstatus: Existenzstatus)
: this(time?.let { HbciTimeFormat.format(it).toInt() } ?: 0, existenzstatus) : this(time?.let { HbciTimeFormat.format(it).toInt() } ?: 0, existenzstatus)
override fun format(): String {
if (value == TimeNotSet) {
return "" // optional element and value not set -> write nothing to output
}
return super.format()
}
} }