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_r190865198
 
 

 ##########
 File path: daffodil-runtime1/src/main/scala/org/apache/daffodil/processors/parsers/PrimitivesDateTime1.scala
 ##########
 @@ -188,3 +169,37 @@ object TextCalendarConstants {
     }
   }
 }
+
+case class ConvertBinaryCalendarParser(
+  override val context: ElementRuntimeData,
+  hasTZ: Boolean,
+  binCalRep: BinaryCalendarRep,
+  epochCal: Calendar,
+  lengthInBits: Int)
+  extends PrimParser {
+
+  override lazy val runtimeDependencies = Nil
+
+  def parse(start: PState): Unit = {
+
+    val dis = start.dataInputStream
+    val slong: Long = dis.getSignedLong(lengthInBits, start)
+
+    if (binCalRep.eq(BinaryCalendarRep.BinarySeconds)) {
+      epochCal.add(Calendar.SECOND, slong.intValue())
+    } else if (binCalRep.eq(BinaryCalendarRep.BinaryMilliseconds)) {
+      val newTime = epochCal.getTimeInMillis + slong
+      try {
+        epochCal.setTimeInMillis(newTime)
 
 Review comment:
   This isn't thread safe. This code could be executed by multiple threads, modifying the calendar at the same time. Instead, we need to create a new thread local Calendar based on calendarEv. It looks like the Parser deals with this by cloning the calendar. In other cases we've used a ThreadLocal, so we could alternatively change our CalendarEv to return a ThreadLocal[Calendar] instead of a Calendar.

----------------------------------------------------------------
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