Skip to content

Commit

Permalink
update RELEASE
Browse files Browse the repository at this point in the history
  • Loading branch information
zhufuyi committed Jul 27, 2024
1 parent 9b65e1a commit 42b8f76
Show file tree
Hide file tree
Showing 7 changed files with 83 additions and 6 deletions.
5 changes: 3 additions & 2 deletions .github/RELEASE.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
## Change log

- Optimize error codes and logs.
- Change protobuf demo.
1. Change page field size to limit.
2. Supporting custom bingdingXXX and response in the web(protobuf).
3. Match message name xxxID in the protobuf file.
2 changes: 1 addition & 1 deletion internal/handler/userExample_logic.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,8 +179,8 @@ func convertUserExamplePb(record *model.UserExample) (*serverNameExampleV1.UserE
if err != nil {
return nil, err
}
// Note: if copier.Copy cannot assign a value to a field, add it here, e.g. CreatedAt, UpdatedAt
value.Id = record.ID
// todo if copier.Copy cannot assign a value to a field, add it here, e.g. CreatedAt, UpdatedAt
// todo generate the conversion createdAt and updatedAt code here
// delete the templates code start
value.CreatedAt = record.CreatedAt.Format(time.RFC3339)
Expand Down
2 changes: 1 addition & 1 deletion internal/handler/userExample_logic.go.exp
Original file line number Diff line number Diff line change
Expand Up @@ -300,8 +300,8 @@ func convertUserExamplePb(record *model.UserExample) (*serverNameExampleV1.UserE
if err != nil {
return nil, err
}
// Note: if copier.Copy cannot assign a value to a field, add it here, e.g. CreatedAt, UpdatedAt
value.Id = record.ID
// todo if copier.Copy cannot assign a value to a field, add it here, e.g. CreatedAt, UpdatedAt
// todo generate the conversion createdAt and updatedAt code here
// delete the templates code start
value.CreatedAt = record.CreatedAt.Format(time.RFC3339)
Expand Down
2 changes: 1 addition & 1 deletion internal/handler/userExample_logic.go.mgo
Original file line number Diff line number Diff line change
Expand Up @@ -179,8 +179,8 @@ func convertUserExamplePb(record *model.UserExample) (*serverNameExampleV1.UserE
if err != nil {
return nil, err
}
// Note: if copier.Copy cannot assign a value to a field, add it here, e.g. CreatedAt, UpdatedAt
value.Id = record.ID.Hex()
// todo if copier.Copy cannot assign a value to a field, add it here, e.g. CreatedAt, UpdatedAt
// todo generate the conversion createdAt and updatedAt code here
// delete the templates code start
value.CreatedAt = record.CreatedAt.Format(time.RFC3339)
Expand Down
2 changes: 1 addition & 1 deletion internal/handler/userExample_logic.go.mgo.exp
Original file line number Diff line number Diff line change
Expand Up @@ -300,8 +300,8 @@ func convertUserExamplePb(record *model.UserExample) (*serverNameExampleV1.UserE
if err != nil {
return nil, err
}
// Note: if copier.Copy cannot assign a value to a field, add it here, e.g. CreatedAt, UpdatedAt
value.Id = record.ID.Hex()
// todo if copier.Copy cannot assign a value to a field, add it here, e.g. CreatedAt, UpdatedAt
// todo generate the conversion createdAt and updatedAt code here
// delete the templates code start
value.CreatedAt = record.CreatedAt.Format(time.RFC3339)
Expand Down
52 changes: 52 additions & 0 deletions pkg/utils/time.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package utils

import "time"

const (
// DateTimeLayout is the layout string for datetime format.
DateTimeLayout = "2006-01-02 15:04:05"

// DateTimeLayoutWithMS is the layout string for datetime format with milliseconds.
DateTimeLayoutWithMS = "2006-01-02 15:04:05.000"

// DateTimeLayoutWithMSAndTZ is the layout string for datetime format with milliseconds and timezone.
DateTimeLayoutWithMSAndTZ = "2006-01-02T15:04:05.000Z"

// TimeLayout is the layout string for time format.
TimeLayout = "15:04:05"

// DateLayout is the layout string for date format.
DateLayout = "2006-01-02"
)

// FormatDateTime formats the given time to string
func FormatDateTime(t time.Time, format string) string {
switch format {
case DateTimeLayoutWithMS:
return t.Format(DateTimeLayoutWithMS)
case DateTimeLayoutWithMSAndTZ:
return t.UTC().Format(DateTimeLayoutWithMSAndTZ)
case TimeLayout:
return t.Format(TimeLayout)
case DateLayout:
return t.Format(DateLayout)
default:
return t.Format(DateTimeLayout)
}
}

// ParseDateTime parses the given string to time
func ParseDateTime(s string, format string) (time.Time, error) {
switch format {
case DateTimeLayoutWithMS:
return time.Parse(DateTimeLayoutWithMS, s)
case DateTimeLayoutWithMSAndTZ:
return time.Parse(DateTimeLayoutWithMSAndTZ, s)
case TimeLayout:
return time.Parse(TimeLayout, s)
case DateLayout:
return time.Parse(DateLayout, s)
default:
return time.Parse(DateTimeLayout, s)
}
}
24 changes: 24 additions & 0 deletions pkg/utils/time_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package utils

import (
"testing"
"time"
)

func TestFormatAndParseDateTime(t *testing.T) {
layouts := []string{
DateTimeLayout,
DateTimeLayoutWithMS,
DateTimeLayoutWithMSAndTZ,
TimeLayout,
DateLayout,
}

now := time.Now()

for _, layout := range layouts {
str := FormatDateTime(now, layout)
ti, err := ParseDateTime(str, layout)
t.Log(str, ti.Second() == now.Second(), err)
}
}

0 comments on commit 42b8f76

Please sign in to comment.