1
0
mirror of https://github.com/golang/go synced 2024-11-18 23:34:45 -07:00
Commit Graph

197 Commits

Author SHA1 Message Date
Pantelis Sampaziotis
575386d632 time: add examples for microseconds and milliseconds methods
This change adds testable examples for the new Microseconds and Milliseconds methods that were introduced in Go 1.13.

Fixes #34354

Change-Id: Ibdbfd770ca2192f9086f756918325f7327ce0482
GitHub-Last-Rev: 4575f48f5f
GitHub-Pull-Request: golang/go#34355
Reviewed-on: https://go-review.googlesource.com/c/go/+/195979
Reviewed-by: Alexander Rakoczy <alex@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Run-TryBot: Alexander Rakoczy <alex@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2019-09-17 20:11:12 +00:00
Joe Tsai
c485506b0a time: update TestSub to avoid future regressions
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>
2019-08-16 19:54:57 +00:00
Joe Tsai
4983a0b75b Revert "time: optimize Sub"
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>
2019-08-16 17:01:35 +00:00
Allen Li
ba3149612f time: clarify when draining a Timer's channel is needed
Updates #27169

Change-Id: I22a6194c06529ba70b1ec648e3188c191224e321
GitHub-Last-Rev: 457b2a61a8
GitHub-Pull-Request: golang/go#32996
Reviewed-on: https://go-review.googlesource.com/c/go/+/185245
Reviewed-by: Rob Pike <r@golang.org>
2019-07-18 20:43:28 +00:00
Nikita Kryuchkov
2fd97ee25e time: fix a typo in comments
Change-Id: I407d7215d077176678a714ff1446e987bb818f7c
GitHub-Last-Rev: 22012adb3a
GitHub-Pull-Request: golang/go#31988
Reviewed-on: https://go-review.googlesource.com/c/go/+/176797
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2019-05-13 14:06:50 +00:00
Elias Naur
b39daa7a11 os,time: fix tests on iOS
When fixing tests for for self-hosted iOS builds, I
broke hosted builds.

Updates #31722

Change-Id: Id4e7d234fbd86cb2d29d320d75f4441efd663d12
Reviewed-on: https://go-review.googlesource.com/c/go/+/174698
Run-TryBot: Elias Naur <mail@eliasnaur.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2019-05-01 13:53:44 +00:00
Elias Naur
8e4f1a71f2 time: look for zoneinfo.zip in GOROOT
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>
2019-04-30 19:13:43 +00:00
LE Manh Cuong
8feeada50c time: fix misleading error with the leading zero format
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 #29918
Fixes #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>
2019-04-26 14:01:55 +00:00
Michael Darakananda
6f7bb2cab6 time: optimize Sub
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>
2019-03-19 04:10:33 +00:00
Derek Phan
aa193c0b96 time: add methods to convert duration to microseconds and milliseconds
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>
2019-03-14 18:27:01 +00:00
Russ Cox
6a9da69147 time: add support for day-of-year in Format and Parse
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>
2019-03-08 01:21:33 +00:00
Rob Pike
61170f85e6 time: move the explanation of u/micro to the ParseDuration example
Fix a few missing capitalizations in drive-by.

Change-Id: I7353c12f3ccddefc0f26a98590caf9e446129558
Reviewed-on: https://go-review.googlesource.com/c/163918
Run-TryBot: Rob Pike <r@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2019-02-28 00:24:56 +00:00
Josh Bleecher Snyder
58bf401293 time: reject tzdata with no zones
Fixes #29437

Change-Id: Ice0a03a543e564d66651bfdfce5cd32ebaa35926
Reviewed-on: https://go-review.googlesource.com/c/155746
Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2019-02-27 18:08:03 +00:00
Rob Pike
9426d8c633 time: rewrite ExampleDuration_Nanoseconds to be more idiomatic.
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>
2019-02-27 02:20:28 +00:00
Ian Lance Taylor
068a832a7e time: read 64-bit data if available
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>
2019-02-26 23:10:35 +00:00
Alberto Donizetti
c0101b1961 time: parse 1us in Nanoseconds example
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>
2019-02-26 17:22:58 +00:00
Max Ushakov
652d59861e time: return ENOENT if a zoneinfo zip file is not found
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>
2018-12-24 19:25:18 +00:00
Tobias Klauser
9e277f7d55 all: use "reports whether" consistently instead of "returns whether"
Follow-up for CL 147037 and after Brad noticed the "returns whether"
pattern during the review of CL 150621.

Go documentation style for boolean funcs is to say:

    // Foo reports whether ...
    func Foo() bool

(rather than "returns whether")

Created with:

    $ perl -i -npe 's/returns whether/reports whether/' $(git grep -l "returns whether" | grep -v vendor)

Change-Id: I15fe9ff99180ad97750cd05a10eceafdb12dc0b4
Reviewed-on: https://go-review.googlesource.com/c/150918
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2018-12-02 15:12:26 +00:00
Agniva De Sarker
742be070b6 time: add a missing comma in the documentation of Time
Updates #28421

Change-Id: I3262c83669bc3cefd2cea6a612e3dc1d4318b2c2
Reviewed-on: https://go-review.googlesource.com/c/148339
Reviewed-by: Rob Pike <r@golang.org>
2018-11-08 18:02:11 +00:00
Agniva De Sarker
5e9ad4a9b4 time: handle negative offsets on js/wasm
Fixes #28649

Change-Id: I9f6807ee3c3007f670dd509780805c7b255a2bda
Reviewed-on: https://go-review.googlesource.com/c/148338
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2018-11-08 17:33:49 +00:00
Agniva De Sarker
d258bac41c time: document that a marshaled time does not include location name
Fixes #28421

Change-Id: I00878ec246d5249d910f2b57749f74cfc38dbec6
Reviewed-on: https://go-review.googlesource.com/c/148117
Reviewed-by: Rob Pike <r@golang.org>
2018-11-08 05:41:45 +00:00
Clément Chigot
bd4b6ca781 all: fix tests for older versions of AIX 7.2
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>
2018-11-02 13:44:27 +00:00
Dmitry Vyukov
ff51353c38 runtime: move nanotime wrappers to time and poll packages
The nanotime wrappers in runtime introduce a bunch
of unnecessary code onto hot paths, e.g.:

0000000000449d70 <time.runtimeNano>:
  449d70:       64 48 8b 0c 25 f8 ff    mov    %fs:0xfffffffffffffff8,%rcx
  449d77:       ff ff
  449d79:       48 3b 61 10             cmp    0x10(%rcx),%rsp
  449d7d:       76 26                   jbe    449da5 <time.runtimeNano+0x35>
  449d7f:       48 83 ec 10             sub    $0x10,%rsp
  449d83:       48 89 6c 24 08          mov    %rbp,0x8(%rsp)
  449d88:       48 8d 6c 24 08          lea    0x8(%rsp),%rbp
  449d8d:       e8 ae 18 01 00          callq  45b640 <runtime.nanotime>
  449d92:       48 8b 04 24             mov    (%rsp),%rax
  449d96:       48 89 44 24 18          mov    %rax,0x18(%rsp)
  449d9b:       48 8b 6c 24 08          mov    0x8(%rsp),%rbp
  449da0:       48 83 c4 10             add    $0x10,%rsp
  449da4:       c3                      retq
  449da5:       e8 56 e0 00 00          callq  457e00 <runtime.morestack_noctxt>
  449daa:       eb c4                   jmp    449d70 <time.runtimeNano>

Move them to the corresponding packages which eliminates all of this.

name                  old time/op  new time/op  delta
TCP4OneShotTimeout-6  17.1µs ± 1%  17.0µs ± 0%  -0.66%  (p=0.032 n=5+5)
SetReadDeadline-6      234ns ± 1%   232ns ± 0%  -0.77%  (p=0.016 n=5+4)

Update #25729

Change-Id: Iee05027adcdc289ba895c5f5a37f154e451bc862
Reviewed-on: https://go-review.googlesource.com/c/146342
Run-TryBot: Dmitry Vyukov <dvyukov@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2018-11-02 12:52:30 +00:00
Dmitry Vyukov
fc3f8d43f1 time: speed up Since and Until
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>
2018-11-02 12:50:18 +00:00
Dmitry Vyukov
a1ee0a21cf runtime, time: refactor startNano handling
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>
2018-11-02 12:50:03 +00:00
Yury Smolsky
86ad85ce98 time: display results in examples rather soon
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>
2018-10-31 16:29:40 +00:00
Agniva De Sarker
eef0140137 time: return correct zone info on js/wasm
Fixes #28265

Change-Id: I0a13e9f9c216647e42127a59a80b0f19618169c1
Reviewed-on: https://go-review.googlesource.com/c/143577
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Reviewed-by: Richard Musiol <neelance@gmail.com>
2018-10-24 15:42:36 +00:00
Clément Chigot
1c88ce5f7b time: add AIX operating system
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>
2018-10-10 14:15:57 +00:00
Florian Uekermann
048de7b1fd time: return first error in unsuccessful calls to LoadLocation
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>
2018-10-03 17:40:17 +00:00
Ian Lance Taylor
fb061b5e11 time: return ENOENT from androidLoadTzinfoFromTzdata if zone not found
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>
2018-09-15 14:58:35 +00:00
Agniva De Sarker
7df585d13d time: improve error message for LoadLocation
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>
2018-09-14 20:51:22 +00:00
Venil Noronha
e84409ac95 time: add example for LoadLocation
Change-Id: I8e55e9397eb6844b5856f8bde9c26185c446a80e
Reviewed-on: https://go-review.googlesource.com/132238
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2018-08-30 19:38:38 +00:00
Alberto Donizetti
38143badf1 time: allow +00 as numeric timezone name and GMT offset
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>
2018-08-24 17:31:42 +00:00
Kazuhiro Sera
ad644d2e86 all: fix typos detected by github.com/client9/misspell
Change-Id: Iadb3c5de8ae9ea45855013997ed70f7929a88661
GitHub-Last-Rev: ae85bcf82b
GitHub-Pull-Request: golang/go#26920
Reviewed-on: https://go-review.googlesource.com/128955
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2018-08-23 15:54:07 +00:00
Alberto Donizetti
2ce8411239 time: accept anything between -23 and 23 as offset namezone name
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>
2018-08-21 22:47:11 +00:00
Ilya Tocar
08cc3dc5e7 time: optimize big4
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>
2018-08-21 20:12:35 +00:00
Sandy
15c362a260 time: use secondsPerMinute instead of 60
It's maybe better.

Change-Id: I7929e93a95c96676915bc24f2f7cce4e73b08c59
GitHub-Last-Rev: a8c2bb6caf
GitHub-Pull-Request: golang/go#26685
Reviewed-on: https://go-review.googlesource.com/126623
Reviewed-by: Ralph Corderoy <ralph@inputplus.co.uk>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2018-08-21 04:38:18 +00:00
Alberto Donizetti
099498db0e time: always run ZoneAbbr test
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>
2018-08-20 14:39:59 +00:00
Daniel Martí
9e4d87d115 all: update stale test skips
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>
2018-08-20 13:10:24 +00:00
Keith Rarick
33c7f88eaf time: fix typo in Truncate example
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>
2018-07-12 15:01:16 +00:00
Caleb Martinez
a07ee41a33 time: add clarification to Timer.Stop documentation
Fixes #26220

Change-Id: I05703912be594d985ad3ccb3a9757ae21ec738ab
GitHub-Last-Rev: e4649847e0
GitHub-Pull-Request: golang/go#26293
Reviewed-on: https://go-review.googlesource.com/122715
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2018-07-11 22:06:22 +00:00
Brad Fitzpatrick
3198b90ea8 time: clarify Unix, UnixNano, and In a bit
Fixes #23316

Change-Id: Ia1758b406d369bbfaace0bdfea02cd6f40735b65
Reviewed-on: https://go-review.googlesource.com/120060
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2018-06-29 23:01:49 +00:00
Alberto Donizetti
97fa89497d time: run genzabbrs.go to update zoneinfo_abbrs_windows.go
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>
2018-06-26 09:55:39 +00:00
Ian Lance Taylor
d6c3b0a56d runtime: don't crash holding locks on racy timer access
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>
2018-06-04 18:33:41 +00:00
Tim Cooper
161874da2a all: update comment URLs from HTTP to HTTPS, where possible
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>
2018-06-01 21:52:00 +00:00
Daniel Martí
98409a44d5 cmd/vet: better align print warnings with fmt
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>
2018-05-04 02:57:37 +00:00
tengufromsky
1670921a07 time: increase test coverage for Time.Sub
Existing tests don't check overflow and underflow case for subtraction
monotonic time.

Updates #17858

Change-Id: I95311440134c92eadd7d5e409a0fc7c689e9bf41
Reviewed-on: https://go-review.googlesource.com/107056
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2018-04-16 21:14:40 +00:00
Kunpei Sakai
0164ada30f time: go fmt
Change-Id: I0e6b308333b84409bb0bb034c17fef9b63ad44c4
Reviewed-on: https://go-review.googlesource.com/107377
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2018-04-16 15:26:44 +00:00
Richard Musiol
70d83eda99 time: add wasm architecture
This commit adds the wasm architecture to the time package.

Updates #18892

Change-Id: I86841e096894eacf7f972add9a532491e4d00014
Reviewed-on: https://go-review.googlesource.com/106997
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2018-04-13 21:12:31 +00:00
Ian Lance Taylor
c96ac60bcd time: document that going to sleep may stop the monotonic clock
Fixes #23178

Change-Id: I060a73d6263bc135f5a14c1991932a225208bb39
Reviewed-on: https://go-review.googlesource.com/103396
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2018-04-13 00:50:22 +00:00