Skip to content

Commit 167e023

Browse files
authored
Timestamp, serialization, and deprecated cleanup (#1203)
1 parent 4ce4d21 commit 167e023

File tree

13 files changed

+122
-729
lines changed

13 files changed

+122
-729
lines changed

Project.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ RecursiveArrayTools = "731186ca-8d62-57ce-b412-fbd966d074cd"
2323
SHA = "ea8e919c-243c-51af-8825-aaa63cd721ce"
2424
SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"
2525
StaticArrays = "90137ffa-7385-5640-81b9-e52037218182"
26+
StructUtils = "ec057cc2-7a8d-4b58-b3b3-92acb9f63b42"
2627
Tables = "bd369af6-aec1-5ad0-b16a-f7cc5008161c"
2728
Tar = "a4e569a6-e804-4fa4-b0f3-eef7a1d5b13e"
2829
TensorCast = "02d47bb6-7ce6-556a-be16-bb1710789e2b"
@@ -64,6 +65,7 @@ SHA = "0.7, 1"
6465
SparseArrays = "1.11"
6566
StaticArrays = "1"
6667
Statistics = "1.11"
68+
StructUtils = "2.6.0"
6769
Tables = "1.11.1"
6870
Tar = "1.9"
6971
TensorCast = "0.3.3, 0.4"

docs/make.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ makedocs(;
1919
],
2020
"Reference" => ["func_ref.md", "services_ref.md", "blob_ref.md"],
2121
],
22+
checkdocs = :public,
2223
# warnonly=[:doctest],
23-
# checkdocs=:none,
2424
# html_prettyurls = !("local" in ARGS),
2525
)
2626

docs/src/GraphData.md

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,19 @@ Labels are the principle identifier of a variable or factor.
4444

4545
#### Timestamps
4646

47-
Each variable or factor can have a timestamp associated with it.
47+
Each variable or factor can have a timestamp associated with it representing when the physical event/observation occurred.
48+
49+
**Time Standard**: Timestamps use UTC-based time (Coordinated Universal Time) via the `TimeDateZone` type, not TAI (International Atomic Time). The key difference is that UTC includes leap seconds to keep synchronized with Earth's rotation, while TAI is a continuous monotonic time scale without leap seconds.
50+
51+
**Timezone Support**: While timestamps default to UTC (`tz"UTC"`), `TimeDateZone` supports any timezone (e.g., `tz"America/New_York"`, `tz"Europe/London"`). The timezone offset is preserved when stored and retrieved.
52+
53+
**Event Time vs Database Time**: The timestamp represents the physical event time (when a sensor measurement was taken, when a robot was at a pose, etc.), not when the variable was added to the database. Database metadata timestamps may be tracked separately by specific backend implementations.
54+
55+
**Temporal Uncertainty**: This single timestamp value is metadata and does not represent temporal uncertainty. For problems where time itself is a state variable requiring inference (e.g., using `SGal3` which includes temporal components), include time as part of your state type rather than relying on this metadata field. Furthermore, the concept of "ClockPriors" is also at play for the API design changes relating to v2.
56+
57+
**Future**: changing away from field name `timestamp` was deferred from v1.0 owing to resolution of older complexity of other fields being standardized; however, the desire for a better name exists and should be revisited in the v2 API. At time of writing, the best summary of the naming debate is captured here: https://github.com/JuliaRobotics/DistributedFactorGraphs.jl/issues/1087#issuecomment-3582252305. In the lead up to a new long term release (a.k.a semver major), a deprecation cycle will be used via semver minors to ensure users have an easy and macro-aided transition in the API.
58+
59+
Related functions:
4860

4961
- [`getTimestamp`](@ref)
5062

src/Common.jl

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,20 @@ function calcDeltatime(from::TimeDateZone, to::TimeDateZone)
187187
end
188188
calcDeltatime(from_node, to_node) = calcDeltatime(from_node.timestamp, to_node.timestamp)
189189

190-
function tdz_now(zone = tz"UTC") #TODO or default to slower localzone()?
190+
Timestamp(args...) = TimeDateZone(args...)
191+
Timestamp(t::Nanosecond, zone = tz"UTC") = Timestamp(Val(:unix), t, zone)
192+
function Timestamp(epoch::Val{:unix}, t::Nanosecond, zone = tz"UTC")
193+
return TimeDateZone(TimeDate(1970) + t, zone)
194+
end
195+
function Timestamp(epoch::Val{:unix}, t::Float64, zone = tz"UTC")
196+
return Timestamp(epoch, Nanosecond(t * 10^9), zone)
197+
end
198+
Timestamp(t::Float64, zone = tz"UTC") = Timestamp(Val(:unix), t, zone)
199+
function Timestamp(epoch::Val{:rata}, t::Float64, zone = tz"UTC")
200+
return TimeDateZone(convert(DateTime, Millisecond(t*10^3)), zone)
201+
end
202+
203+
function now_tdz(zone = tz"UTC")
191204
t = time()
192-
return TimeDateZone(TimeDate(1970) + Nanosecond(t * 10^9), zone)
205+
return Timestamp(t, zone)
193206
end

src/DataBlobs/entities/BlobEntry.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ StructUtils.@kwarg struct Blobentry
4444
""" Storage for a couple of bytes directly in the graph. Use with caution and keep it small and simple."""
4545
metadata::JSONText = JSONText("{}")
4646
""" When the Blob itself was first created. Serialized as an ISO 8601 string."""
47-
timestamp::TimeDateZone = tdz_now()
47+
timestamp::TimeDateZone = now_tdz()
4848
""" Type version of this Blobentry."""
4949
version::VersionNumber = DFG.version(Blobentry)
5050
end

0 commit comments

Comments
 (0)