Skip to content
Browse files

Merge from github (pull request #1)

  • Loading branch information...
2 parents e2a185f + ff2eda8 commit 93db657e6331812655d1a0834bb7ddb9c0432272 @tebeka committed
Showing with 10 additions and 9 deletions.
  1. +1 −0 .gitignore
  2. +1 −1 doc.go
  3. +6 −6 jtime.go
  4. +2 −2 jtime_test.go
View
1 .gitignore
@@ -0,0 +1 @@
+README.html
View
2 doc.go
@@ -6,7 +6,7 @@ Use jtime.Time in your struct, and before calling json.Marshal/json.Unmarashal
set the marshaller using SetMarshaller.
You can either write your own marshaller or use two of the available marshallers:
-* FormatMashaller uses time.Time format to marshal/unmarshal time as JSON strings
+* FormatMarshaller uses time.Time format to marshal/unmarshal time as JSON strings
* UnixMarshaler marshal time.Time to JSON integers (with or without msec)
jtime.Time embeds time.Time so you can use all time.Time methods with it.
View
12 jtime.go
@@ -28,18 +28,18 @@ func SetMarshaler(m Marshaler) {
marshaler = m
}
-// FormatMashaler uses time.Time format strings
-type FormatMashaler struct {
+// FormatMarshaler uses time.Time format strings
+type FormatMarshaler struct {
Format string
}
// Marshal will marshal to JSON string in Format
-func (fm *FormatMashaler) Marshal(t Time) ([]byte, error) {
+func (fm *FormatMarshaler) Marshal(t Time) ([]byte, error) {
return []byte(`"` + t.Format(fm.Format) + `"`), nil
}
// Unmarshal from JSON string in Format
-func (fm *FormatMashaler) Unmarshal(data []byte) (Time, error) {
+func (fm *FormatMarshaler) Unmarshal(data []byte) (Time, error) {
if len(data) < 2 {
return Time{}, fmt.Errorf("data too short - %v", data)
}
@@ -92,7 +92,7 @@ func validJSONTime(t Time) bool {
// MarshalJSON implements the json.Marshaler interface.
func (t Time) MarshalJSON() ([]byte, error) {
if !validJSONTime(t) {
- return nil, fmt.Errorf("vtime.Time.MarshalJson: year outside of range [0,9999]")
+ return nil, fmt.Errorf("jtime.Time.MarshalJson: year outside of range [0,9999]")
}
return marshaler.Marshal(t)
}
@@ -105,5 +105,5 @@ func (t *Time) UnmarshalJSON(data []byte) (err error) {
func init() {
// Default behaviour
- SetMarshaler(&FormatMashaler{time.RFC3339Nano})
+ SetMarshaler(&FormatMarshaler{time.RFC3339Nano})
}
View
4 jtime_test.go
@@ -24,7 +24,7 @@ func testTime() Time {
func TestFormatMarshaller(t *testing.T) {
tm := testTime()
- fm := &FormatMashaler{"2006"}
+ fm := &FormatMarshaler{"2006"}
data, err := fm.Marshal(tm)
if err != nil {
t.Fatalf("can't marshal: %s", err)
@@ -57,7 +57,7 @@ func checkUnmarshal(data []byte, t *testing.T) {
}
func TestJSON(t *testing.T) {
- SetMarshaler(&FormatMashaler{"2006"})
+ SetMarshaler(&FormatMarshaler{"2006"})
ts := TestStruct{testTime()}
data, err := json.Marshal(ts)

0 comments on commit 93db657

Please sign in to comment.
Something went wrong with that request. Please try again.