Commits

Miki Tebeka committed d4c79fe

readme

Comments (0)

Files changed (3)

+syntax: glob
+
+README.html
+# Flexible JSON time Handling
+
+`time.Time` marshal to JSON only in one format (RFC3339Nano).
+`jtime.Time` embeds `time.Time` and lets the user set the format via
+Marshallers.
+
+# Example
+
+    package main
+
+    import (
+            "encoding/json"
+            "fmt"
+            "log"
+
+            "bitbucket.org/tebeka/jtime"
+    )
+
+    type T struct {
+            Created jtime.Time `json:"created"`
+    }
+
+    func main() {
+            jtime.SetMarshaler(&jtime.UnixMarshaler{})
+            data := []byte(`{"created":1382135725}`) // Oct 18, 2013
+            t := T{}
+            if err := json.Unmarshal(data, &t); err != nil {
+                    log.Fatalf("error umarshaling: %s\n", err)
+            }
+            fmt.Println(t.Created) // 2013-10-18 15:35:25 -0700 PDT
+    }
 		if err := json.Unmarshal(data, &t); err != nil {
 			log.Fatalf("error umarshaling: %s\n", err)
 		}
-		fmt.Println(t.Created)
+		fmt.Println(t.Created) // 2013-10-18 15:35:25 -0700 PDT
 	}
 
 Caution: Changing marshaller in mid-flight is dangerous :)