diff options
author | Justus Winter <justus@sequoia-pgp.org> | 2020-01-15 16:09:03 +0100 |
---|---|---|
committer | Justus Winter <justus@sequoia-pgp.org> | 2020-01-15 16:09:03 +0100 |
commit | 8a8ff96444cf135bb4c3422af4598685b56df572 (patch) | |
tree | b4874c71f41bef95cc9afbc42183aa373b58cbb6 /openpgp/src/types/timestamp.rs | |
parent | d5356427bdf765a8e6f56d05dc049ae71760998b (diff) |
openpgp: Implement addition and subtraction of durations.
Diffstat (limited to 'openpgp/src/types/timestamp.rs')
-rw-r--r-- | openpgp/src/types/timestamp.rs | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/openpgp/src/types/timestamp.rs b/openpgp/src/types/timestamp.rs index 168625c4..1706426c 100644 --- a/openpgp/src/types/timestamp.rs +++ b/openpgp/src/types/timestamp.rs @@ -57,6 +57,22 @@ impl Timestamp { .expect("representable for the next hundred years") } + /// Adds a duration to this timestamp. + /// + /// Returns `None` if the resulting timestamp is not + /// representable. + pub fn checked_add(&self, d: Duration) -> Option<Timestamp> { + self.0.checked_add(d.0).map(|v| Self(v)) + } + + /// Subtracts a duration from this timestamp. + /// + /// Returns `None` if the resulting timestamp is not + /// representable. + pub fn checked_sub(&self, d: Duration) -> Option<Timestamp> { + self.0.checked_sub(d.0).map(|v| Self(v)) + } + /// Rounds down to the given level of precision. /// /// This can be used to reduce the metadata leak resulting from |