55
66import decimal
77
8+ from typing import Optional , Union # pylint: disable=unused-import
9+
810from dfdatetime import definitions
911from dfdatetime import interface
1012
1113
1214class CocoaTimeEpoch (interface .DateTimeEpoch ):
1315 """Cocoa time epoch."""
1416
15- def __init__ (self ):
17+ def __init__ (self ) -> 'None' :
1618 """Initializes a Cocoa time epoch."""
1719 super (CocoaTimeEpoch , self ).__init__ (2001 , 1 , 1 )
1820
@@ -32,32 +34,33 @@ class CocoaTime(interface.DateTimeValues):
3234 is_local_time (bool): True if the date and time value is in local time.
3335 """
3436 # The difference between January 1, 2001 and January 1, 1970 in seconds.
35- _COCOA_TO_POSIX_BASE = - 978307200
37+ _COCOA_TO_POSIX_BASE : 'int' = - 978307200
3638
37- _EPOCH = CocoaTimeEpoch ()
39+ _EPOCH : 'interface.DateTimeEpoch' = CocoaTimeEpoch ()
3840
39- def __init__ (self , timestamp = None ):
41+ def __init__ (self , timestamp : 'Optional[float]' = None ) -> 'None' :
4042 """Initializes a Cocoa timestamp.
4143
4244 Args:
4345 timestamp (Optional[float]): Cocoa timestamp.
4446 """
4547 super (CocoaTime , self ).__init__ ()
46- self ._precision = definitions .PRECISION_1_SECOND
47- self ._timestamp = timestamp
48+ self ._precision : 'str' = definitions .PRECISION_1_SECOND
49+ self ._timestamp : 'Union[float, None]' = timestamp
4850
4951 @property
50- def timestamp (self ):
52+ def timestamp (self ) -> 'Union[float, None]' :
5153 """float: Cocoa timestamp or None if timestamp is not set."""
5254 return self ._timestamp
5355
54- def _GetNormalizedTimestamp (self ):
56+ def _GetNormalizedTimestamp (self ) -> 'Union[decimal.Decimal, None]' :
5557 """Retrieves the normalized timestamp.
5658
5759 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.
60+ decimal.Decimal: normalized timestamp, which contains the number of
61+ seconds since January 1, 1970 00:00:00 and a fraction of second
62+ used for increased precision, or None if the normalized timestamp
63+ cannot be determined.
6164 """
6265 if self ._normalized_timestamp is None :
6366 if self ._timestamp is not None :
@@ -66,7 +69,7 @@ def _GetNormalizedTimestamp(self):
6669
6770 return self ._normalized_timestamp
6871
69- def CopyFromDateTimeString (self , time_string ) :
72+ def CopyFromDateTimeString (self , time_string : 'str' ) -> 'None' :
7073 """Copies a Cocoa timestamp from a date and time string.
7174
7275 Args:
@@ -92,19 +95,20 @@ def CopyFromDateTimeString(self, time_string):
9295 microseconds = date_time_values .get ('microseconds' , None )
9396 time_zone_offset = date_time_values .get ('time_zone_offset' , 0 )
9497
95- timestamp = self ._GetNumberOfSecondsFromElements (
96- year , month , day_of_month , hours , minutes , seconds , time_zone_offset )
97- timestamp += self ._COCOA_TO_POSIX_BASE
98+ number_of_seconds = self ._GetNumberOfSecondsFromElements (
99+ year , month , day_of_month , hours , minutes , seconds ,
100+ time_zone_offset = time_zone_offset )
101+ number_of_seconds += self ._COCOA_TO_POSIX_BASE
98102
99- timestamp = float (timestamp )
103+ timestamp = float (number_of_seconds )
100104 if microseconds is not None :
101105 timestamp += float (microseconds ) / definitions .MICROSECONDS_PER_SECOND
102106
103107 self ._normalized_timestamp = None
104108 self ._timestamp = timestamp
105109 self ._time_zone_offset = time_zone_offset
106110
107- def CopyToDateTimeString (self ):
111+ def CopyToDateTimeString (self ) -> 'Union[str, None]' :
108112 """Copies the Cocoa timestamp to a date and time string.
109113
110114 Returns:
0 commit comments