xiam / to

Aggressive data type conversions for Go
MIT License
92 stars 25 forks source link

Optimization strToTimeFormats #3

Closed achun closed 10 years ago

achun commented 10 years ago

stdFracSecond0 can be omitted for time.Parse. such as this:

var strToTimeFormats = []string{
    "2006-01-02", // follow use time.Local
    "2006-01-02 15:04",
    "2006-01-02 15:04:05", // Compatible "2006-01-02 15:04:05.000000000" for time.Parse
    "2006-01-02T15:04",
    "2006-01-02T15:04:05", // "2006-01-02T15:04:05.000000000",
    "01/02/2006",
    "01/02/2006 15:04",
    "01/02/2006 15:04:05", // "01/02/2006 15:04:05.000000000",
    "01/02/06",
    "01/02/06 15:04",
    "01/02/06 15:04:05", // "01/02/06 15:04:05.000000000",
    "_2/Jan/2006 15:04:05",
    "Jan _2, 2006",
    time.Stamp, // time.StampMilli, time.StampMicro, time.StampNano,
    time.ANSIC,
    time.Kitchen,
    time.UnixDate, // follow with timezone
    time.RubyDate,
    time.RFC822,
    time.RFC822Z,
    time.RFC850,
    time.RFC1123,
    time.RFC1123Z,
    time.RFC3339, // time.RFC3339Nano,
    "Mon Jan _2 15:04:05 -0700 MST 2006", // "Mon Jan _2 15:04:05.000000000 -0700 MST 2006",
    "2006-01-02 15:04:05-0700", // append some layout
    "2006-01-02 15:04:05 -0700",
    "2006-01-02 15:04:05Z07:00",
    "2006-01-02 15:04:05 Z07:00",
}
xiam commented 10 years ago

Looks fine but I'll have to run some tests on this. Would you like to create a pull request?

xiam commented 10 years ago

I just merged this into the experimental branch. Thanks!