diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..282358f --- /dev/null +++ b/Makefile @@ -0,0 +1,5 @@ +build: + GOOS=darwin GOARCH=amd64 go build -o bin/awpark.amd64 main.go + GOOS=darwin GOARCH=arm64 go build -o bin/awpark.arm64 main.go + mkdir -p bin + lipo -create -output ./bin/awpark bin/awpark.amd64 bin/awpark.arm64 \ No newline at end of file diff --git a/cmd/timestamp.go b/cmd/timestamp.go index 848c4ab..833b0f2 100644 --- a/cmd/timestamp.go +++ b/cmd/timestamp.go @@ -12,6 +12,7 @@ import ( func init() { Register(×tampGetter{}) Register(×tampFormatter{}) + Register(×tampParser{}) } type timestampGetter struct{ RunModeRun } @@ -71,3 +72,76 @@ func (t *timestampFormatter) Action(args []string) { wf.NewItem("Formatted: " + formatted).Valid(true).Copytext(formatted).Arg(formatted).Icon(&aw.Icon{Value: "clock.png"}).Subtitle("Press [Enter], copy to the clipboard.") } } + +type timestampParser struct{ RunModeRun } + +func (t *timestampParser) Use() string { + return "timestamp-parser" +} + +func (t *timestampParser) ActionItem() *aw.Item { + return wf.NewItem("Timestamp Parser").UID("B00000004-3").Valid(true).Icon(&aw.Icon{Value: "clock.png"}) +} + +func (t *timestampParser) Action(args []string) { + formatTemplate := []string{ + "2006-01-02T15:04:05Z07:00", + "2006-01-02T15:04:05.999999999Z07:00", + "2006-01-02T15:04:05.999999999", + "2006-01-02T15:04:05", + "2006-01-02 15:04:05Z07:00", + "2006-01-02 15:04:05.999999999Z07:00", + "2006-01-02 15:04:05.999999999", + "2006-01-02 15:04:05 -0700 MST", + "2006-01-02 15:04:05 -0700", + "2006-01-02 15:04:05 -07:00", + "2006-01-02 15:04:05.999999999 -0700 MST", + "2006-01-02 15:04:05.999999999 -0700", + "2006-01-02 15:04:05.999999999 -07:00", + "2006-01-02 15:04:05", + "2006-01-02", + "01/02 03:04:05PM '06 -0700", + "Mon Jan _2 15:04:05 2006", + "Mon Jan _2 15:04:05 MST 2006", + "Mon Jan 02 15:04:05 -0700 2006", + "02 Jan 06 15:04 MST", + "02 Jan 06 15:04 -0700", + "Monday, 02-Jan-06 15:04:05 MST", + "Mon, 02 Jan 2006 15:04:05 MST", + "Mon, 02 Jan 2006 15:04:05 -0700", + "3:04PM", + "Jan _2 15:04:05", + "Jan _2 15:04:05.000", + "Jan _2 15:04:05.000000", + "Jan _2 15:04:05.000000000", + } + tips := func() { + wf.NewItem("Reference the following date format.").Valid(false).Icon(&aw.Icon{Value: "clock.png"}) + for _, t := range formatTemplate { + wf.NewItem("eg. " + t).Valid(false).Icon(&aw.Icon{Value: "clock.png"}) + } + } + if len(args) > 0 && len(args[0]) > 0 { + timestr := args[0] + var ( + inputTime time.Time + err error + ) + for _, format := range formatTemplate { + inputTime, err = time.ParseInLocation(format, timestr, time.Local) + if err == nil { + break + } + } + if err != nil { + tips() + return + } + seconds := fmt.Sprintf("%d", inputTime.Unix()) + milliseconds := fmt.Sprintf("%d", inputTime.UnixNano()/int64(time.Millisecond)) + wf.NewItem("Seconds: " + seconds).Valid(true).Copytext(seconds).Arg(seconds).Icon(&aw.Icon{Value: "clock.png"}) + wf.NewItem("Milliseconds: " + milliseconds).Valid(true).Copytext(milliseconds).Arg(milliseconds).Icon(&aw.Icon{Value: "clock.png"}).Subtitle("Press [Enter], copy to the clipboard.") + } else { + tips() + } +} diff --git a/main.go b/main.go index efaed8f..005a0e5 100644 --- a/main.go +++ b/main.go @@ -1,9 +1,9 @@ package main import ( -"github.com/sipt/awpark/cmd" + "github.com/sipt/awpark/cmd" ) func main() { cmd.Execute() -} \ No newline at end of file +}