aboutsummaryrefslogtreecommitdiff
path: root/apps/cassiopeia/src/time.rs
diff options
context:
space:
mode:
authorMx Kookie <kookie@spacekookie.de>2020-12-15 19:41:48 +0000
committerMx Kookie <kookie@spacekookie.de>2020-12-21 05:19:49 +0100
commitb9c988f42504c2e4cfa0715ac8f2d2a0db591cad (patch)
tree4850aba3bc43b7b303c4a1a3b6dd64a3f85e1df5 /apps/cassiopeia/src/time.rs
parent236cf191b90a428325c8c179d595d4b1cd36f776 (diff)
cassiopeia: finishing up version 0.3.0
This commit does kind of a lot to get cass(1) over the finish line. For one it implements all the CLI functions (well, almost all) with their respective parameters, and also creates a new `gen` module which uses the IR stream to generate a new file based on the old one, while updating header fields that need to be updated (currently only `version`). This version does nothing with the actual header values, and probably has a lot of bugs. More documentation will follow in future cassiopeia commits.
Diffstat (limited to '')
-rw-r--r--apps/cassiopeia/src/time.rs18
1 files changed, 14 insertions, 4 deletions
diff --git a/apps/cassiopeia/src/time.rs b/apps/cassiopeia/src/time.rs
index 4ac4ce7db900..0161742a0c92 100644
--- a/apps/cassiopeia/src/time.rs
+++ b/apps/cassiopeia/src/time.rs
@@ -27,12 +27,23 @@ impl<'t> Sub for &'t Time {
}
}
+impl ToString for Time {
+ fn to_string(&self) -> String {
+ format!("{}", self.inner.format("%Y-%m-%d %H:%M:%S%:z"))
+ }
+}
+
impl Time {
/// Get the current local time and pin it to a fixed Tz offset
pub fn now() -> Self {
let now = Local::now();
Self {
- inner: build_datetime(now.time()),
+ inner: build_datetime(
+ now.time()
+ .with_second(0)
+ .and_then(|t| t.with_nanosecond(0))
+ .unwrap(),
+ ),
}
}
@@ -44,7 +55,7 @@ impl Time {
pub fn after(&self, date: &Date) -> bool {
&Date::from(self.date()) > date
}
-
+
#[cfg(test)]
pub(crate) fn fixed(hour: u32, min: u32, sec: u32) -> Self {
Self {
@@ -59,10 +70,9 @@ impl Time {
/// rounding values that were created in a different timezone.
pub fn round(&self) -> Self {
let naive = self.inner.time();
-
let (new_min, incr_hour) = match naive.minute() {
// 0-7 => (0, false)
- m if m > 0 && m < 7 => (0, false),
+ m if m >= 0 && m < 7 => (0, false),
// 7-22 => (15, false)
m if m >= 7 && m < 22 => (15, false),
// 22-37 => (30, false)