Skip to content

Commit 969860c

Browse files
committed
Set timestamp on time-filter output file
If the input file has a timestamp set in the header and the specified *TO-TIME* is before that timestamp in the header, the header of the output file will have the timestamp set to the *TO-TIME* (or *TO-TIME* minus one second if a *FROM-TIME* was also set). See #285
1 parent 02b70f2 commit 969860c

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

man/osmium-time-filter.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@ This commands reads its input file only once and writes its output file
2929
in one go so it can be streamed, ie. it can read from STDIN and write to
3030
STDOUT.
3131

32+
If the input file has a timestamp set in the header and the specified *TO-TIME*
33+
is before that timestamp in the header, the header of the output file will have
34+
the timestamp set to the *TO-TIME* (or *TO-TIME* minus one second if a
35+
*FROM-TIME* was also set).
3236

3337
@MAN_COMMON_OPTIONS@
3438
@MAN_PROGRESS_OPTIONS@

src/command_time_filter.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,19 @@ bool CommandTimeFilter::run() {
134134

135135
m_vout << "Opening output file...\n";
136136
osmium::io::Header header{reader.header()};
137+
try {
138+
osmium::Timestamp const input_timestamp{header.get("osmosis_replication_timestamp")};
139+
if (input_timestamp.valid() && input_timestamp >= m_to) {
140+
auto ts = m_to;
141+
if (m_from != m_to) {
142+
ts -= 1;
143+
}
144+
m_vout << "Set output timestamp to " << ts.to_iso() << "\n";
145+
header.set("osmosis_replication_timestamp", ts.to_iso());
146+
}
147+
} catch (const std::invalid_argument&) { // NOLINT(bugprone-empty-catch)
148+
// Ignore unset or invalid timestamp from input file
149+
}
137150
setup_header(header);
138151

139152
osmium::io::Writer writer{m_output_file, header, m_output_overwrite, m_fsync};

0 commit comments

Comments
 (0)