1 | // Copyright 2022 The Go Authors. All rights reserved. |
---|---|
2 | // Use of this source code is governed by a BSD-style |
3 | // license that can be found in the LICENSE file. |
4 | |
5 | // This file contains tests for the timeformat checker. |
6 | |
7 | package a |
8 | |
9 | import ( |
10 | "time" |
11 | |
12 | "b" |
13 | ) |
14 | |
15 | func hasError() { |
16 | a, _ := time.Parse("2006-02-01 15:04:05", "2021-01-01 00:00:00") // want `2006-02-01 should be 2006-01-02` |
17 | a.Format(`2006-02-01`) // want `2006-02-01 should be 2006-01-02` |
18 | a.Format("2006-02-01 15:04:05") // want `2006-02-01 should be 2006-01-02` |
19 | |
20 | const c = "2006-02-01" |
21 | a.Format(c) // want `2006-02-01 should be 2006-01-02` |
22 | } |
23 | |
24 | func notHasError() { |
25 | a, _ := time.Parse("2006-01-02 15:04:05", "2021-01-01 00:00:00") |
26 | a.Format("2006-01-02") |
27 | |
28 | const c = "2006-01-02" |
29 | a.Format(c) |
30 | |
31 | v := "2006-02-01" |
32 | a.Format(v) // Allowed though variables. |
33 | |
34 | m := map[string]string{ |
35 | "y": "2006-02-01", |
36 | } |
37 | a.Format(m["y"]) |
38 | |
39 | s := []string{"2006-02-01"} |
40 | a.Format(s[0]) |
41 | |
42 | a.Format(badFormat()) |
43 | |
44 | o := b.Parse("2006-02-01 15:04:05", "2021-01-01 00:00:00") |
45 | o.Format("2006-02-01") |
46 | } |
47 | |
48 | func badFormat() string { |
49 | return "2006-02-01" |
50 | } |
51 |
Members