1.1 --- a/imiptools/data.py Sun Feb 01 19:59:29 2015 +0100
1.2 +++ b/imiptools/data.py Sun Feb 01 21:02:53 2015 +0100
1.3 @@ -223,4 +223,28 @@
1.4 def uri_items(items):
1.5 return [(get_uri(value), attr) for value, attr in items]
1.6
1.7 +# Operations on structure data.
1.8 +
1.9 +def is_new_object(old_sequence, new_sequence, old_dtstamp, new_dtstamp, partstat_set):
1.10 +
1.11 + """
1.12 + Return for the given 'old_sequence' and 'new_sequence', 'old_dtstamp' and
1.13 + 'new_dtstamp', and the 'partstat_set' indication, whether the object
1.14 + providing the new information is really newer than the object providing the
1.15 + old information.
1.16 + """
1.17 +
1.18 + have_sequence = old_sequence is not None and new_sequence is not None
1.19 + is_same_sequence = have_sequence and int(new_sequence) == int(old_sequence)
1.20 +
1.21 + have_dtstamp = old_dtstamp and new_dtstamp
1.22 + is_old_dtstamp = have_dtstamp and new_dtstamp < old_dtstamp or old_dtstamp and not new_dtstamp
1.23 +
1.24 + is_old_sequence = have_sequence and (
1.25 + int(new_sequence) < int(old_sequence) or
1.26 + is_same_sequence and is_old_dtstamp
1.27 + )
1.28 +
1.29 + return is_same_sequence and partstat_set or not is_old_sequence
1.30 +
1.31 # vim: tabstop=4 expandtab shiftwidth=4