public inbox for pbs-devel@lists.proxmox.com
 help / color / mirror / Atom feed
From: Dominik Csapak <d.csapak@proxmox.com>
To: pbs-devel@lists.proxmox.com
Subject: [pbs-devel] [PATCH proxmox-backup 04/10] tools/systemd/tm_editor: remove reset_time from add_days and document it
Date: Thu,  3 Sep 2020 13:39:54 +0200	[thread overview]
Message-ID: <20200903114000.6932-5-d.csapak@proxmox.com> (raw)
In-Reply-To: <20200903114000.6932-1-d.csapak@proxmox.com>

we never passed 'false' to it anyway so remove it
(we can add it again if we should ever need it)

also remove the adding of wday (gets normalized anyway)
and set changes to all, since adding days can wrap the month and year too
(all other fields get set by us here explicitely)

Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
---
 src/tools/systemd/time.rs      |  6 +++---
 src/tools/systemd/tm_editor.rs | 15 ++++++---------
 2 files changed, 9 insertions(+), 12 deletions(-)

diff --git a/src/tools/systemd/time.rs b/src/tools/systemd/time.rs
index 6c7cefec..b6899b0c 100644
--- a/src/tools/systemd/time.rs
+++ b/src/tools/systemd/time.rs
@@ -183,10 +183,10 @@ pub fn compute_next_event(
                     .find(|d| event.days.contains(WeekDays::from_bits(1<<d).unwrap()))
                 {
                     // try next day
-                    t.add_days(n - day_num, true)?;
+                    t.add_days(n - day_num,)?;
                 } else {
                     // try next week
-                    t.add_days(7 - day_num, true)?;
+                    t.add_days(7 - day_num)?;
                 }
                 continue;
             }
@@ -203,7 +203,7 @@ pub fn compute_next_event(
                     t.set_time(n as libc::c_int, 0, 0)?;
                 } else {
                     // test next day
-                    t.add_days(1, true)?;
+                    t.add_days(1)?;
                 }
                 continue;
             }
diff --git a/src/tools/systemd/tm_editor.rs b/src/tools/systemd/tm_editor.rs
index 62f8d1d0..a1cf2464 100644
--- a/src/tools/systemd/tm_editor.rs
+++ b/src/tools/systemd/tm_editor.rs
@@ -36,17 +36,14 @@ impl TmEditor {
         Ok(epoch)
     }
 
-    pub fn add_days(&mut self, days: libc::c_int, reset_time: bool) -> Result<(), Error> {
+    /// increases the day by 'days' and resets all smaller fields to their minimum
+    pub fn add_days(&mut self, days: libc::c_int) -> Result<(), Error> {
         if days == 0 { return Ok(()); }
-        if reset_time {
-            self.t.tm_hour = 0;
-            self.t.tm_min = 0;
-            self.t.tm_sec = 0;
-            self.changes.insert(TMChanges::HOUR|TMChanges::MIN|TMChanges::SEC);
-        }
+        self.t.tm_hour = 0;
+        self.t.tm_min = 0;
+        self.t.tm_sec = 0;
         self.t.tm_mday += days;
-        self.t.tm_wday += days;
-        self.changes.insert(TMChanges::MDAY|TMChanges::WDAY);
+        self.changes = TMChanges::all(); // adding a day can wrap the month/year too
         self.normalize_time()
     }
 
-- 
2.20.1





  parent reply	other threads:[~2020-09-03 11:40 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-09-03 11:39 [pbs-devel] [PATCH proxmox-backup 00/10] implement dates for calendarevents Dominik Csapak
2020-09-03 11:39 ` [pbs-devel] [PATCH proxmox-backup 01/10] tools/systemd/time: let libc normalize time for us Dominik Csapak
2020-09-04  4:52   ` Dietmar Maurer
2020-09-04  4:57   ` Dietmar Maurer
2020-09-03 11:39 ` [pbs-devel] [PATCH proxmox-backup 02/10] tools/systemd/time: move continue out of the if/else Dominik Csapak
2020-09-03 11:39 ` [pbs-devel] [PATCH proxmox-backup 03/10] tools/systemd/time: convert the resulting timestamp into an option Dominik Csapak
2020-09-03 11:39 ` Dominik Csapak [this message]
2020-09-04  5:12   ` [pbs-devel] [PATCH proxmox-backup 04/10] tools/systemd/tm_editor: remove reset_time from add_days and document it Dietmar Maurer
2020-09-03 11:39 ` [pbs-devel] [PATCH proxmox-backup 05/10] tools/systemd/parse_time: error out on invalid ranges Dominik Csapak
2020-09-03 11:39 ` [pbs-devel] [PATCH proxmox-backup 06/10] tools/systemd/time: fix selection for multiple options Dominik Csapak
2020-09-03 11:39 ` [pbs-devel] [PATCH proxmox-backup 07/10] tools/systemd/time: use i32 for DateTimeValues instead of u32 Dominik Csapak
2020-09-04  5:31   ` Dietmar Maurer
2020-09-04  5:39   ` Dietmar Maurer
2020-09-03 11:39 ` [pbs-devel] [PATCH proxmox-backup 08/10] tools/systemd/tm_editor: remove conversion of the year Dominik Csapak
2020-09-03 11:39 ` [pbs-devel] [PATCH proxmox-backup 09/10] tools/systemd/tm_editor: add setter/getter for months/years/days Dominik Csapak
2020-09-03 11:40 ` [pbs-devel] [PATCH proxmox-backup 10/10] tools/systemd/time: enable dates for calendarevents Dominik Csapak

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200903114000.6932-5-d.csapak@proxmox.com \
    --to=d.csapak@proxmox.com \
    --cc=pbs-devel@lists.proxmox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal