]> Cypherpunks repositories - gostls13.git/commitdiff
time: change formatting of microseconds duration to SI modifier
authorRob Pike <r@golang.org>
Fri, 13 Jun 2014 00:01:13 +0000 (17:01 -0700)
committerRob Pike <r@golang.org>
Fri, 13 Jun 2014 00:01:13 +0000 (17:01 -0700)
'u' is not micro, µ (U+00B5) is.

LGTM=gri, bradfitz
R=golang-codereviews, bradfitz, gri
CC=golang-codereviews
https://golang.org/cl/105030046

src/pkg/time/example_test.go
src/pkg/time/time.go
src/pkg/time/time_test.go

index cfa5b38c5f13e86fb8b902b77368935adacd3124..a37e8b86ddcb2254a04b09f751de19f84d576465 100644 (file)
@@ -122,7 +122,7 @@ func ExampleTime_Round() {
        }
        // Output:
        // t.Round(   1ns) = 12:15:30.918273645
-       // t.Round(   1us) = 12:15:30.918274
+       // t.Round(   1µs) = 12:15:30.918274
        // t.Round(   1ms) = 12:15:30.918
        // t.Round(    1s) = 12:15:31
        // t.Round(    2s) = 12:15:30
@@ -150,7 +150,7 @@ func ExampleTime_Truncate() {
 
        // Output:
        // t.Truncate(   1ns) = 12:15:30.918273645
-       // t.Truncate(   1us) = 12:15:30.918273
+       // t.Truncate(   1µs) = 12:15:30.918273
        // t.Truncate(   1ms) = 12:15:30.918
        // t.Truncate(    1s) = 12:15:30
        // t.Truncate(    2s) = 12:15:30
index 0a2b0914283e8f85622934976944fb843c1c509f..fa449c052d9b9ff98b955b41d7fe6af771b7ed31 100644 (file)
@@ -475,29 +475,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 {
index 4ae7da5a443a6706089f9e8bd7b5f3b35e3a5fff..7e31dd78a926276bc69148fc868a3fc1b955da3b 100644 (file)
@@ -535,7 +535,7 @@ var durationTests = []struct {
 }{
        {"0", 0},
        {"1ns", 1 * Nanosecond},
-       {"1.1us", 1100 * Nanosecond},
+       {"1.1µs", 1100 * Nanosecond},
        {"2.2ms", 2200 * Microsecond},
        {"3.3s", 3300 * Millisecond},
        {"4m5s", 4*Minute + 5*Second},