aboutsummaryrefslogtreecommitdiff
path: root/src/app/cursor.rs
diff options
context:
space:
mode:
authorAkshay <[email protected]>2021-02-06 13:30:40 +0000
committerAkshay <[email protected]>2021-02-06 13:30:40 +0000
commit77368eed146ec8278609e04e395c7ef04c386313 (patch)
tree440eed647438cd8de03e91609e1daa43caf04bca /src/app/cursor.rs
parent9cdef4e296c77fb94d99553de05ba1aaa6c81ed8 (diff)
deprecate view_month_offset in favor of cursor
Diffstat (limited to 'src/app/cursor.rs')
-rw-r--r--src/app/cursor.rs22
1 files changed, 21 insertions, 1 deletions
diff --git a/src/app/cursor.rs b/src/app/cursor.rs
index ed6bd65..f76d591 100644
--- a/src/app/cursor.rs
+++ b/src/app/cursor.rs
@@ -16,7 +16,7 @@ impl Cursor {
16 0: Local::now().naive_local().date(), 16 0: Local::now().naive_local().date(),
17 } 17 }
18 } 18 }
19 pub fn do_move(&mut self, d: Absolute) { 19 pub fn small_seek(&mut self, d: Absolute) {
20 let today = Local::now().naive_local().date(); 20 let today = Local::now().naive_local().date();
21 let cursor = self.0; 21 let cursor = self.0;
22 match d { 22 match d {
@@ -48,4 +48,24 @@ impl Cursor {
48 Absolute::None => {} 48 Absolute::None => {}
49 } 49 }
50 } 50 }
51 fn long_seek(&mut self, offset: Duration) {
52 let cursor = self.0;
53 let today = Local::now().naive_local().date();
54 let next = cursor.checked_add_signed(offset).unwrap_or(cursor);
55
56 if next <= today {
57 self.0 = next;
58 } else {
59 self.0 = today;
60 }
61 }
62 pub fn month_forward(&mut self) {
63 self.long_seek(Duration::weeks(4));
64 }
65 pub fn month_backward(&mut self) {
66 self.long_seek(Duration::weeks(-4));
67 }
68 pub fn reset(&mut self) {
69 self.0 = Local::now().naive_local().date();
70 }
51} 71}