stevedlawrence commented on a change in pull request #70: Adding property
binaryCalendarRep with values "binarySeconds" and "bi…
URL: https://github.com/apache/incubator-daffodil/pull/70#discussion_r189956436
##########
File path:
daffodil-runtime1/src/main/scala/org/apache/daffodil/processors/parsers/PrimitivesDateTime1.scala
##########
@@ -188,3 +189,83 @@ object TextCalendarConstants {
}
}
}
+
+case class ConvertBinaryCalendarParser(erd: ElementRuntimeData,
+ xsdType: String,
+ prettyType: String,
+ pattern: String,
+ hasTZ: Boolean,
+ localeEv: CalendarLanguageEv,
+ calendarEv: CalendarEv,
+ infosetPattern: String,
+ firstDay: Int,
+ calendarDaysInFirstWeek: Int,
+ calendarCheckPolicy: Boolean,
+ calendarTz: Option[TimeZone],
+ tz: TimeZone,
+ binCalRep: BinaryCalendarRep,
+ binCalEpoch: String,
+ lengthInBits: Int)
+ extends ConvertTextCalendarProcessorBase(erd,
+ xsdType, prettyType, pattern, hasTZ, localeEv, calendarEv, infosetPattern,
firstDay, calendarDaysInFirstWeek,
+ calendarCheckPolicy, calendarTz, tz)
+ with TextPrimParser {
+
+ override lazy val runtimeDependencies = List(localeEv, calendarEv)
+
+ def parse(start: PState): Unit = {
+
+ val dis = start.dataInputStream
+ val int: BigInt = dis.getSignedBigInt(lengthInBits, start)
+ val pos = new ParsePosition(0)
+ val locale: ULocale = localeEv.evaluate(start)
+ val calendar: Calendar = calendarEv.evaluate(start)
+
+ // This initialization is needed because the calendar object may have
+ // been persisted, and that computes/completes fields that are not yet
completed,
+ // such as the Julian day, which freezes the year to 1970.
+ // We want a fresh start on all the fields that are filled in from a parse.
+
+ calendar.clear()
+
+ val df = tlDataFormatter(locale, calendar)
+ val cal = df.getCalendar.clone.asInstanceOf[Calendar]
+
+ df.parse(binCalEpoch, cal, pos)
+
+ // Use pos to verify all characters consumed & check for errors
+ if (pos.getIndex != binCalEpoch.length || pos.getErrorIndex >= 0) {
+ val errIndex = if (pos.getErrorIndex >= 0) pos.getErrorIndex else
pos.getIndex
+ PE(start, "Parsing the binaryCalendarEpoch from String '%s' - Failed to
parse at index: %d.", binCalEpoch, errIndex)
+ return
+ }
+
+ if (binCalRep.eq(BinaryCalendarRep.BinarySeconds)) {
+ cal.add(Calendar.SECOND, int.intValue())
+ } else if (binCalRep.eq(BinaryCalendarRep.BinaryMilliseconds)) {
+ cal.add(Calendar.MILLISECOND, int.intValue())
Review comment:
milliseconds is 64 bits, which isn't an integer, does cal.add accept a long
value or can we not actually support 64 bit values? Maybe using setTimeInMillis
instead of cal.add would work better?
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services