[tor-commits] [nyx/master] Revise days_since() to behave more intuitively

atagar at torproject.org atagar at torproject.org
Tue May 5 05:42:06 UTC 2015


commit 6a582784233e4db9e6b5a5035f3b5eebbdf908ce
Author: Damian Johnson <atagar at torproject.org>
Date:   Mon May 4 20:39:16 2015 -0700

    Revise days_since() to behave more intuitively
    
    We only used days_since() to figure out if one day was the same as another, so
    didn't really care what the value actually was. Changing it to be in reference
    to today at midnight so zero means today, one means yesterday, etc.
---
 nyx/util/log.py |    9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/nyx/util/log.py b/nyx/util/log.py
index 1371bb8..f224789 100644
--- a/nyx/util/log.py
+++ b/nyx/util/log.py
@@ -24,20 +24,25 @@ except ImportError:
   from stem.util.lru_cache import lru_cache
 
 TOR_RUNLEVELS = ['DEBUG', 'INFO', 'NOTICE', 'WARN', 'ERR']
-TIMEZONE_OFFSET = time.altzone if time.localtime()[8] else time.timezone
 CONFIG = stem.util.conf.config_dict('nyx', {'tor.chroot': ''})
 
 
 def days_since(timestamp):
   """
   Provides the number of days since a given unix timestamp, by local time.
+  Daybreaks are rolled over at midnight. For instance, 5pm today would report
+  zero, and 5pm yesterday would report one.
 
   :param int timestamp: unix timestamp to provide time since
 
   :reutrns: **int** with the number of days since this event
   """
 
-  return int((timestamp - TIMEZONE_OFFSET) / 86400)
+  # unix timestamp for today at midnight
+
+  midnight = time.mktime(datetime.datetime.today().date().timetuple())
+
+  return int((midnight - timestamp) / 86400)
 
 
 def log_file_path(controller):





More information about the tor-commits mailing list