zenity/date_unix.go

32 lines
815 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"
2024-07-10 00:06:01 -04:00
"git.bigun.dev/evan/zenity/internal/zenutil"
2021-04-11 22:02:21 -04:00
)
func calendar(text string, opts options) (time.Time, error) {
2022-12-20 07:23:15 -05:00
args := []string{"--calendar", "--text", quoteMarkup(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
}