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_r192196125
##########
File path:
daffodil-core/src/main/scala/org/apache/daffodil/grammar/primitives/PrimitivesDateTime.scala
##########
@@ -191,3 +186,61 @@ case class ConvertTextDateTimePrim(e: ElementBase)
extends ConvertTextCalendarPr
protected override val implicitPattern = "uuuu-MM-dd'T'HH:mm:ss"
protected override val validFormatCharacters =
"adDeEFGhHkKmMsSuwWvVyXxYzZ".toSeq
}
+
+abstract class ConvertBinaryCalendarPrimBase(e: ElementBase, guard: Boolean,
lengthInBits: Long)
+ extends ConvertCalendarPrimBase(e, guard) {
+
+ lazy val epochCalendar: Calendar = {
+ val cal = Calendar.getInstance
+ cal.clear()
+ cal.setLenient(false)
+
+ val sdfWithTZ = new SimpleDateFormat("uuuu-MM-dd'T'HH:mm:ssZZZZ",
ULocale.ENGLISH)
+ var pos = new ParsePosition(0)
+ sdfWithTZ.parse(e.binaryCalendarEpoch, cal, pos)
+
+ if (pos.getIndex != e.binaryCalendarEpoch.length || pos.getErrorIndex >=
0) {
+ // binaryCalendarEpoch didn't match the first format with timezone, so
try without
+ cal.clear()
+ pos = new ParsePosition(0)
+ val sdf = new SimpleDateFormat("uuuu-MM-dd'T'HH:mm:ss", ULocale.ENGLISH)
+ cal.setTimeZone(TimeZone.UNKNOWN_ZONE)
+ sdf.parse(e.binaryCalendarEpoch, cal, pos)
+
+ if (pos.getIndex != e.binaryCalendarEpoch.length || pos.getErrorIndex >=
0) {
+ SDE("Failed to parse binaryCalendarEpoch - Format must match the
pattern 'uuuu-MM-dd'T'HH:mm:ss' or 'uuuu-MM-dd'T'HH:mm:ssZZZZ'")
+ }
+ }
+
+ try {
+ cal.getTime
+ } catch {
+ case e: IllegalArgumentException => {
+ SDE("Failed to parse binaryCalendarEpoch: %s.", e.getMessage())
+ }
+ }
+
+ cal
+ }
+
+ override lazy val parser = new ConvertBinaryCalendarParser(
Review comment:
Should this and the below prim be renamed to something that makes it clear
is for seconds/milliseconds so that it will be differentiated from other
binaryCalendarRep's when they are added?
----------------------------------------------------------------
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