@@ -305,16 +305,24 @@ def apply_diffs_to_file(self, infile: str, outfile: str, start_id: int,
305305 return (diffs .id , diffs .newest )
306306
307307 def timestamp_to_sequence (self , timestamp : dt .datetime ,
308- balanced_search : bool = False ) -> Optional [int ]:
308+ balanced_search : bool = False ,
309+ limit_by_oldest_available : bool = False ) -> Optional [int ]:
309310 """ Get the sequence number of the replication file that contains the
310311 given timestamp. The search algorithm is optimised for replication
311312 servers that publish updates in regular intervals. For servers
312313 with irregular change file publication dates 'balanced_search`
313314 should be set to true so that a standard binary search for the
314315 sequence will be used. The default is good for all known
315316 OSM replication services.
316- """
317317
318+ When `limit_by_oldest_available` is set, then the function will
319+ return None when the server replication does not start at 0 and
320+ the given timestamp is older than the oldest available timestamp
321+ on the server. Some replication servers do not keep the full
322+ history and this flag avoids accidentally trying to download older
323+ data. The downside is that the function will never return the
324+ oldest available sequence ID when the flag is set.
325+ """
318326 # get the current timestamp from the server
319327 upper = self .get_state_info ()
320328
@@ -331,8 +339,10 @@ def timestamp_to_sequence(self, timestamp: dt.datetime,
331339 lower = self .get_state_info (lowerid )
332340
333341 if lower is not None and lower .timestamp >= timestamp :
334- if lower .sequence == 0 or lower .sequence + 1 >= upper .sequence :
335- return lower .sequence
342+ if lower .sequence == 0 :
343+ return 0
344+ if lower .sequence + 1 >= upper .sequence :
345+ return None if limit_by_oldest_available else lower .sequence
336346 upper = lower
337347 lower = None
338348 lowerid = 0
0 commit comments