@@ -82,7 +82,7 @@ def __init__(self, golang_timestamp=None, precision=None):
8282
8383 @property
8484 def golang_timestamp (self ):
85- """int : Golang time.Time timestamp or None if not set."""
85+ """bytes : Golang time.Time timestamp or None if not set."""
8686 return self ._golang_timestamp
8787
8888 def _GetNormalizedTimestamp (self ):
@@ -101,11 +101,9 @@ def _GetNormalizedTimestamp(self):
101101 and self ._nanoseconds is not None
102102 and self ._nanoseconds >= 0
103103 ):
104-
105104 self ._normalized_timestamp = decimal .Decimal (
106105 self ._number_of_seconds - GolangTime ._GOLANG_TO_POSIX_BASE
107106 )
108-
109107 if self ._nanoseconds is not None and self ._nanoseconds >= 0 :
110108 self ._normalized_timestamp += (
111109 decimal .Decimal (self ._nanoseconds )
@@ -147,15 +145,12 @@ def _GetNumberOfSeconds(self, golang_timestamp):
147145 number_of_seconds , nanoseconds , time_zone_offset = struct .unpack (
148146 ">qih" , golang_timestamp [1 :15 ]
149147 )
150-
151148 # TODO: add support for version 2 time zone offset in seconds
152149
153150 except (TypeError , struct .error ) as exception :
154151 raise ValueError (
155- (
156- f"Unable to unpacked Golang time.Time timestamp with error: "
157- f"{ exception !s} "
158- )
152+ f"Unable to unpacked Golang time.Time timestamp with error: "
153+ f"{ exception !s} "
159154 )
160155
161156 # A time zone offset of -1 minute is a special representation for UTC.
@@ -195,7 +190,6 @@ def CopyFromDateTimeString(self, time_string):
195190 seconds = self ._GetNumberOfSecondsFromElements (
196191 year , month , day_of_month , hours , minutes , seconds
197192 )
198-
199193 seconds += self ._GOLANG_TO_POSIX_BASE
200194
201195 self ._normalized_timestamp = None
@@ -216,15 +210,25 @@ def CopyToDateTimeString(self):
216210 number_of_days , hours , minutes , seconds = self ._GetTimeValues (
217211 self ._number_of_seconds
218212 )
219-
220213 year , month , day_of_month = self ._GetDateValuesWithEpoch (
221214 number_of_days , self ._EPOCH
222215 )
223-
224216 return (
225217 f"{ year :04d} -{ month :02d} -{ day_of_month :02d} "
226218 f"{ hours :02d} :{ minutes :02d} :{ seconds :02d} .{ self ._nanoseconds :09d} "
227219 )
228220
221+ def CopyToSerializableDict (self ):
222+ """Copies the date time value to a serializable dictionary.
223+
224+ Returns:
225+ dict[str, object]: serializable dictionary.
226+ """
227+ return {
228+ "__class_name__" : type (self ).__name__ ,
229+ "__type__" : "DateTimeValues" ,
230+ "golang_timestamp" : self ._golang_timestamp ,
231+ }
232+
229233
230234factory .Factory .RegisterDateTimeValues (GolangTime )
0 commit comments