Skip to content

Commit bcdc685

Browse files
committed
fix string --> ZonedDateTime millisecond issues,
copy #588, help fix #560
1 parent 3a0e22a commit bcdc685

File tree

1 file changed

+39
-3
lines changed

1 file changed

+39
-3
lines changed

src/services/Serialization.jl

Lines changed: 39 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,40 @@ function packVariable(dfg::G, v::DFGVariable)::Dict{String, Any} where G <: Abst
3232
return props
3333
end
3434

35+
# Corrects any `::ZonedDateTime` fields of T in corresponding `interm::Dict` as `dateformat"yyyy-mm-ddTHH:MM:SS.ssszzz"`
36+
function standardizeZDTString!(T, interm::Dict)
37+
@debug "About to look through types of" T
38+
for (name, typ) in zip(fieldnames(T), T.types)
39+
# @debug "name=$name"
40+
# @debug "typ=$typ"
41+
if typ <: ZonedDateTime
42+
# Make sure that the timestamp is correctly formatted with subseconds
43+
namestr = string(name)
44+
@debug "must ensure SS.ssszzz on $name :: $typ -- $(interm[namestr])"
45+
# # FIXME copy #588, but doesnt work: https://github.com/JuliaRobotics/DistributedFactorGraphs.jl/issues/582#issuecomment-671884668
46+
# # E.g.: interm[namestr] = replace(interm[namestr], r":(\d)(\d)(Z|z|\+|-)" => s":\1\2.000\3") = "2020-08-11T04:05:59.82-04:00"
47+
# @show interm[namestr] = replace(interm[namestr], r":(\d)(\d)(Z|z|\+|-)" => s":\1\2.000\3")
48+
# @debug "after SS.ssszzz -- $(interm[namestr])"
49+
## DROP piece below once this cleaner copy #588 is working
50+
supersec, subsec = split(interm[namestr], '.')
51+
sss, zzz = split(subsec, '-')
52+
# @debug "split time elements are $sss-$zzz"
53+
# make sure milliseconds portion is precisely 3 characters long
54+
if length(sss) < 3
55+
# pad with zeros at the end
56+
while length(sss) < 3
57+
sss *= "0"
58+
end
59+
newtimessszzz = supersec*"."*sss*"-"*zzz
60+
@debug "new time string: $newtimessszzz"
61+
# reassembled ZonedDateTime is put back in the dict
62+
interm[namestr] = newtimessszzz
63+
end
64+
end
65+
end
66+
nothing
67+
end
68+
3569
function unpackVariable(dfg::G,
3670
packedProps::Dict{String, Any};
3771
unpackPPEs::Bool=true,
@@ -85,10 +119,12 @@ function unpackVariable(dfg::G,
85119
end
86120

87121
for (k,bdeInter) in dataIntermed
88-
@show label
89-
@show bdeInter
122+
# @debug "label=$label"
123+
# @debug "bdeInter=$bdeInter"
90124
interm = JSON.parse(bdeInter)
91-
Unmarshal.unmarshal(getfield(DistributedFactorGraphs, dataElemTypes[k]), interm)
125+
objType = getfield(DistributedFactorGraphs, dataElemTypes[k])
126+
standardizeZDTString!(objType, interm)
127+
fullVal = Unmarshal.unmarshal(objType, interm)
92128
variable.dataDict[k] = fullVal
93129
end
94130
end

0 commit comments

Comments
 (0)