Skip to content

Commit

Permalink
add timeformat cli arg parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
alehechka committed Jun 28, 2022
1 parent a63b8ee commit f95f9fa
Showing 1 changed file with 47 additions and 0 deletions.
47 changes: 47 additions & 0 deletions gen/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"log"
"path/filepath"
"strings"
"time"

"github.com/alehechka/json2go/jenshared"
)
Expand All @@ -17,6 +18,7 @@ type Config struct {
RootName string
PackageName string
OutputFileName string
TimeFormat string
}

func (c *Config) toJensharedConfig() *jenshared.Config {
Expand All @@ -34,6 +36,7 @@ func (c *Config) toJensharedConfig() *jenshared.Config {
PackageName: c.PackageName,
OutputFileName: c.OutputFileName,
OutputDirectory: dir,
TimeFormat: c.getTimeFormat(),
Debugger: c.Debugger,
}
}
Expand All @@ -60,3 +63,47 @@ func (c *Config) prepareOutputFileName() {
c.OutputFileName += ".go"
}
}

func (c *Config) getTimeFormat() string {

if len(c.TimeFormat) == 0 {
return time.RFC3339
}

switch c.TimeFormat {
case "Layout":
return time.Layout
case "ANSIC":
return time.ANSIC
case "UnixDate":
return time.UnixDate
case "RubyDate":
return time.RubyDate
case "RFC822":
return time.RFC822
case "RFC822Z":
return time.RFC822Z
case "RFC850":
return time.RFC850
case "RFC1123":
return time.RFC1123
case "RFC1123Z":
return time.RFC1123Z
case "RFC3339":
return time.RFC3339
case "RFC3339Nano":
return time.RFC3339Nano
case "Kitchen":
return time.Kitchen
case "Stamp":
return time.Stamp
case "StampMilli":
return time.StampMilli
case "StampMicro":
return time.StampMicro
case "StampNano":
return time.StampNano
default:
return c.TimeFormat
}
}

0 comments on commit f95f9fa

Please sign in to comment.