zenity/date_darwin.go

42 lines
758 B
Go
Raw Permalink Normal View History

2022-03-24 12:15:11 -04:00
package zenity
import (
"time"
"github.com/ncruces/zenity/internal/zenutil"
)
2022-03-30 10:36:50 -04:00
func calendar(text string, opts options) (t time.Time, err error) {
2022-06-01 19:00:08 -04:00
var data zenutil.Date
2022-03-24 12:15:11 -04:00
2022-06-01 19:00:08 -04:00
data.OK, data.Cancel, data.Extra = getAlertButtons(opts)
data.Format, err = zenutil.DateUTS35()
2022-03-30 10:36:50 -04:00
if err != nil {
return
}
2022-03-28 22:05:46 -04:00
if opts.time != nil {
2022-03-30 10:36:50 -04:00
unix := opts.time.Unix()
2022-06-01 19:00:08 -04:00
data.Date = &unix
2022-03-28 22:05:46 -04:00
}
2022-03-24 12:15:11 -04:00
if opts.title != nil {
2022-06-01 19:00:08 -04:00
data.Text = *opts.title
data.Info = text
2022-03-24 12:15:11 -04:00
} else {
2022-06-01 19:00:08 -04:00
data.Text = text
}
2022-06-08 18:52:44 -04:00
if opts.attach != nil {
data.Application = opts.attach
}
2022-06-01 19:00:08 -04:00
if i, ok := opts.windowIcon.(string); ok {
data.WindowIcon = i
2022-03-24 12:15:11 -04:00
}
2022-06-01 19:00:08 -04:00
out, err := zenutil.Run(opts.ctx, "date", data)
2022-03-24 12:15:11 -04:00
str, err := strResult(opts, out, err)
if err != nil {
2022-03-30 10:36:50 -04:00
return
2022-03-24 12:15:11 -04:00
}
2022-05-02 10:03:48 -04:00
return zenutil.DateParse(str)
2022-03-24 12:15:11 -04:00
}