Avoid strftime dependency.

This commit is contained in:
Nuno Cruces 2022-05-02 15:03:48 +01:00
parent cf58f91e75
commit 270b1a0c0e
9 changed files with 26 additions and 23 deletions

View file

@ -116,6 +116,8 @@ func main() {
validateFlags()
opts := loadFlags()
zenutil.Command = true
zenutil.DateUTS35 = func() (string, error) { return strftime.UTS35(zenutil.DateFormat) }
zenutil.DateParse = func(s string) (time.Time, error) { return strftime.Parse(zenutil.DateFormat, s) }
if unixeol {
zenutil.LineBreak = "\n"
}

View file

@ -3,7 +3,6 @@ package zenity
import (
"time"
"github.com/ncruces/go-strftime"
"github.com/ncruces/zenity/internal/zenutil"
)
@ -11,7 +10,7 @@ func calendar(text string, opts options) (t time.Time, err error) {
var date zenutil.Date
date.OK, date.Cancel, date.Extra = getAlertButtons(opts)
date.Format, err = strftime.UTS35(zenutil.DateFormat)
date.Format, err = zenutil.DateUTS35()
if err != nil {
return
}
@ -32,5 +31,5 @@ func calendar(text string, opts options) (t time.Time, err error) {
if err != nil {
return
}
return strftime.Parse(zenutil.DateFormat, str)
return zenutil.DateParse(str)
}

View file

@ -6,7 +6,6 @@ import (
"strconv"
"time"
"github.com/ncruces/go-strftime"
"github.com/ncruces/zenity/internal/zenutil"
)
@ -28,5 +27,5 @@ func calendar(text string, opts options) (time.Time, error) {
if err != nil {
return time.Time{}, err
}
return strftime.Parse(zenutil.DateFormat, str)
return zenutil.DateParse(str)
}

2
go.mod
View file

@ -9,7 +9,7 @@ require (
github.com/randall77/makefat v0.0.0-20210315173500-7ddd0e42c844
go.uber.org/goleak v1.1.12 // test
golang.org/x/image v0.0.0-20220413100746-70e8d0d3baa9
golang.org/x/sys v0.0.0-20220429233432-b5fbb4746d32
golang.org/x/sys v0.0.0-20220502124256-b6088ccd6cba
)
require (

4
go.sum
View file

@ -42,8 +42,8 @@ golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7w
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210330210617-4fbd30eecc44/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210510120138-977fb7262007/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220429233432-b5fbb4746d32 h1:Js08h5hqB5xyWR789+QqueR6sDE8mk+YvpETZ+F6X9Y=
golang.org/x/sys v0.0.0-20220429233432-b5fbb4746d32/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220502124256-b6088ccd6cba h1:AyHWHCBVlIYI5rgEM3o+1PLd0sLPcIAoaUckGQMaWtw=
golang.org/x/sys v0.0.0-20220502124256-b6088ccd6cba/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=

View file

@ -1,6 +1,8 @@
// Package zenutil is internal. DO NOT USE.
package zenutil
import "time"
// These are internal.
const (
ErrCanceled = stringErr("dialog canceled")
@ -8,6 +10,16 @@ const (
ErrUnsupported = stringErr("unsupported option")
)
// These are internal.
var (
Command bool
Timeout int
DateFormat = "%Y-%m-%d"
DateUTS35 = func() (string, error) { return "yyyy-MM-dd", nil }
DateParse = func(s string) (time.Time, error) { return time.Parse("2006-01-02", s) }
)
type stringErr string
func (e stringErr) Error() string { return string(e) }

View file

@ -2,9 +2,6 @@ package zenutil
// These are internal.
var (
Command bool
Timeout int
Separator = "\x00"
LineBreak = "\n"
DateFormat = "%F"
)

View file

@ -4,9 +4,6 @@ package zenutil
// These are internal.
var (
Command bool
Timeout int
Separator = "\x1e"
LineBreak = "\n"
DateFormat = "%F"
)

View file

@ -2,9 +2,6 @@ package zenutil
// These are internal.
var (
Command bool
Timeout int
Separator string
LineBreak = "\r\n"
DateFormat = "%F"
)