summaryrefslogtreecommitdiff
path: root/src/timestamp.rs
diff options
context:
space:
mode:
authorBotahamec <botahamec@outlook.com>2022-03-18 14:57:13 -0400
committerBotahamec <botahamec@outlook.com>2022-03-18 14:57:13 -0400
commitdb9f20681f90f206d393d2b06a6a8401515ff562 (patch)
tree48c16c94a4bf0da27c7cde56a247703b7794600c /src/timestamp.rs
parente0e0a18a4bc873583e973d771669e88a92b20d92 (diff)
Addition methods for NaiveDateTime
Diffstat (limited to 'src/timestamp.rs')
-rw-r--r--src/timestamp.rs24
1 files changed, 24 insertions, 0 deletions
diff --git a/src/timestamp.rs b/src/timestamp.rs
index ea8f2e1..c223ccb 100644
--- a/src/timestamp.rs
+++ b/src/timestamp.rs
@@ -26,6 +26,30 @@ impl UnixTimestamp {
}
#[must_use]
+ pub const fn add_days_overflowing(self, days: i64) -> (Self, bool) {
+ let (seconds, overflowing) = self.seconds.overflowing_add(days as i64 * 3600 * 24);
+
+ let timestamp = Self::new(seconds, self.nanoseconds);
+ (timestamp, overflowing)
+ }
+
+ #[must_use]
+ pub const fn add_hours_overflowing(self, hours: i64) -> (Self, bool) {
+ let (seconds, overflowing) = self.seconds.overflowing_add(hours as i64 * 3600);
+
+ let timestamp = Self::new(seconds, self.nanoseconds);
+ (timestamp, overflowing)
+ }
+
+ #[must_use]
+ pub const fn add_minutes_overflowing(self, minutes: i64) -> (Self, bool) {
+ let (seconds, overflowing) = self.seconds.overflowing_add(minutes as i64 * 60);
+
+ let timestamp = Self::new(seconds, self.nanoseconds);
+ (timestamp, overflowing)
+ }
+
+ #[must_use]
pub const fn add_seconds_overflowing(self, seconds: i64) -> (Self, bool) {
// TODO overflowing goes first
let (seconds, overflowing) = self.seconds.overflowing_add(seconds as i64);