text
stringlengths
0
828
""'1' if Daylight Savings Time, '0' otherwise.""
if self.timezone and self.timezone.dst(self.data):
return u'1'
else:
return u'0'"
1006,"def S(self):
""English ordinal suffix for the day of the month, 2 characters; i.e. 'st', 'nd', 'rd' or 'th'""
if self.data.day in (11, 12, 13): # Special case
return u'th'
last = self.data.day % 10
if last == 1:
return u'st'
if last == 2:
return u'nd'
if last == 3:
return u'rd'
return u'th'"
1007,"def t(self):
""Number of days in the given month; i.e. '28' to '31'""
return u'%02d' % calendar.monthrange(self.data.year, self.data.month)[1]"
1008,"def T(self):
""Time zone of this machine; e.g. 'EST' or 'MDT'""
name = self.timezone and self.timezone.tzname(self.data) or None
if name is None:
name = self.format('O')
return unicode(name)"
1009,"def U(self):
""Seconds since the Unix epoch (January 1 1970 00:00:00 GMT)""
if getattr(self.data, 'tzinfo', None):
return int(calendar.timegm(self.data.utctimetuple()))
else:
return int(time.mktime(self.data.timetuple()))"
1010,"def W(self):
""ISO-8601 week number of year, weeks starting on Monday""
# Algorithm from http://www.personal.ecu.edu/mccartyr/ISOwdALG.txt
week_number = None
jan1_weekday = self.data.replace(month=1, day=1).weekday() + 1
weekday = self.data.weekday() + 1
day_of_year = self.z()
if day_of_year <= (8 - jan1_weekday) and jan1_weekday > 4:
if jan1_weekday == 5 or (jan1_weekday == 6 and calendar.isleap(self.data.year-1)):
week_number = 53
else:
week_number = 52
else:
if calendar.isleap(self.data.year):
i = 366
else:
i = 365
if (i - day_of_year) < (4 - weekday):
week_number = 1
else:
j = day_of_year + (7 - weekday) + (jan1_weekday - 1)
week_number = j // 7
if jan1_weekday > 4:
week_number -= 1
return week_number"
1011,"def z(self):
""Day of the year; i.e. '0' to '365'""
doy = self.year_days[self.data.month] + self.data.day
if self.L() and self.data.month > 2:
doy += 1
return doy"
1012,"def Z(self):
""""""
Time zone offset in seconds (i.e. '-43200' to '43200'). The offset for
timezones west of UTC is always negative, and for those east of UTC is
always positive.
""""""
if not self.timezone:
return 0
offset = self.timezone.utcoffset(self.data)
# Only days can be negative, so negative offsets have days=-1 and
# seconds positive. Positive offsets have days=0
return offset.days * 86400 + offset.seconds"
1013,"def print_metric(name, count, elapsed):
""""""A metric function that prints to standard output
:arg str name: name of the metric
:arg int count: number of items
:arg float elapsed: time in seconds
""""""
_do_print(name, count, elapsed, file=sys.stdout)"
1014,"def stderr_metric(name, count, elapsed):
""""""A metric function that prints to standard error
:arg str name: name of the metric
:arg int count: number of items
:arg float elapsed: time in seconds
""""""
_do_print(name, count, elapsed, file=sys.stderr)"
1015,"def make_multi_metric(*metrics):
""""""Make a new metric function that calls the supplied metrics
:arg functions metrics: metric functions
:rtype: function
""""""
def multi_metric(name, count, elapsed):
""""""Calls multiple metrics (closure)""""""
for m in metrics: