CL 131196 optimized Time.Sub, but was reverted because
it incorrectly computed the nanoseconds in some edge cases.
This CL adds a test case to enforce the correct behavior
so that a future optimization does not break this again.
Updates #17858
Updates #33677
Change-Id: I596d8302ca6bf721cf7ca11cc6f939639fcbdd43
Reviewed-on: https://go-review.googlesource.com/c/go/+/190524
Run-TryBot: Joe Tsai <thebrokentoaster@gmail.com>
Reviewed-by: Daniel Martí <mvdan@mvdan.cc>
Reviewed-by: Andrew Bonventre <andybons@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
This reverts commit CL 131196 because there is a bug
in the calculation of nanoseconds.
Fixes#33677
Change-Id: Ic8e94c547ee29b8aeda1b9a5cb9764dbf47b14b4
Reviewed-on: https://go-review.googlesource.com/c/go/+/190497
Run-TryBot: Andrew Bonventre <andybons@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Emmanuel Odeke <emm.odeke@gmail.com>
Reviewed-by: Andrew Bonventre <andybons@golang.org>
The zoneinfo.zip file will be in the $GOROOT in self-hsoted builds
on iOS.
Updates #31722
Change-Id: I991fae92e3dc50581b099a2d8901aed36ecc7cef
Reviewed-on: https://go-review.googlesource.com/c/go/+/174310
Run-TryBot: Elias Naur <mail@eliasnaur.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
When the leading zero format is used, we currently don't handle the
month and year properly.
For the month, we were reporting an out of range error when getnum
returns zero of its own, as it also returns the month 0. That's
confusing, so only check the range when getnum returns a nil error.
For the year, we don't restore the value when parsing error occurs. For
example, with the incorrect input "111-01", "01" will be used to report
an error. So restore the value when an error occurs fix the problem.
Fixes#29918Fixes#29916
Change-Id: I3145f8c46813a0457766b7c302482e6b56f94ed6
Reviewed-on: https://go-review.googlesource.com/c/go/+/160338
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
This is primarily achieved by checking for arithmetic overflow
instead of using Add and Equal.
It's a decent performance improvement even though
the function still isn't inlined.
name old time/op new time/op delta
Sub-6 242ns ± 0% 122ns ± 0% -49.59% (p=0.002 n=8+10)
Updates #17858.
Change-Id: I1469b618183c83ea8ea54d5ce277eb15f2ec0f11
Reviewed-on: https://go-review.googlesource.com/c/go/+/131196
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
The return values are integers, as opposed to floats, since the fractionals can be derived from multiplying t.Seconds().
Fixes#28564
Change-Id: I3796227e1f64ead39ff0aacfbdce912d952f2994
GitHub-Last-Rev: b843ab740b
GitHub-Pull-Request: golang/go#30819
Reviewed-on: https://go-review.googlesource.com/c/go/+/167387
Run-TryBot: Robert Griesemer <gri@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Day of year is 002 or __2, in contrast to day-in-month 2 or 02 or _2.
This means there is no way to print a variable-width day-of-year,
but that's probably OK.
Fixes#25689.
Change-Id: I1425d412cb7d2d360e9b3bf74e89566714e2477a
Reviewed-on: https://go-review.googlesource.com/c/go/+/122876
Run-TryBot: Russ Cox <rsc@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rob Pike <r@golang.org>
Fix the punctuation and use the proper units for microseconds,
while explaining the incorrect but common variant 'us'.
Change-Id: I9e96694ef27ab4761efccd8616ac7b6700f60d39
Reviewed-on: https://go-review.googlesource.com/c/163917
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Also store 64-bit data in lib/time/zoneinfo.zip.
The comments argue that we don't need the 64-bit data until 2037 or
2106, but that turns out not to be the case. We also need them for
dates before December 13, 1901, which is time.Unix(-0x80000000, 0).
Fixes#30099
Change-Id: Ib8c9efb29b7b3c08531ae69912c588209d6320e9
Reviewed-on: https://go-review.googlesource.com/c/161202
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
The example for Nanoseconds() currently reads:
ns, _ := time.ParseDuration("1000ns")
fmt.Printf("one microsecond has %d nanoseconds.", ns.Nanoseconds())
which is not terribly interesting: it seems obvious that parsing
"1000ns" and then calling Nanoseconds() will print 1000. The mention
of microseconds in the text suggests that the author's intention was,
instead, to write something like this:
u, _ := time.ParseDuration("1us")
i.e. build a time value by parsing 1 microsecond, and then print the
value in nanoseconds. Change the example to do this.
Change-Id: I4ddb123f0935a12cda3b5d6f1ca919bfcd6383d6
Reviewed-on: https://go-review.googlesource.com/c/163622
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Updates #20969
Change-Id: Ibcf0bf932d5b1de67c22c63dd8514ed7a5d198fb
Reviewed-on: https://go-review.googlesource.com/c/155538
Run-TryBot: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
This commit fixes tests which fail on some versions of AIX 7.2 due
to internal bugs.
getsockname isn't working properly with unix networks.
Timezone files aren't returning a correct output.
Change-Id: I4ff15683912be62ab86dfbeeb63b73513404d086
Reviewed-on: https://go-review.googlesource.com/c/146940
Run-TryBot: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
time.now is somewhat expensive (much more expensive than nanotime),
in the common case when Time has monotonic time we don't actually
need to call time.now in Since/Until as we can do calculation
based purely on monotonic times.
name old time/op new time/op delta
TCP4OneShotTimeout-6 17.0µs ± 0% 17.1µs ± 1% ~ (p=0.151 n=5+5)
SetReadDeadline-6 261ns ± 0% 234ns ± 1% -10.35% (p=0.008 n=5+5)
Benchmark that only calls Until:
benchmark old ns/op new ns/op delta
BenchmarkUntil 54.0 29.5 -45.37%
Update #25729
Change-Id: I5ac5af3eb1fe9f583cf79299f10b84501b1a0d7d
Reviewed-on: https://go-review.googlesource.com/c/146341
Run-TryBot: Dmitry Vyukov <dvyukov@google.com>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Move startNano from runtime to time package.
In preparation for a subsequent change that speeds up Since and Until.
This also makes code simpler as we have less assembly as the result,
monotonic time handling is better localized in time package.
This changes values returned from nanotime on windows
(it does not account for startNano anymore), current comments state
that it's important, but it's unclear how it can be important
since no other OS does this.
Update #25729
Change-Id: I2275d57b7b5ed8fd0d53eb0f19d55a86136cc555
Reviewed-on: https://go-review.googlesource.com/c/146340
Reviewed-by: Ian Lance Taylor <iant@golang.org>
We have fixed the playground to display results of
the program when it was timed out.
This CL fixes how soon results will be displayed to the user.
Change-Id: Ifb75828e0de12c726c8ca6e2d04947e01913dc73
Reviewed-on: https://go-review.googlesource.com/c/146237
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
This commit adds AIX operating system to time package for ppc64
architecture.
Updates: #25893
Change-Id: I4fb6fb47eae7671bf4e22729d6d160f557083c44
Reviewed-on: https://go-review.googlesource.com/c/138721
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Unsuccessful calls to LoadLocation previously returned the first
error encountered while traversing the default list of sources, but
ignored errors from sources specified by ZONEINFO. Whether errors
indicating missing zones or sources were ignored in this process
differed between kinds of sources.
With this change, unsuccessful calls to LoadLocation always return
the first error, not counting errors indicating missing zones or
sources.
Change-Id: Ief2c088f1df53d974b837e6565e784c2b9928ef4
Reviewed-on: https://go-review.googlesource.com/c/81595
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
This makes Android consistent with the change in CL 121877.
Updates #20969
Change-Id: I1f114556fd1d4654c8e4e6a59513bddd5dc3d1a0
Reviewed-on: https://go-review.googlesource.com/135416
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Reviewed-by: Elias Naur <elias.naur@gmail.com>
Currently, when a tz file was being checked inside a zoneInfo dir,
a syscall.ENOENT error was being returned, which caused it to look
in the zoneinfo.zip file and return an error for that case.
We return a syscall.ENOENT error for the zip file case too, so that
it falls through to the end of the loop and returns an uniform error
for both cases.
Fixes#20969
Change-Id: If1de068022ac7693caabb5cffd1c929878460140
Reviewed-on: https://go-review.googlesource.com/121877
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
A timezone with a zero offset from UTC and without a three-letter
abbreviation will have a numeric name in timestamps: "+00".
There are currently two of them:
$ zdump Atlantic/Azores America/Scoresbysund
Atlantic/Azores Wed Aug 22 09:01:05 2018 +00
America/Scoresbysund Wed Aug 22 09:01:05 2018 +00
These two timestamp are rejected by Parse, since it doesn't allow for
zero offsets:
parsing time "Wed Aug 22 09:01:05 2018 +00": extra text: +00
This change modifies Parse to accept a +00 offset in numeric timezone
names.
As side effect of this change, Parse also now accepts "GMT+00". It was
explicitely disallowed (with a unit test ensuring it got rejected),
but the restriction seems incorrect.
DATE(1), for example, allows it:
$ date --debug --date="2009-01-02 03:04:05 GMT+00"
date: parsed date part: (Y-M-D) 2009-01-02
date: parsed time part: 03:04:05
date: parsed zone part: UTC+00
date: input timezone: parsed date/time string (+00)
date: using specified time as starting value: '03:04:05'
date: starting date/time: '(Y-M-D) 2009-01-02 03:04:05 TZ=+00'
date: '(Y-M-D) 2009-01-02 03:04:05 TZ=+00' = 1230865445 epoch-seconds
date: timezone: system default
date: final: 1230865445.000000000 (epoch-seconds)
date: final: (Y-M-D) 2009-01-02 03:04:05 (UTC)
date: final: (Y-M-D) 2009-01-02 04:04:05 (UTC+01)
Fri 2 Jan 04:04:05 CET 2009
This fixes 2 of 17 time.Parse() failures listed in Issue #26032.
Updates #26032
Change-Id: I01cd067044371322b7bb1dae452fb3c758ed3cc2
Reviewed-on: https://go-review.googlesource.com/130696
Run-TryBot: Alberto Donizetti <alb.donizetti@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
time.Parse currently rejects numeric timezones names with UTC offsets
bigger than +12, but this is incorrect: there's a +13 timezone and a
+14 timezone:
$ zdump Pacific/Kiritimati
Pacific/Kiritimati Mon Jun 25 02:15:03 2018 +14
For convenience, this cl changes the ranges of accepted offsets from
-14..+12 to -23..+23 (zero still excluded), i.e. every possible offset
that makes sense. We don't validate three-letter abbreviations for the
timezones names, so there's no need to be too strict on numeric names.
This change also fixes a bug in the parseTimeZone, that is currently
unconditionally returning true (i.e. valid timezone), without checking
the value returned by parseSignedOffset.
This fixes 5 of 17 time.Parse() failures listed in Issue #26032.
Updates #26032
Change-Id: I2f08ca9aa41ea4c6149ed35ed2dd8f23eeb42bff
Reviewed-on: https://go-review.googlesource.com/120558
Reviewed-by: Rob Pike <r@golang.org>
Use the same load order in big4 as in encoding/binary.BigEndian.
This order is recognized by the compiler and converted into single load.
This isn't in the hot path, but doesn't hurt readability, so lets do this.
Change-Id: Ib1240d0b278e9d667ad419fe91fa52b23d28cfc0
Reviewed-on: https://go-review.googlesource.com/130478
Run-TryBot: Ilya Tocar <ilya.tocar@intel.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
CL 52430 added logic to skip the testZoneAbbr test in locales where
the timezone does not have a three-letter name, because the following
line
Parse(RFC1123, t1.Format(RFC1123))
failed for timezones with only numeric names (like -07).
Since Go 1.11, Parse supports the parsing of timezones with numeric
names (this was implemented in CL 98157), so we can now run the test
unconditionally.
Change-Id: I8ed40e1ba325c0c0dc79c4184a9e71209e2e9a02
Reviewed-on: https://go-review.googlesource.com/127757
Run-TryBot: Alberto Donizetti <alb.donizetti@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Issues #10043, #15405, and #22660 appear to have been fixed, and
whatever tests I could run locally do succeed, so remove the skips.
Issue #7237 was closed in favor of #17906, so update its skip line.
Issue #7634 was closed as it had not appeared for over three years.
Re-enable it for now. An issue should be open if the test starts being
skipped again.
Change-Id: I67daade906744ed49223291035baddaad9f56dca
Reviewed-on: https://go-review.googlesource.com/121735
Run-TryBot: Daniel Martí <mvdan@mvdan.cc>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
The existing example code uses variable name d, but
prints t in its output. It's needlessly confusing.
Change-Id: I67bef3c732e84d2d89819f96b4b62663630fd69e
Reviewed-on: https://go-review.googlesource.com/123516
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
The abbreviations list in zoneinfo_abbrs_windows.go was last updated
in June 2017, and it's currently outdated. Update it.
Change-Id: Ie2bf4268787f5aefe98ee110c2c279451e18fd97
Reviewed-on: https://go-review.googlesource.com/120559
Run-TryBot: Alberto Donizetti <alb.donizetti@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Alex Brainman <alex.brainman@gmail.com>
If we run into data corruption due to the program accessing timers in
a racy way, do a normal panic rather than a hard crash with "panic
holding locks". The hope is to make the problem less confusing for users.
Fixes#25686
Change-Id: I863417adf21f7f8c088675b67a3acf49a0cdef41
Reviewed-on: https://go-review.googlesource.com/115815
Reviewed-by: Austin Clements <austin@google.com>
Each URL was manually verified to ensure it did not serve up incorrect
content.
Change-Id: I4dc846227af95a73ee9a3074d0c379ff0fa955df
Reviewed-on: https://go-review.googlesource.com/115798
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Run-TryBot: Ian Lance Taylor <iant@golang.org>
fmt's %d, %x, and %X all accept pointer arguments. However, in cmd/vet's
printVerbs table, they were defined as if they did not accept pointer
arguments.
This inconsistency with fmt did not manifest to users since the vet
codebase worked around it. In particular, pointer arguments were usually
allowed for verbs that accepted integers, as the *types.Pointer argument
type case read the following:
t&(argInt|argPointer) != 0
As a result, using the %q verb with a pointer resulted in a bug in
cmd/vet:
$ go run f.go
%!q(*int=0xc000014140)
$ go vet f.go
[no warning]
As documented, fmt's %q verb only accepts runes (integers), strings, and
byte slices. It should not accept pointers, and it does not. But since
vet mixed integers and pointers, it wasn't properly warning about the
misuse of fmt.
This patch surfaced another bug with fmt.Printf("%p", nil):
$ go run f.go
%!p(<nil>)
$ go vet f.go
[no warning]
As documented, fmt's %p verb only accepts pointers, and untyped nil is
not a valid pointer. But vet did not warn about it, which is another
inconsistency with fmt's documented rules. Fix that too, with a test,
also getting rid of the TODO associated with the code.
As a result of those changes, fix a wrong use of the fmt format verbs in
the standard library, now correctly spotted by vet.
Fixes#25233.
Change-Id: Id0ad31fbc25adfe1c46c6b6879b8d02b23633b3a
Reviewed-on: https://go-review.googlesource.com/111284
Run-TryBot: Daniel Martí <mvdan@mvdan.cc>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Alan Donovan <adonovan@google.com>