@@ -26,7 +26,7 @@ var Module = &starlarkstruct.Module{
2626 "time" : starlark .NewBuiltin ("time" , newTime ),
2727 "parse_time" : starlark .NewBuiltin ("time" , parseTime ),
2828 "sleep" : starlark .NewBuiltin ("sleep" , sleep ),
29- "from_timestamp" : starlark .NewBuiltin ("fromtimestamp " , fromUnixTime ),
29+ "from_timestamp" : starlark .NewBuiltin ("from_timestamp " , fromTimestamp ),
3030
3131 "zero" : Time {},
3232
@@ -114,7 +114,7 @@ func parseTime(thread *starlark.Thread, _ *starlark.Builtin, args starlark.Tuple
114114 return Time (t ), nil
115115}
116116
117- func fromUnixTime (thread * starlark.Thread , _ * starlark.Builtin , args starlark.Tuple , kwargs []starlark.Tuple ) (starlark.Value , error ) {
117+ func fromTimestamp (thread * starlark.Thread , _ * starlark.Builtin , args starlark.Tuple , kwargs []starlark.Tuple ) (starlark.Value , error ) {
118118 var x int
119119 if err := starlark .UnpackPositionalArgs ("from_timestamp" , args , kwargs , 1 , & x ); err != nil {
120120 return nil , err
@@ -179,7 +179,7 @@ func (d Duration) Freeze() {}
179179// Hash returns a function of x such that Equals(x, y) => Hash(x) == Hash(y)
180180// required by starlark.Value interface.
181181func (d Duration ) Hash () (uint32 , error ) {
182- return starlark . MakeInt64 ( int64 (d )). Hash ()
182+ return uint32 ( d ) ^ uint32 ( int64 (d )>> 32 ), nil
183183}
184184
185185// Truth returns the truth value of an object required by starlark.Value
@@ -253,7 +253,6 @@ func (d Duration) Binary(op syntax.Token, yV starlark.Value, _ starlark.Side) (s
253253 return Duration (x - time .Duration (i )), nil
254254 case Time :
255255 // duration - time = duration
256- return nil , nil
257256 }
258257
259258 case syntax .SLASH :
@@ -272,16 +271,6 @@ func (d Duration) Binary(op syntax.Token, yV starlark.Value, _ starlark.Side) (s
272271 return nil , fmt .Errorf ("%s division by zero" , d .Type ())
273272 }
274273 return Duration (d / Duration (i )), nil
275- case Time :
276- // y := time.Time(yV.(Time))
277- // switch op {
278- // case syntax.PLUS:
279- // // duration + time = time
280- // return Time(y.Add(x)), nil
281- // case syntax.MINUS:
282- // // duration - time = duration
283- // return nil, nil
284- // }
285274 }
286275
287276 // if int64(y) == 0 {
@@ -302,16 +291,6 @@ func (d Duration) Binary(op syntax.Token, yV starlark.Value, _ starlark.Side) (s
302291 return nil , fmt .Errorf ("int value out of range (want signed 64-bit value)" )
303292 }
304293 return d / Duration (i ), nil
305- case Time :
306- // y := time.Time(yV.(Time))
307- // switch op {
308- // case syntax.PLUS:
309- // // duration + time = time
310- // return Time(y.Add(x)), nil
311- // case syntax.MINUS:
312- // // duration - time = duration
313- // return nil, nil
314- // }
315294 }
316295
317296 // if int64(y) == 0 {
@@ -329,19 +308,7 @@ func (d Duration) Binary(op syntax.Token, yV starlark.Value, _ starlark.Side) (s
329308 return nil , fmt .Errorf ("int value out of range (want signed 64-bit value)" )
330309 }
331310 return d * Duration (i ), nil
332- case Time :
333- // y := time.Time(yV.(Time))
334- // switch op {
335- // case syntax.PLUS:
336- // // duration + time = time
337- // return Time(y.Add(x)), nil
338- // case syntax.MINUS:
339- // // duration - time = duration
340- // return nil, nil
341- // }
342311 }
343-
344- // return Duration(x * y), nil
345312 }
346313
347314 return nil , nil
@@ -378,7 +345,7 @@ func (t Time) Freeze() {}
378345// Hash returns a function of x such that Equals(x, y) => Hash(x) == Hash(y)
379346// required by starlark.Value interface.
380347func (t Time ) Hash () (uint32 , error ) {
381- return starlark . MakeInt64 (time .Time (t ).UnixNano ()). Hash ()
348+ return uint32 (time .Time (t ).UnixNano ()) ^ uint32 ( int64 ( time . Time ( t ). UnixNano ()) >> 32 ), nil
382349}
383350
384351// Truth returns the truth value of an object required by starlark.Value
0 commit comments