git.net

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GitHub] stevedlawrence commented on a change in pull request #70: Adding property binaryCalendarRep with values "binarySeconds" and "bi…


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_r189954845
 
 

 ##########
 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
+    }
+
 
 Review comment:
   Similar to unparse, do we need all this calendar stuff from above? Can we just get a long, calculate the diff between the binaryCalendarEpoch, and then convert that to a DFDLDateTime? Does binarySeconds/Milliseconds actually care about most of the dfdl:calendar* properties? I'm not even sure the dfd.parse(binCalEpoch) is correct. As is, that's using the calendarPattern format, but I would think that should always be in a standard xs:dateTime format, and so shouldn't use the CalendarEv, but just use some standard infoset dateTime parsing stuff and schema compile time in the primitive.

----------------------------------------------------------------
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:
users@xxxxxxxxxxxxxxxx


With regards,
Apache Git Services