[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

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



commit 6a582784233e4db9e6b5a5035f3b5eebbdf908ce
Author: Damian Johnson <atagar@xxxxxxxxxxxxxx>
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):



_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits