44from __future__ import unicode_literals
55
66import decimal
7+ import typing
78
89from dfdatetime import definitions
910from dfdatetime import interface
1213class CocoaTimeEpoch (interface .DateTimeEpoch ):
1314 """Cocoa time epoch."""
1415
15- def __init__ (self ):
16+ def __init__ (self ) -> None :
1617 """Initializes a Cocoa time epoch."""
1718 super (CocoaTimeEpoch , self ).__init__ (2001 , 1 , 1 )
1819
@@ -36,28 +37,29 @@ class CocoaTime(interface.DateTimeValues):
3637
3738 _EPOCH = CocoaTimeEpoch ()
3839
39- def __init__ (self , timestamp = None ):
40+ def __init__ (self , timestamp : typing . Optional [ float ] = None ) -> None :
4041 """Initializes a Cocoa timestamp.
4142
4243 Args:
4344 timestamp (Optional[float]): Cocoa timestamp.
4445 """
4546 super (CocoaTime , self ).__init__ ()
46- self ._precision = definitions .PRECISION_1_SECOND
47- self ._timestamp = timestamp
47+ self ._precision : str = definitions .PRECISION_1_SECOND
48+ self ._timestamp : typing . Union [ float , None ] = timestamp
4849
4950 @property
50- def timestamp (self ):
51+ def timestamp (self ) -> typing . Union [ float , None ] :
5152 """float: Cocoa timestamp or None if timestamp is not set."""
5253 return self ._timestamp
5354
54- def _GetNormalizedTimestamp (self ):
55+ def _GetNormalizedTimestamp (self ) -> typing . Union [ decimal . Decimal , None ] :
5556 """Retrieves the normalized timestamp.
5657
5758 Returns:
58- float: normalized timestamp, which contains the number of seconds since
59- January 1, 1970 00:00:00 and a fraction of second used for increased
60- precision, or None if the normalized timestamp cannot be determined.
59+ decimal.Decimal: normalized timestamp, which contains the number of
60+ seconds since January 1, 1970 00:00:00 and a fraction of second
61+ used for increased precision, or None if the normalized timestamp
62+ cannot be determined.
6163 """
6264 if self ._normalized_timestamp is None :
6365 if self ._timestamp is not None :
@@ -66,7 +68,7 @@ def _GetNormalizedTimestamp(self):
6668
6769 return self ._normalized_timestamp
6870
69- def CopyFromDateTimeString (self , time_string ) :
71+ def CopyFromDateTimeString (self , time_string : str ) -> None :
7072 """Copies a Cocoa timestamp from a date and time string.
7173
7274 Args:
@@ -92,19 +94,19 @@ def CopyFromDateTimeString(self, time_string):
9294 microseconds = date_time_values .get ('microseconds' , None )
9395 time_zone_offset = date_time_values .get ('time_zone_offset' , 0 )
9496
95- timestamp = self ._GetNumberOfSecondsFromElements (
97+ number_of_seconds = self ._GetNumberOfSecondsFromElements (
9698 year , month , day_of_month , hours , minutes , seconds , time_zone_offset )
97- timestamp += self ._COCOA_TO_POSIX_BASE
99+ number_of_seconds += self ._COCOA_TO_POSIX_BASE
98100
99- timestamp = float (timestamp )
101+ timestamp = float (number_of_seconds )
100102 if microseconds is not None :
101103 timestamp += float (microseconds ) / definitions .MICROSECONDS_PER_SECOND
102104
103105 self ._normalized_timestamp = None
104106 self ._timestamp = timestamp
105107 self ._time_zone_offset = time_zone_offset
106108
107- def CopyToDateTimeString (self ):
109+ def CopyToDateTimeString (self ) -> typing . Union [ str , None ] :
108110 """Copies the Cocoa timestamp to a date and time string.
109111
110112 Returns:
0 commit comments