Browse Source

def timestamp_now_utc & timestamp_now_local;
rename timestamp_iso -> timestamp_iso_local;
fix timestamp_iso_local

> ValueError: astimezone() cannot be applied to a naive datetime

Fabian Peter Hammerle 5 years ago
parent
commit
4544d5cc90
1 changed files with 10 additions and 2 deletions
  1. 10 2
      rc.xsh

+ 10 - 2
rc.xsh

@@ -78,10 +78,18 @@ def locate(*patterns, match_all=True, ignore_case=True):
         params.insert(0, '--ignore-case')
     return $(locate @(params) -- @(patterns)).split('\n')[:-1]
 
-def timestamp_iso():
+def timestamp_now_utc():
+    return dt.datetime.utcnow().replace(tzinfo=dt.timezone.utc)
+
+def timestamp_now_local():
+    # if called without tz argument astimezone() assumes
+    # the system local timezone for the target timezone
+    return timestamp_now_utc().astimezone()
+
+def timestamp_iso_local():
     # if called without tz argument astimezone() assumes
     # the system local timezone for the target timezone
-    return dt.datetime.now().astimezone().strftime('%Y%m%dT%H%M%S%z')
+    return timestamp_now_local().strftime('%Y%m%dT%H%M%S%z')
 
 aliases['dpkg-welse'] = lambda args: '\n'.join(dpkg_welse(args[0]))
 aliases['dpkg-which'] = lambda args: '\t'.join(dpkg_which(args[0]))