+ def getValue(self):
+ from m5.objects.params import EthAddr
+ return EthAddr(self.value)
+
+ def ini_str(self):
+ return self.value
+
+time_formats = [ "%a %b %d %H:%M:%S %Z %Y",
+ "%a %b %d %H:%M:%S %Z %Y",
+ "%Y/%m/%d %H:%M:%S",
+ "%Y/%m/%d %H:%M",
+ "%Y/%m/%d",
+ "%m/%d/%Y %H:%M:%S",
+ "%m/%d/%Y %H:%M",
+ "%m/%d/%Y",
+ "%m/%d/%y %H:%M:%S",
+ "%m/%d/%y %H:%M",
+ "%m/%d/%y"]
+
+
+def parse_time(value):
+ from time import gmtime, strptime, struct_time, time
+ from datetime import datetime, date
+
+ if isinstance(value, struct_time):
+ return value
+
+ if isinstance(value, (int, long)):
+ return gmtime(value)
+
+ if isinstance(value, (datetime, date)):
+ return value.timetuple()
+
+ if isinstance(value, str):
+ if value in ('Now', 'Today'):
+ return time.gmtime(time.time())
+
+ for format in time_formats:
+ try:
+ return strptime(value, format)
+ except ValueError:
+ pass
+
+ raise ValueError, "Could not parse '%s' as a time" % value
+
+class Time(ParamValue):
+ cxx_type = 'tm'
+ cxx_predecls = [ '#include <time.h>' ]
+ swig_predecls = [ '%include "python/swig/time.i"' ]
+ def __init__(self, value):
+ self.value = parse_time(value)
+
+ def getValue(self):
+ from m5.objects.params import tm
+
+ c_time = tm()
+ py_time = self.value
+
+ # UNIX is years since 1900
+ c_time.tm_year = py_time.tm_year - 1900;
+
+ # Python starts at 1, UNIX starts at 0
+ c_time.tm_mon = py_time.tm_mon - 1;
+ c_time.tm_mday = py_time.tm_mday;
+ c_time.tm_hour = py_time.tm_hour;
+ c_time.tm_min = py_time.tm_min;
+ c_time.tm_sec = py_time.tm_sec;
+
+ # Python has 0 as Monday, UNIX is 0 as sunday
+ c_time.tm_wday = py_time.tm_wday + 1
+ if c_time.tm_wday > 6:
+ c_time.tm_wday -= 7;
+
+ # Python starts at 1, Unix starts at 0
+ c_time.tm_yday = py_time.tm_yday - 1;
+
+ return c_time
+