zhangjq 6 gadi atpakaļ
vecāks
revīzija
6cb6af2973
1 mainītis faili ar 11 papildinājumiem un 7 dzēšanām
  1. 11 7
      models/LocalTime.go

+ 11 - 7
models/time.go → models/LocalTime.go

@@ -5,17 +5,21 @@ import (
 	"time"
 )
 
-type Time time.Time
+type LocalTime time.Time
+
+func  init()  {
+	AddTableName("local_time")
+}
 
 const (
 	timeFormat = "2006-01-02 15:04:05"
 )
 
-func NowLocal() Time {
-	return Time(time.Now())
+func NowLocal() LocalTime {
+	return LocalTime(time.Now())
 }
 
-func (t *Time) UnmarshalJSON(data []byte) error {
+func (t *LocalTime) UnmarshalJSON(data []byte) error {
 	if data[0] == '"' && data[len(data)-1] == '"' {
 		data = data[1 : len(data)-1]
 	}
@@ -23,7 +27,7 @@ func (t *Time) UnmarshalJSON(data []byte) error {
 	dataStr := strings.TrimSpace(string(data))
 	if dataStr == "" {
 		now, err := time.ParseInLocation(timeFormat, string(data), time.Local)
-		*t = Time(now)
+		*t = LocalTime(now)
 		return err
 	}
 
@@ -49,12 +53,12 @@ func (t *Time) UnmarshalJSON(data []byte) error {
 
 	now, err = time.ParseInLocation(timeFormat, dataStr, time.Local)
 
-	*t = Time(now)
+	*t = LocalTime(now)
 
 	return err
 }
 
-func (t Time) MarshalJSON() ([]byte, error) {
+func (t LocalTime) MarshalJSON() ([]byte, error) {
 	b := make([]byte, 0, len(timeFormat)+2)
 	b = append(b, '"')
 	b = time.Time(t).AppendFormat(b, timeFormat)