diff options
Diffstat (limited to 'libgo/go/time/time.go')
-rw-r--r-- | libgo/go/time/time.go | 43 |
1 files changed, 20 insertions, 23 deletions
diff --git a/libgo/go/time/time.go b/libgo/go/time/time.go index 0a2b0914283..0300e846a4b 100644 --- a/libgo/go/time/time.go +++ b/libgo/go/time/time.go @@ -31,6 +31,11 @@ import "errors" // change the instant in time being denoted and therefore does not affect the // computations described in earlier paragraphs. // +// Note that the Go == operator compares not just the time instant but also the +// Location. Therefore, Time values should not be used as map or database keys +// without first guaranteeing that the identical Location has been set for all +// values, which can be achieved through use of the UTC or Local method. +// type Time struct { // sec gives the number of seconds elapsed since // January 1, year 1 00:00:00 UTC. @@ -39,14 +44,7 @@ type Time struct { // nsec specifies a non-negative nanosecond // offset within the second named by Seconds. // It must be in the range [0, 999999999]. - // - // It is declared as uintptr instead of int32 or uint32 - // to avoid garbage collector aliasing in the case where - // on a 64-bit system the int32 or uint32 field is written - // over the low half of a pointer, creating another pointer. - // TODO(rsc): When the garbage collector is completely - // precise, change back to int32. - nsec uintptr + nsec int32 // loc specifies the Location that should be used to // determine the minute, hour, month, day, and year @@ -475,29 +473,28 @@ func (d Duration) String() string { if u < uint64(Second) { // Special case: if duration is smaller than a second, // use smaller units, like 1.2ms - var ( - prec int - unit byte - ) + var prec int + w-- + buf[w] = 's' + w-- switch { case u == 0: return "0" case u < uint64(Microsecond): // print nanoseconds prec = 0 - unit = 'n' + buf[w] = 'n' case u < uint64(Millisecond): // print microseconds prec = 3 - unit = 'u' + // U+00B5 'µ' micro sign == 0xC2 0xB5 + w-- // Need room for two bytes. + copy(buf[w:], "µ") default: // print milliseconds prec = 6 - unit = 'm' + buf[w] = 'm' } - w -= 2 - buf[w] = unit - buf[w+1] = 's' w, u = fmtFrac(buf[:w], u, prec) w = fmtInt(buf[:w], u) } else { @@ -620,7 +617,7 @@ func (t Time) Add(d Duration) Time { t.sec-- nsec += 1e9 } - t.nsec = uintptr(nsec) + t.nsec = nsec return t } @@ -783,7 +780,7 @@ func now() (sec int64, nsec int32) // Now returns the current local time. func Now() Time { sec, nsec := now() - return Time{sec + unixToInternal, uintptr(nsec), Local} + return Time{sec + unixToInternal, nsec, Local} } // UTC returns t with the location set to UTC. @@ -900,7 +897,7 @@ func (t *Time) UnmarshalBinary(data []byte) error { int64(buf[3])<<32 | int64(buf[2])<<40 | int64(buf[1])<<48 | int64(buf[0])<<56 buf = buf[8:] - t.nsec = uintptr(int32(buf[3]) | int32(buf[2])<<8 | int32(buf[1])<<16 | int32(buf[0])<<24) + t.nsec = int32(buf[3]) | int32(buf[2])<<8 | int32(buf[1])<<16 | int32(buf[0])<<24 buf = buf[4:] offset := int(int16(buf[1])|int16(buf[0])<<8) * 60 @@ -979,7 +976,7 @@ func Unix(sec int64, nsec int64) Time { sec-- } } - return Time{sec + unixToInternal, uintptr(nsec), Local} + return Time{sec + unixToInternal, int32(nsec), Local} } func isLeap(year int) bool { @@ -1088,7 +1085,7 @@ func Date(year int, month Month, day, hour, min, sec, nsec int, loc *Location) T unix -= int64(offset) } - return Time{unix + unixToInternal, uintptr(nsec), loc} + return Time{unix + unixToInternal, int32(nsec), loc} } // Truncate returns the result of rounding t down to a multiple of d (since the zero time). |