zenity/date_unix.go

32 lines
825 B
Go
Raw Normal View History

2022-03-24 12:15:11 -04:00
//go:build !windows && !darwin
2021-04-11 22:02:21 -04:00
package zenity
import (
"strconv"
"time"
"github.com/ncruces/zenity/internal/zenutil"
)
func calendar(text string, opts options) (time.Time, error) {
2022-03-29 07:53:20 -04:00
args := []string{"--calendar", "--text", text, "--date-format", zenutil.DateFormat}
2021-04-11 22:02:21 -04:00
args = appendTitle(args, opts)
args = appendButtons(args, opts)
args = appendWidthHeight(args, opts)
args = appendIcon(args, opts)
2022-03-28 22:05:46 -04:00
if opts.time != nil {
year, month, day := opts.time.Date()
args = append(args, "--month", strconv.Itoa(int(month)))
args = append(args, "--day", strconv.Itoa(day))
args = append(args, "--year", strconv.Itoa(year))
2021-04-11 22:02:21 -04:00
}
out, err := zenutil.Run(opts.ctx, args)
2022-03-24 12:15:11 -04:00
str, err := strResult(opts, out, err)
if err != nil {
return time.Time{}, err
2021-04-11 22:02:21 -04:00
}
2022-03-29 07:53:20 -04:00
return time.Parse(zenutil.Strftime(zenutil.DateFormat), str)
2021-04-11 22:02:21 -04:00
}