@@ -64,7 +64,7 @@ def from_timedelta(cls, td: timedelta) -> "Duration":
6464 # Get the fractional part and convert to nanoseconds
6565 # This preserves more precision than using microsecond * 1000
6666 fractional = total_seconds - seconds
67- nanoseconds = int (fractional * Decimal (' 1000000000' ))
67+ nanoseconds = int (fractional * Decimal (" 1000000000" ))
6868 return cls (seconds = seconds , nanoseconds = nanoseconds )
6969
7070 def to_timedelta (self ) -> timedelta :
@@ -150,9 +150,9 @@ def to_string(self) -> str:
150150 return f"{ self .seconds } s"
151151
152152 # Use Decimal for precise decimal arithmetic
153- total = Decimal (self .seconds ) + (Decimal (self .nanoseconds ) / Decimal (' 1000000000' ))
153+ total = Decimal (self .seconds ) + (Decimal (self .nanoseconds ) / Decimal (" 1000000000" ))
154154 # Format with up to 9 decimal places, removing trailing zeros
155- return f"{ total :.9f} " .rstrip ('0' ).rstrip ('.' ) + 's'
155+ return f"{ total :.9f} " .rstrip ("0" ).rstrip ("." ) + "s"
156156
157157
158158class Timestamp :
@@ -213,16 +213,16 @@ def from_datetime(cls, dt: datetime) -> "Timestamp":
213213 dt = dt .replace (tzinfo = timezone .utc )
214214 # Convert to UTC
215215 utc_dt = dt .astimezone (timezone .utc )
216-
216+
217217 # Get seconds since epoch using Decimal for precise calculation
218218 # datetime.timestamp() returns float, so we need to handle it carefully
219219 ts = Decimal (str (utc_dt .timestamp ()))
220220 seconds = int (ts )
221221 # Get the fractional part and convert to nanoseconds
222222 # This preserves more precision than using microsecond * 1000
223223 fractional = ts - seconds
224- nanos = int (fractional * Decimal (' 1000000000' ))
225-
224+ nanos = int (fractional * Decimal (" 1000000000" ))
225+
226226 return cls (seconds = seconds , nanos = nanos )
227227
228228 def to_datetime (self ) -> datetime :
@@ -267,7 +267,7 @@ def parse(cls, timestamp_str: str) -> "Timestamp":
267267
268268 # Build the datetime string with a standardized offset format
269269 dt_str = f"{ year } -{ month } -{ day } T{ hour } :{ minute } :{ second } "
270-
270+
271271 # Handle fractional seconds, truncating to microseconds for fromisoformat
272272 nanos = 0
273273 if frac :
@@ -343,6 +343,6 @@ def replace(self, **kwargs) -> "Timestamp":
343343 Returns:
344344 A new Timestamp instance with the specified fields replaced
345345 """
346- seconds = kwargs .get (' seconds' , self .seconds )
347- nanos = kwargs .get (' nanos' , self .nanos )
346+ seconds = kwargs .get (" seconds" , self .seconds )
347+ nanos = kwargs .get (" nanos" , self .nanos )
348348 return Timestamp (seconds = seconds , nanos = nanos )
0 commit comments