MCPcopy Create free account
hub / github.com/apache/fory / _get_timestamp

Method _get_timestamp

python/pyfory/_serializer.py:435–444  ·  view source on GitHub ↗
(self, value: datetime.datetime)

Source from the content-addressed store, hash-verified

433 __win_platform = platform.system() == "Windows"
434
435 def _get_timestamp(self, value: datetime.datetime):
436 seconds_offset = 0
437 if TimestampSerializer.__win_platform and value.tzinfo is None:
438 is_dst = time.daylight and time.localtime().tm_isdst > 0
439 seconds_offset = time.altzone if is_dst else time.timezone
440 value = value.replace(tzinfo=datetime.timezone.utc)
441 micros = int((value.timestamp() + seconds_offset) * 1_000_000)
442 seconds, micros_rem = divmod(micros, 1_000_000)
443 nanos = micros_rem * 1000
444 return seconds, nanos
445
446 def write(self, write_context, value: datetime.datetime):
447 if not isinstance(value, datetime.datetime):

Callers 1

writeMethod · 0.95

Calls 2

timestampMethod · 0.80
replaceMethod · 0.45

Tested by

no test coverage detected