zenity/date_unix.go

32 lines
802 B
Go
Raw Permalink 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}
2022-06-02 07:24:24 -04:00
args = appendGeneral(args, opts)
2021-04-11 22:02:21 -04:00
args = appendButtons(args, opts)
args = appendWidthHeight(args, opts)
2022-05-18 09:48:09 -04:00
args = appendWindowIcon(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-05-02 10:03:48 -04:00
return zenutil.DateParse(str)
2021-04-11 22:02:21 -04:00
}