stevedlawrence commented on code in PR #1682:
URL: https://github.com/apache/daffodil/pull/1682#discussion_r3395533180


##########
daffodil-core/src/main/scala/org/apache/daffodil/lib/xml/XMLUtils.scala:
##########
@@ -1302,6 +1302,16 @@ Differences were (path, expected, actual):
     }
   }
 
+  /**
+   * Normalizing fractional seconds to milliseconds precision.
+   * @param data Date/Time
+   * @return normalized data with microseconds precision dropped.
+   */
+  private def normalizeFractionalSeconds(data: String): String = {

Review Comment:
   Thoughts on calling this something like `normalizeXmlCalendar`, and then if 
we ever need additional normalizations we can put them all in here and the name 
still makes sense?



##########
daffodil-core/src/main/scala/org/apache/daffodil/lib/xml/XMLUtils.scala:
##########
@@ -1302,6 +1302,16 @@ Differences were (path, expected, actual):
     }
   }
 
+  /**
+   * Normalizing fractional seconds to milliseconds precision.
+   * @param data Date/Time
+   * @return normalized data with microseconds precision dropped.
+   */
+  private def normalizeFractionalSeconds(data: String): String = {
+    // match ".ffffff" after seconds, keep at most 3 digits
+    data.replaceAll("""(\.\d{3})\d+""", "$1")

Review Comment:
   Thoughts on normalizing the XMLGregorianCalendar after it's parsed, instead 
of pre-processing the string? I can't think of a case where this regex will do 
the wrong thing, but it feels like it woudl be safer and more clear to do it 
after being parsed, e.g.:
    
   ```scala
   private def normalizeFractionalSeconds(cal: XMLGregorianCalendar): String = {
     val frac = cal.getFractionalSeconds()
     if (frac != null) {
       cal.setFractionalSeconds(frac.setScale(3, RoundingMode.DOWN))
     }
   }
   ```
   It's a bit more verbose, but it feels a bit more clear that it's normalizing 
the fractional seconds.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to