Skip to content

Commit 4a99da4

Browse files
committed
Change DateTime to ZonedDateTime
1 parent f3c3a7b commit 4a99da4

11 files changed

+65
-28
lines changed

Project.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ Neo4j = "d2adbeaf-5838-5367-8a2f-e46d570981db"
1717
Reexport = "189a3867-3050-52da-a836-e630ba90ab69"
1818
Requires = "ae029012-a4dd-5104-9daa-d747884805df"
1919
SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"
20+
TimeZones = "f269a46b-ccf7-5d73-abea-4c690281aa53"
2021
UUIDs = "cf7118a7-6976-5b1a-9a39-7adc72f591a4"
2122
Unmarshal = "cbff2730-442d-58d7-89d1-8e530c41eb02"
2223

src/Deprecated.jl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,13 @@
77
## Remove in 0.10
88
##==============================================================================
99

10+
# temporary promote with warning
11+
Base.promote_rule(::Type{DateTime}, ::Type{ZonedDateTime}) = DateTime
12+
function Base.convert(::Type{DateTime}, ts::ZonedDateTime)
13+
@warn "DFG now uses ZonedDateTime, temporary promoting and converting to DateTime local time"
14+
return DateTime(ts, Local)
15+
end
16+
1017
export listSolvekeys
1118

1219
@deprecate listSolvekeys(x...) listSolveKeys(x...)

src/DistributedFactorGraphs.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ using Base
1818
using DocStringExtensions
1919
using Requires
2020
using Dates
21+
using TimeZones
2122
using Distributions
2223
using Reexport
2324
using JSON

src/entities/DFGFactor.jl

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ struct DFGFactor{T, N} <: AbstractDFGFactor
106106
label::Symbol
107107
"""Variable timestamp.
108108
Accessors: [`getTimestamp`](@ref), [`setTimestamp`](@ref)"""
109-
timestamp::DateTime
109+
timestamp::ZonedDateTime
110110
"""Nano second time, for more resolution on timestamp (only subsecond information)"""
111111
nstime::Nanosecond
112112
"""Factor tags, e.g [:FACTOR].
@@ -122,14 +122,21 @@ struct DFGFactor{T, N} <: AbstractDFGFactor
122122
Accessors: [`getVariableOrder`](@ref)"""
123123
_variableOrderSymbols::NTuple{N,Symbol}
124124
# Inner constructor
125-
DFGFactor{T}(label::Symbol,
126-
timestamp::DateTime,
125+
function DFGFactor{T}(label::Symbol,
126+
timestamp::Union{DateTime,ZonedDateTime},
127127
nstime::Nanosecond,
128128
tags::Set{Symbol},
129129
solverData::GenericFunctionNodeData{T},
130130
solvable::Int,
131-
_variableOrderSymbols::NTuple{N,Symbol}) where {T,N} =
132-
new{T,N}(label, timestamp, nstime, tags, Ref(solverData), Ref(solvable), _variableOrderSymbols)
131+
_variableOrderSymbols::NTuple{N,Symbol}) where {T,N}
132+
133+
#TODO Deprecate remove in v0.10.
134+
if timestamp isa DateTime
135+
Base.depwarn("DFGFactor timestamp field is now a ZonedTimestamp", :DFGFactor)
136+
return new{T,N}(label, ZonedDateTime(timestamp, localzone()), nstime, tags, Ref(solverData), Ref(solvable), _variableOrderSymbols)
137+
end
138+
return new{T,N}(label, timestamp, nstime, tags, Ref(solverData), Ref(solvable), _variableOrderSymbols)
139+
end
133140

134141
end
135142

@@ -142,7 +149,7 @@ $(SIGNATURES)
142149
Construct a DFG factor given a label.
143150
"""
144151
DFGFactor(label::Symbol,
145-
timestamp::DateTime,
152+
timestamp::Union{DateTime,ZonedDateTime},
146153
nstime::Nanosecond,
147154
tags::Set{Symbol},
148155
solverData::GenericFunctionNodeData{T},
@@ -151,15 +158,15 @@ DFGFactor(label::Symbol,
151158
DFGFactor{T}(label, timestamp, nstime, tags, solverData, solvable, _variableOrderSymbols)
152159

153160

154-
DFGFactor{T}(label::Symbol, variableOrderSymbols::Vector{Symbol}, timestamp::DateTime=now(), data::GenericFunctionNodeData{T} = GenericFunctionNodeData{T}()) where {T} =
161+
DFGFactor{T}(label::Symbol, variableOrderSymbols::Vector{Symbol}, timestamp::Union{DateTime,ZonedDateTime}=now(localzone()), data::GenericFunctionNodeData{T} = GenericFunctionNodeData{T}()) where {T} =
155162
DFGFactor(label, timestamp, Nanosecond(0), Set{Symbol}(), data, 1, Tuple(variableOrderSymbols))
156163

157164

158165
DFGFactor(label::Symbol,
159166
variableOrderSymbols::Vector{Symbol},
160167
data::GenericFunctionNodeData{T};
161168
tags::Set{Symbol}=Set{Symbol}(),
162-
timestamp::DateTime=now(),
169+
timestamp::Union{DateTime,ZonedDateTime}=now(localzone()),
163170
solvable::Int=1,
164171
nstime::Nanosecond = Nanosecond(0)) where {T} =
165172
DFGFactor{T}(label, timestamp, nstime, tags, data, solvable, Tuple(variableOrderSymbols))
@@ -179,6 +186,10 @@ end
179186
Base.setproperty!(x::DFGFactor,f::Symbol, val) = begin
180187
if f == :solvable || f == :solverData
181188
getfield(x,f)[] = val
189+
elseif f == :timestamp && val isa DateTime
190+
# #TODO Deprecation - Remove in v0.10
191+
Base.depwarn("DFGFactor timestamp field is now a ZonedTimestamp", :setproperty!)
192+
setfield!(x,:timestamp, ZonedDateTime(val, localzone()))
182193
else
183194
setfield!(x,f,val)
184195
end
@@ -201,7 +212,7 @@ struct DFGFactorSummary <: AbstractDFGFactor
201212
label::Symbol
202213
"""Variable timestamp.
203214
Accessors: [`getTimestamp`](@ref)"""
204-
timestamp::DateTime
215+
timestamp::ZonedDateTime
205216
"""Factor tags, e.g [:FACTOR].
206217
Accessors: [`getTags`](@ref), [`mergeTags!`](@ref), and [`removeTags!`](@ref)"""
207218
tags::Set{Symbol}

src/entities/DFGVariable.jl

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ struct DFGVariable{T<:InferenceVariable} <: AbstractDFGVariable
184184
label::Symbol
185185
"""Variable timestamp.
186186
Accessors: [`getTimestamp`](@ref), [`setTimestamp`](@ref)"""
187-
timestamp::DateTime
187+
timestamp::ZonedDateTime
188188
"""Nano second time, for more resolution on timestamp (only subsecond information)"""
189189
nstime::Nanosecond
190190
"""Variable tags, e.g [:POSE, :VARIABLE, and :LANDMARK].
@@ -215,7 +215,7 @@ end
215215
The default DFGVariable constructor.
216216
"""
217217
DFGVariable(label::Symbol, softtype::T;
218-
timestamp::DateTime=now(),
218+
timestamp::Union{DateTime,ZonedDateTime}=now(localzone()),
219219
nstime::Nanosecond = Nanosecond(0),
220220
tags::Set{Symbol}=Set{Symbol}(),
221221
estimateDict::Dict{Symbol, <: AbstractPointParametricEst}=Dict{Symbol, MeanMaxPPE}(),
@@ -228,7 +228,7 @@ DFGVariable(label::Symbol, softtype::T;
228228

229229
DFGVariable(label::Symbol,
230230
solverData::VariableNodeData{T};
231-
timestamp::DateTime=now(),
231+
timestamp::Union{DateTime,ZonedDateTime}=now(localzone()),
232232
nstime::Nanosecond = Nanosecond(0),
233233
tags::Set{Symbol}=Set{Symbol}(),
234234
estimateDict::Dict{Symbol, <: AbstractPointParametricEst}=Dict{Symbol, MeanMaxPPE}(),
@@ -244,6 +244,10 @@ Base.getproperty(x::DFGVariable,f::Symbol) = begin
244244
elseif f == :bigData
245245
Base.depwarn("DFGVariable field bigData is deprecated, use `dataDict` instead",:getproperty)
246246
getfield(x,:dataDict)
247+
# elseif f == :timestamp
248+
# #TODO Deprecation - Remove in v0.10
249+
# Base.depwarn("DFGVariable timestamp field is now a ZonedTimestamp, use accessors to prevent breaking changes",:getproperty)
250+
# getfield(x,:timestamp)
247251
else
248252
getfield(x,f)
249253
end
@@ -254,8 +258,12 @@ Base.setproperty!(x::DFGVariable,f::Symbol, val) = begin
254258
getfield(x,f)[] = val
255259
elseif f == :bigData
256260
#TODO Deprecation - Remove in v0.10
257-
Base.depwarn("DFGVariable field bigData is deprecated, use `dataDict` instead",:setproperty!)
258-
setfield(x, :dataDict)
261+
Base.depwarn("DFGVariable field bigData is deprecated, use `dataDict` instead", :setproperty!)
262+
setfield(x, :dataDict, val)
263+
elseif f == :timestamp && val isa DateTime
264+
# #TODO Deprecation - Remove in v0.10
265+
Base.depwarn("DFGVariable timestamp field is now a ZonedTimestamp", :setproperty!)
266+
setfield!(x,:timestamp, ZonedDateTime(val, localzone()))
259267
else
260268
setfield!(x,f,val)
261269
end
@@ -288,7 +296,7 @@ struct DFGVariableSummary <: AbstractDFGVariable
288296
label::Symbol
289297
"""Variable timestamp.
290298
Accessors: [`getTimestamp`](@ref), [`setTimestamp`](@ref)"""
291-
timestamp::DateTime
299+
timestamp::ZonedDateTime
292300
"""Variable tags, e.g [:POSE, :VARIABLE, and :LANDMARK].
293301
Accessors: [`getTags`](@ref), [`mergeTags!`](@ref), and [`removeTags!`](@ref)"""
294302
tags::Set{Symbol}

src/services/AbstractDFG.jl

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -766,14 +766,15 @@ end
766766
##==============================================================================
767767
## Finding
768768
##==============================================================================
769-
769+
# function findClosestTimestamp(setA::Vector{Tuple{DateTime,T}},
770+
# setB::Vector{Tuple{DateTime,S}}) where {S,T}
770771
"""
771772
$SIGNATURES
772773
773774
Find and return the closest timestamp from two sets of Tuples. Also return the minimum delta-time (`::Millisecond`) and how many elements match from the two sets are separated by the minimum delta-time.
774775
"""
775-
function findClosestTimestamp(setA::Vector{Tuple{DateTime,T}},
776-
setB::Vector{Tuple{DateTime,S}}) where {S,T}
776+
function findClosestTimestamp(setA::Vector{Tuple{ZonedDateTime,T}},
777+
setB::Vector{Tuple{ZonedDateTime,S}}) where {S,T}
777778
#
778779
# build matrix of delta times, ranges on rows x vars on columns
779780
DT = Array{Millisecond, 2}(undef, length(setA), length(setB))
@@ -813,7 +814,7 @@ Related
813814
ls, listVariables, findClosestTimestamp
814815
"""
815816
function findVariableNearTimestamp(dfg::AbstractDFG,
816-
timest::DateTime,
817+
timest::ZonedDateTime,
817818
regexFilter::Union{Nothing, Regex}=nothing;
818819
tags::Vector{Symbol}=Symbol[],
819820
solvable::Int=0,
@@ -853,6 +854,10 @@ function findVariableNearTimestamp(dfg::AbstractDFG,
853854
return RET
854855
end
855856

857+
findVariableNearTimestamp(dfg::AbstractDFG, timest::DateTime, regexFilter::Union{Nothing, Regex}=nothing;
858+
timezone=localzone(), kwargs...) =
859+
findVariableNearTimestamp(dfg, ZonedDateTime(timest, timezone), regexFilter; kwargs...)
860+
856861
##==============================================================================
857862
## Copy Functions
858863
##==============================================================================

src/services/DFGFactor.jl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,12 +67,13 @@ end
6767
## COMMON
6868
# getTimestamp
6969

70+
setTimestamp(f::AbstractDFGFactor, ts::DateTime, timezone=localzone()) = setTimestamp(f, ZonedDateTime(ts, timezone))
7071

71-
function setTimestamp(f::DFGFactor, ts::DateTime)
72+
function setTimestamp(f::DFGFactor, ts::ZonedDateTime)
7273
return DFGFactor(f.label, ts, f.nstime, f.tags, f.solverData, f.solvable, getfield(f,:_variableOrderSymbols))
7374
end
7475

75-
function setTimestamp(f::DFGFactorSummary, ts::DateTime)
76+
function setTimestamp(f::DFGFactorSummary, ts::ZonedDateTime)
7677
return DFGFactorSummary(f.label, ts, f.tags, f._variableOrderSymbols)
7778
end
7879

src/services/DFGVariable.jl

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,14 +162,16 @@ Since the `timestamp` field is not mutable `setTimestamp` returns a new variable
162162
Use [`updateVariable!`](@ref) on the returened variable to update it in the factor graph if needed. Alternatively use [`setTimestamp!`](@ref).
163163
See issue #315.
164164
"""
165-
function setTimestamp(v::DFGVariable, ts::DateTime; verbose::Bool=true)
165+
function setTimestamp(v::DFGVariable, ts::ZonedDateTime; verbose::Bool=true)
166166
if verbose
167167
@warn "verbose=true: setTimestamp(::DFGVariable,...) creates a returns a new immutable DFGVariable object (and didn't change a distributed factor graph object), make sure you are using the right pointers: getVariable(...). See setTimestamp!(...) and note suggested use is at addVariable!(..., [timestamp=...]). See DFG #315 for explanation."
168168
end
169169
return DFGVariable(v.label, ts, v.nstime, v.tags, v.ppeDict, v.solverDataDict, v.smallData, v.dataDict, Ref(v.solvable))
170170
end
171171

172-
function setTimestamp(v::DFGVariableSummary, ts::DateTime; verbose::Bool=true)
172+
setTimestamp(v::AbstractDFGVariable, ts::DateTime, timezone=localzone(); verbose::Bool=true) = setTimestamp(v, ZonedDateTime(ts, timezone); verbose=verbose)
173+
174+
function setTimestamp(v::DFGVariableSummary, ts::ZonedDateTime; verbose::Bool=true)
173175
if verbose
174176
@warn "verbose=true: setTimestamp(::DFGVariableSummary,...) creates and returns a new immutable DFGVariable object (and didn't change a distributed factor graph object), make sure you are using the right pointers: getVariable(...). See setTimestamp!(...) and note suggested use is at addVariable!(..., [timestamp=...]). See DFG #315 for explanation."
175177
end

src/services/Serialization.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ end
2525

2626
function unpackVariable(dfg::G, packedProps::Dict{String, Any})::DFGVariable where G <: AbstractDFG
2727
label = Symbol(packedProps["label"])
28-
timestamp = DateTime(packedProps["timestamp"])
28+
timestamp = ZonedDateTime(packedProps["timestamp"])
2929
nstime = Nanosecond(get(packedProps, "nstime", 0))
3030
tags = JSON2.read(packedProps["tags"], Vector{Symbol})
3131
#TODO this will work for some time, but unpacking in an <: AbstractPointParametricEst would be lekker.
@@ -151,7 +151,7 @@ end
151151

152152
function unpackFactor(dfg::G, packedProps::Dict{String, Any})::DFGFactor where G <: AbstractDFG
153153
label = packedProps["label"]
154-
timestamp = DateTime(packedProps["timestamp"])
154+
timestamp = ZonedDateTime(packedProps["timestamp"])
155155
nstime = Nanosecond(get(packedProps, "nstime", 0))
156156
tags = JSON2.read(packedProps["tags"], Vector{Symbol})
157157

test/LightDFGSummaryTypes.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33
# FACTYPE = DFGFactorSummary
44

55
dfg = LightDFG{NoSolverParams, VARTYPE, FACTYPE}()
6-
DistributedFactorGraphs.DFGVariableSummary(label::Symbol) = DFGVariableSummary(label, DistributedFactorGraphs.now(), Set{Symbol}(), Dict{Symbol, MeanMaxPPE}(), :Pose2, Dict{Symbol,AbstractDataEntry}())
7-
DistributedFactorGraphs.DFGFactorSummary(label::Symbol) = DFGFactorSummary(label, DistributedFactorGraphs.now(), Set{Symbol}(), Symbol[])
6+
DistributedFactorGraphs.DFGVariableSummary(label::Symbol) = DFGVariableSummary(label, DistributedFactorGraphs.now(localzone()), Set{Symbol}(), Dict{Symbol, MeanMaxPPE}(), :Pose2, Dict{Symbol,AbstractDataEntry}())
7+
DistributedFactorGraphs.DFGFactorSummary(label::Symbol) = DFGFactorSummary(label, DistributedFactorGraphs.now(localzone()), Set{Symbol}(), Symbol[])
88

9-
DistributedFactorGraphs.DFGVariableSummary(label::Symbol, ::VariableNodeData{T}) where T = DFGVariableSummary(label, DistributedFactorGraphs.now(), Set{Symbol}(), Dict{Symbol, MeanMaxPPE}(), Symbol(T), Dict{Symbol,AbstractDataEntry}())
9+
DistributedFactorGraphs.DFGVariableSummary(label::Symbol, ::VariableNodeData{T}) where T = DFGVariableSummary(label, DistributedFactorGraphs.now(localzone()), Set{Symbol}(), Dict{Symbol, MeanMaxPPE}(), Symbol(T), Dict{Symbol,AbstractDataEntry}())
1010
DistributedFactorGraphs.SkeletonDFGVariable(label::Symbol, args...) = SkeletonDFGVariable(label)
1111

1212

0 commit comments

Comments
 (0)