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) {
|
|
|
|
args := []string{"--calendar", "--text", text, "--date-format=%F"}
|
|
|
|
args = appendTitle(args, opts)
|
|
|
|
args = appendButtons(args, opts)
|
|
|
|
args = appendWidthHeight(args, opts)
|
|
|
|
args = appendIcon(args, opts)
|
2022-03-28 15:22:39 -04:00
|
|
|
if time.January <= opts.month && opts.month <= time.December {
|
|
|
|
args = append(args, "--month", strconv.Itoa(int(opts.month)))
|
2021-04-11 22:02:21 -04:00
|
|
|
}
|
2022-03-28 15:22:39 -04:00
|
|
|
if 1 <= opts.day && opts.day <= 31 {
|
|
|
|
args = append(args, "--day", strconv.Itoa(opts.day))
|
2021-04-11 22:02:21 -04:00
|
|
|
}
|
2022-03-28 15:22:39 -04:00
|
|
|
if opts.year != nil {
|
|
|
|
args = append(args, "--year", strconv.Itoa(*opts.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-24 12:15:11 -04:00
|
|
|
return time.Parse("2006-01-02", str)
|
2021-04-11 22:02:21 -04:00
|
|
|
}
|