Skip to content

Commit 42b8f76

Browse files
committed
update RELEASE
1 parent 9b65e1a commit 42b8f76

File tree

7 files changed

+83
-6
lines changed

7 files changed

+83
-6
lines changed

.github/RELEASE.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
## Change log
22

3-
- Optimize error codes and logs.
4-
- Change protobuf demo.
3+
1. Change page field size to limit.
4+
2. Supporting custom bingdingXXX and response in the web(protobuf).
5+
3. Match message name xxxID in the protobuf file.

internal/handler/userExample_logic.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,8 +179,8 @@ func convertUserExamplePb(record *model.UserExample) (*serverNameExampleV1.UserE
179179
if err != nil {
180180
return nil, err
181181
}
182+
// Note: if copier.Copy cannot assign a value to a field, add it here, e.g. CreatedAt, UpdatedAt
182183
value.Id = record.ID
183-
// todo if copier.Copy cannot assign a value to a field, add it here, e.g. CreatedAt, UpdatedAt
184184
// todo generate the conversion createdAt and updatedAt code here
185185
// delete the templates code start
186186
value.CreatedAt = record.CreatedAt.Format(time.RFC3339)

internal/handler/userExample_logic.go.exp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -300,8 +300,8 @@ func convertUserExamplePb(record *model.UserExample) (*serverNameExampleV1.UserE
300300
if err != nil {
301301
return nil, err
302302
}
303+
// Note: if copier.Copy cannot assign a value to a field, add it here, e.g. CreatedAt, UpdatedAt
303304
value.Id = record.ID
304-
// todo if copier.Copy cannot assign a value to a field, add it here, e.g. CreatedAt, UpdatedAt
305305
// todo generate the conversion createdAt and updatedAt code here
306306
// delete the templates code start
307307
value.CreatedAt = record.CreatedAt.Format(time.RFC3339)

internal/handler/userExample_logic.go.mgo

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,8 +179,8 @@ func convertUserExamplePb(record *model.UserExample) (*serverNameExampleV1.UserE
179179
if err != nil {
180180
return nil, err
181181
}
182+
// Note: if copier.Copy cannot assign a value to a field, add it here, e.g. CreatedAt, UpdatedAt
182183
value.Id = record.ID.Hex()
183-
// todo if copier.Copy cannot assign a value to a field, add it here, e.g. CreatedAt, UpdatedAt
184184
// todo generate the conversion createdAt and updatedAt code here
185185
// delete the templates code start
186186
value.CreatedAt = record.CreatedAt.Format(time.RFC3339)

internal/handler/userExample_logic.go.mgo.exp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -300,8 +300,8 @@ func convertUserExamplePb(record *model.UserExample) (*serverNameExampleV1.UserE
300300
if err != nil {
301301
return nil, err
302302
}
303+
// Note: if copier.Copy cannot assign a value to a field, add it here, e.g. CreatedAt, UpdatedAt
303304
value.Id = record.ID.Hex()
304-
// todo if copier.Copy cannot assign a value to a field, add it here, e.g. CreatedAt, UpdatedAt
305305
// todo generate the conversion createdAt and updatedAt code here
306306
// delete the templates code start
307307
value.CreatedAt = record.CreatedAt.Format(time.RFC3339)

pkg/utils/time.go

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
package utils
2+
3+
import "time"
4+
5+
const (
6+
// DateTimeLayout is the layout string for datetime format.
7+
DateTimeLayout = "2006-01-02 15:04:05"
8+
9+
// DateTimeLayoutWithMS is the layout string for datetime format with milliseconds.
10+
DateTimeLayoutWithMS = "2006-01-02 15:04:05.000"
11+
12+
// DateTimeLayoutWithMSAndTZ is the layout string for datetime format with milliseconds and timezone.
13+
DateTimeLayoutWithMSAndTZ = "2006-01-02T15:04:05.000Z"
14+
15+
// TimeLayout is the layout string for time format.
16+
TimeLayout = "15:04:05"
17+
18+
// DateLayout is the layout string for date format.
19+
DateLayout = "2006-01-02"
20+
)
21+
22+
// FormatDateTime formats the given time to string
23+
func FormatDateTime(t time.Time, format string) string {
24+
switch format {
25+
case DateTimeLayoutWithMS:
26+
return t.Format(DateTimeLayoutWithMS)
27+
case DateTimeLayoutWithMSAndTZ:
28+
return t.UTC().Format(DateTimeLayoutWithMSAndTZ)
29+
case TimeLayout:
30+
return t.Format(TimeLayout)
31+
case DateLayout:
32+
return t.Format(DateLayout)
33+
default:
34+
return t.Format(DateTimeLayout)
35+
}
36+
}
37+
38+
// ParseDateTime parses the given string to time
39+
func ParseDateTime(s string, format string) (time.Time, error) {
40+
switch format {
41+
case DateTimeLayoutWithMS:
42+
return time.Parse(DateTimeLayoutWithMS, s)
43+
case DateTimeLayoutWithMSAndTZ:
44+
return time.Parse(DateTimeLayoutWithMSAndTZ, s)
45+
case TimeLayout:
46+
return time.Parse(TimeLayout, s)
47+
case DateLayout:
48+
return time.Parse(DateLayout, s)
49+
default:
50+
return time.Parse(DateTimeLayout, s)
51+
}
52+
}

pkg/utils/time_test.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package utils
2+
3+
import (
4+
"testing"
5+
"time"
6+
)
7+
8+
func TestFormatAndParseDateTime(t *testing.T) {
9+
layouts := []string{
10+
DateTimeLayout,
11+
DateTimeLayoutWithMS,
12+
DateTimeLayoutWithMSAndTZ,
13+
TimeLayout,
14+
DateLayout,
15+
}
16+
17+
now := time.Now()
18+
19+
for _, layout := range layouts {
20+
str := FormatDateTime(now, layout)
21+
ti, err := ParseDateTime(str, layout)
22+
t.Log(str, ti.Second() == now.Second(), err)
23+
}
24+
}

0 commit comments

Comments
 (0)