mirror of
https://github.com/munki/munki.git
synced 2026-05-03 10:59:48 -05:00
munkicommon.format_time() updated to use Foundation.NSDate().
git-svn-id: http://munki.googlecode.com/svn/trunk@853 a4e17f2e-e282-11dd-95e1-755cbddbdd66
This commit is contained in:
@@ -33,6 +33,7 @@ import time
|
||||
import urllib2
|
||||
from distutils import version
|
||||
from xml.dom import minidom
|
||||
from Foundation import NSDate
|
||||
|
||||
import munkistatus
|
||||
import FoundationPlist
|
||||
@@ -223,29 +224,13 @@ def display_error(msg):
|
||||
report['Errors'].append(msg)
|
||||
|
||||
|
||||
def format_time(t=None, tz=None, alttz=None):
|
||||
"""Return struct_time as an ISO 8601 formatted string, with timezone information.
|
||||
If t is not given the current local time is used. If timezone information is
|
||||
not given, the local timezone and alternate timezone is used."""
|
||||
# get the current local time
|
||||
if t is None:
|
||||
t = time.localtime()
|
||||
# get the current local timezone offset
|
||||
if tz is None:
|
||||
tz = time.timezone
|
||||
if alttz is None:
|
||||
alttz = time.altzone
|
||||
# calculate UTC offset. NOTE: POSIX uses inverted UTC offset as timezone
|
||||
if t.tm_isdst:
|
||||
utcoffset = -alttz
|
||||
def format_time(timestamp=None):
|
||||
"""Return timestamp as an ISO 8601 formatted string, in the current timezone.
|
||||
If timestamp isn't given the current time is used."""
|
||||
if timestamp is None:
|
||||
return str(NSDate.new())
|
||||
else:
|
||||
utcoffset = -tz
|
||||
# convert UTC offset in seconds to hours and minutes
|
||||
utcoffset_h = (utcoffset / 60) / 60
|
||||
utcoffset_m = (utcoffset / 60) % 60
|
||||
utcoffset_sign = "+" if utcoffset >= 0 else "-"
|
||||
utcoffset_string = " %s%02d%02d" % (utcoffset_sign, utcoffset_h, utcoffset_m)
|
||||
return time.strftime("%Y-%m-%d %H:%M:%S", t) + utcoffset_string
|
||||
t = str(NSDate.alloc().initWithTimeIntervalSince1970_(timestamp))
|
||||
|
||||
|
||||
def log(msg, logname=''):
|
||||
|
||||
Reference in New Issue
Block a user