1 from datetime import timedelta, datetime
2
4 """
5 The EventTime class. The purpose of this class is to translate IceCube time,
6 which constist of the year and tenths of nanoseconds since the beginning of the
7 year, to a format that is more user-friendly. This class uses python's
8 datetime module.
9 @todo: Implement math operations.
10 @todo: Clean up the interface so the tenths of nanoseconds and datetime is more
11 unified and integrated.
12 """
14 """
15 The constructor takes a year and a DAQTime (i.e. number of tenths of nanoseconds
16 since the beginning of the year).
17 @param year: The time of year that was used to initialize the class.
18 @param daqTime : Number of tenths of nanoseconds since the beginning of the year.
19 """
20 self.year = year
21 """
22 The year the event occured.
23 """
24 self.daqTime = daqTime
25 """
26 The number of tenths of nanoseconds the event occured since the beginning of the year.
27 """
28
29 dtpair = self._make_datetime_pair()
30 self.dateTime = dtpair[0]
31 """
32 The datetime object
33 """
34 self.utcTenthNanoSecond = dtpair[1]
35 """
36 The remainder of the tenths of nanoseconds from the creation of the datetime object
37 """
38
40 """
41 This method uses the year and daqTime to create a datetime object. Since the highest precision
42 of datetime is microseconds, the remaining tenths of nanoseconds is returned as well.
43 @return: This method returns a tuple (datetime, int) where the first element is the datetime
44 object and the second element is the remaining tenths of nanoseconds.
45 """
46 microsec = long(self.daqTime * 10**-4)
47 utcTenthNanoSecond = self.daqTime % 10000
48 dt = timedelta(microseconds = microsec)
49 dateTime = datetime(year = self.year, month = 1, day = 1) + dt
50 return (dateTime,utcTenthNanoSecond)
51
53 date_str = ""
54 dateTime,tenthns = self._make_datetime_pair()
55 if dateTime.microsecond == 0. :
56 date_str = "%s.%010d" % (str(dateTime),tenthns)
57 else:
58 date_str = "%s%d" % (str(dateTime),tenthns)
59 return date_str
60