Expand code doc for util.Date, util.Time
This commit is contained in:
@@ -110,7 +110,6 @@ def uuid_from_time(time_arg, node=None, clock_seq=None):
|
|||||||
if clock_seq > 0x3fff:
|
if clock_seq > 0x3fff:
|
||||||
raise ValueError('clock_seq is out of range (need a 14-bit value)')
|
raise ValueError('clock_seq is out of range (need a 14-bit value)')
|
||||||
|
|
||||||
|
|
||||||
clock_seq_low = clock_seq & 0xff
|
clock_seq_low = clock_seq & 0xff
|
||||||
clock_seq_hi_variant = 0x80 | ((clock_seq >> 8) & 0x3f)
|
clock_seq_hi_variant = 0x80 | ((clock_seq >> 8) & 0x3f)
|
||||||
|
|
||||||
@@ -824,6 +823,13 @@ class Time(object):
|
|||||||
nanosecond_time = 0
|
nanosecond_time = 0
|
||||||
|
|
||||||
def __init__(self, value):
|
def __init__(self, value):
|
||||||
|
"""
|
||||||
|
Initializer value can be:
|
||||||
|
|
||||||
|
- integer_type: absolute nanoseconds in the day
|
||||||
|
- datetime.time: built-in time
|
||||||
|
- string_type: a string time of the form "HH:MM:SS[.mmmuuunnn]"
|
||||||
|
"""
|
||||||
if isinstance(value, six.integer_types):
|
if isinstance(value, six.integer_types):
|
||||||
self._from_timestamp(value)
|
self._from_timestamp(value)
|
||||||
elif isinstance(value, datetime.time):
|
elif isinstance(value, datetime.time):
|
||||||
@@ -835,20 +841,32 @@ class Time(object):
|
|||||||
|
|
||||||
@property
|
@property
|
||||||
def hour(self):
|
def hour(self):
|
||||||
|
"""
|
||||||
|
The hour component of this time (0-23)
|
||||||
|
"""
|
||||||
return self.nanosecond_time // Time.HOUR
|
return self.nanosecond_time // Time.HOUR
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def minute(self):
|
def minute(self):
|
||||||
|
"""
|
||||||
|
The minute component of this time (0-59)
|
||||||
|
"""
|
||||||
minutes = self.nanosecond_time // Time.MINUTE
|
minutes = self.nanosecond_time // Time.MINUTE
|
||||||
return minutes % 60
|
return minutes % 60
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def second(self):
|
def second(self):
|
||||||
|
"""
|
||||||
|
The second component of this time (0-59)
|
||||||
|
"""
|
||||||
seconds = self.nanosecond_time // Time.SECOND
|
seconds = self.nanosecond_time // Time.SECOND
|
||||||
return seconds % 60
|
return seconds % 60
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def nanosecond(self):
|
def nanosecond(self):
|
||||||
|
"""
|
||||||
|
The fractional seconds component of the time, in nanoseconds
|
||||||
|
"""
|
||||||
return self.nanosecond_time % Time.SECOND
|
return self.nanosecond_time % Time.SECOND
|
||||||
|
|
||||||
def _from_timestamp(self, t):
|
def _from_timestamp(self, t):
|
||||||
@@ -915,6 +933,13 @@ class Date(object):
|
|||||||
days_from_epoch = 0
|
days_from_epoch = 0
|
||||||
|
|
||||||
def __init__(self, value):
|
def __init__(self, value):
|
||||||
|
"""
|
||||||
|
Initializer value can be:
|
||||||
|
|
||||||
|
- integer_type: absolute days from epoch (1970, 1, 1). Can be negative.
|
||||||
|
- datetime.date: built-in date
|
||||||
|
- string_type: a string time of the form "yyyy-mm-dd"
|
||||||
|
"""
|
||||||
if isinstance(value, six.integer_types):
|
if isinstance(value, six.integer_types):
|
||||||
self.days_from_epoch = value
|
self.days_from_epoch = value
|
||||||
elif isinstance(value, (datetime.date, datetime.datetime)):
|
elif isinstance(value, (datetime.date, datetime.datetime)):
|
||||||
@@ -926,9 +951,17 @@ class Date(object):
|
|||||||
|
|
||||||
@property
|
@property
|
||||||
def seconds(self):
|
def seconds(self):
|
||||||
|
"""
|
||||||
|
Absolute seconds from epoch (can be negative)
|
||||||
|
"""
|
||||||
return self.days_from_epoch * Date.DAY
|
return self.days_from_epoch * Date.DAY
|
||||||
|
|
||||||
def date(self):
|
def date(self):
|
||||||
|
"""
|
||||||
|
Return a built-in datetime.date for Dates falling in the years [datetime.MINYEAR, datetime.MAXYEAR]
|
||||||
|
|
||||||
|
ValueError is raised for Dates outside this range.
|
||||||
|
"""
|
||||||
try:
|
try:
|
||||||
dt = datetime_from_timestamp(self.seconds)
|
dt = datetime_from_timestamp(self.seconds)
|
||||||
return datetime.date(dt.year, dt.month, dt.day)
|
return datetime.date(dt.year, dt.month, dt.day)
|
||||||
|
|||||||
Reference in New Issue
Block a user