From a7d5ee9e17aea897f438ea4e229c3971732fd4d9 Mon Sep 17 00:00:00 2001
From: Guba Sándor <guba.sandor@cloud.bme.hu>
Date: Fri, 14 Nov 2014 13:57:28 +0100
Subject: [PATCH] add local time support

---
 notify.py | 14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)

diff --git a/notify.py b/notify.py
index 14471c5..e57b17d 100755
--- a/notify.py
+++ b/notify.py
@@ -53,6 +53,9 @@ def wall(text):
 
 
 def accept():
+    import datetime
+    from tzlocal import get_localzone
+    from pytz import UTC
     file_path = os.path.join(get_temp_dir(), file_name)
     if not os.path.isfile(file_path):
         print "There is no recent notification to accept."
@@ -73,12 +76,19 @@ def accept():
         rsp = opener.open(req)
         data = json.load(rsp)
         newtime = data["new_suspend_time"]
-    except:
+        # Parse time from JSON (Create UTC Localized Datetime objec)
+        parsed_time =  datetime.datetime.strptime(newtime[:-6], "%Y-%m-%d %H:%M:%S.%f").replace(tzinfo=UTC)
+        # Convert to the machine localization
+        new_local_time = parsed_time.astimezone(get_localzone()).strftime("%Y-%m-%d %H:%M:%S")
+    except ValueError as e:
+        print "Parsing time failed: %s" % e
+    except Exception as e:
+        print e
         print "Renewal failed. Please try it manually at %s" % url
         logger.exception("renew failed")
         return False
     else:
-        print "Renew succeeded. The machine will be suspended at %s." % newtime
+        print "Renew succeeded. The machine will be suspended at %s." % new_local_time
         os.remove(file_path)
         return True
 
--
libgit2 0.26.0