-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
244 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package common | ||
|
||
import ( | ||
"strings" | ||
"time" | ||
) | ||
|
||
type CustomTime struct { | ||
time.Time | ||
} | ||
|
||
var locCST = time.FixedZone("CST", 8*3600) | ||
|
||
func (ct *CustomTime) UnmarshalJSON(data []byte) error { | ||
s := strings.Trim(string(data), `"`) | ||
// Ignore null, like in the main JSON package. | ||
if s == "null" { | ||
return nil | ||
} | ||
// Fractional seconds are handled implicitly by Parse. | ||
var err error | ||
ct.Time, err = time.Parse(time.RFC3339, s) | ||
if err != nil { | ||
ct.Time, err = time.ParseInLocation(`2006-01-02T15:04:05`, s, locCST) | ||
} | ||
return err | ||
} | ||
|
||
func (ct *CustomTime) UnmarshalText(data []byte) error { | ||
s := strings.Trim(string(data), `"`) | ||
// Ignore null, like in the main JSON package. | ||
if s == "" { | ||
return nil | ||
} | ||
// Fractional seconds are handled implicitly by Parse. | ||
var err error | ||
ct.Time, err = time.Parse(time.RFC3339, s) | ||
if err != nil { | ||
ct.Time, err = time.ParseInLocation(`2006-01-02T15:04:05`, s, locCST) | ||
} | ||
return err | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters