From f3fe8bb12155db9e67db02825323d2ae8ada28ae Mon Sep 17 00:00:00 2001 From: Krateng Date: Fri, 26 Apr 2019 17:05:29 +0200 Subject: [PATCH] Added ability to quickly access previous and next timerange --- htmlmodules.py | 27 +++++++++++++++++++++++++++ malojatime.py | 8 ++++++++ 2 files changed, 35 insertions(+) diff --git a/htmlmodules.py b/htmlmodules.py index 808eaae..242dea8 100644 --- a/htmlmodules.py +++ b/htmlmodules.py @@ -522,6 +522,33 @@ def module_filterselection(keys,time=True,delimit=False): # weekendstr = "/".join((str(num) for num in weekend)) + + # relative to current range + + html += "
" + # if timekeys.get("timerange").next(-1) is not None: + # html += "«" + # if timekeys.get("timerange").next(-1) is not None or timekeys.get("timerange").next(1) is not None: + # html += " " + timekeys.get("timerange").desc() + " " + # if timekeys.get("timerange").next(1) is not None: + # html += "»" + + if timekeys.get("timerange").next(-1) is not None: + prevrange = timekeys.get("timerange").next(-1) + html += "" + prevrange.desc() + "" + html += " | " + if timekeys.get("timerange").next(-1) is not None or timekeys.get("timerange").next(1) is not None: + html += "" + timekeys.get("timerange").desc() + "" + if timekeys.get("timerange").next(1) is not None: + html += " | " + nextrange = timekeys.get("timerange").next(1) + html += "" + nextrange.desc() + "" + + html += "
" + + + # predefined ranges + html += "
" if timekeys.get("timerange") == today(): html += "Today" diff --git a/malojatime.py b/malojatime.py index 132a1f3..6511a6b 100644 --- a/malojatime.py +++ b/malojatime.py @@ -84,6 +84,13 @@ class MRangeDescriptor: def unlimited(self): return False + # returns the description of the range including buttons to go back and forth + #def desc_interactive(self,**kwargs): + # if self.next(1) is None: + # return self.desc(**kwargs) + # else: + # prevrange = self.next(-1) + # nextrange = self.next(1) # a range that is exactly a gregorian calendar unit (year, month or day) class MTime(MRangeDescriptor): @@ -362,6 +369,7 @@ class MRange(MRangeDescriptor): def next(self,step=1): if abs(step) == math.inf: return None + if self.since is None or self.to is None: return None # hop from the start element by one until we reach the end element diff = 1 nxt = self.since