stevedlawrence commented on a change in pull request #157: Add support for type
aware checking in the TDML runner
URL: https://github.com/apache/incubator-daffodil/pull/157#discussion_r241905880
##########
File path:
daffodil-runtime1/src/main/scala/org/apache/daffodil/dpath/DFDLFunctions.scala
##########
@@ -114,10 +114,20 @@ case class DFDLTimeZoneFromDFDLCalendar(recipe:
CompiledDPath, argType: NodeInfo
extends FNOneArg(recipe, argType) {
override def computeValue(value: AnyRef, dstate: DState) = {
- val calendar = value.asInstanceOf[DFDLCalendar]
-
- val res = if (calendar.hasTimeZone) { calendar.getTimeZoneString } else {
"" }
- res
+ val dfdlcal = value.asInstanceOf[DFDLCalendar]
+ if (dfdlcal.hasTimeZone) {
+ val tz = dfdlcal.calendar.getTimeZone
+ val offsetInMils = tz.getRawOffset
+ val offsetInMins = Math.abs(offsetInMils / (1000 * 60))
+ val hour = offsetInMins / 60
+ val mins = offsetInMins % 60
+
+ val signStr = if (offsetInMils >= 0) "+" else "-"
+ val hourStr = if (hour < 10) "0" + hour else hour
+ val minsStr = if (mins < 10) "0" + mins else mins
+
+ signStr + hourStr + ":" + minsStr
Review comment:
This is actually for the output of the
``dfdl:timeZoneFrom{Date,TIme,DateTIme}`` XPath functions, which according to
the spec should always output +00:00 for the GMT time.
The place to change what we output to an infoset is in
DFDLCalendarConversions.scala, which uses some SimpleDateFormats for outputting
the timezone. So we'd just need to change thepattern from 'xxx' to 'XXX'.
That said, this conversion code should probably be in the
DFDLCalendarConversions stuff. And it probably would be a good idea to stop
using SimpleDateFormats for creating the output. SimpleDateFOrmat's are not
thread safe and way heavier than what we need. I don't think it would be too
difficult to do something like the above for dates and times too. I'll refactor
that toXMLString stuff to not require SImpelDateTIme's and todo somethine more
like above.
----------------------------------------------------------------
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