Documentation
¶
Index ¶
- Variables
- func WithEndTime(end time.Time) parseOpts
- func WithHTTP11Client(forceHTTP11 bool) parseOpts
- func WithLocationAllDayEvent(location *time.Location) parseOpts
- func WithLocationMap(name string, location *time.Location) parseOpts
- func WithStartTime(start time.Time) parseOpts
- type Conc
- type Parser
- type Source
- type SourceType
Examples ¶
Constants ¶
This section is empty.
Variables ¶
Functions ¶
func WithEndTime ¶
WithEndTime sets the end time for the parsing period.
func WithHTTP11Client ¶
func WithHTTP11Client(forceHTTP11 bool) parseOpts
WithHTTP11Client sets the HTTP client to use HTTP/1.1.
func WithLocationAllDayEvent ¶ added in v0.1.2
WithLocationAllDayEvent sets the time location for all-day events.
func WithLocationMap ¶ added in v0.1.2
WithLocationMap sets the time location for the parser.
func WithStartTime ¶
WithStartTime sets the start time for the parsing period.
Types ¶
type Conc ¶
type Conc struct {
// contains filtered or unexported fields
}
Conc parses multiple calendar sources concurrently.
func NewConcurrent ¶
NewConcurrent creates a concurrent parser using parser for each source.
func (*Conc) Close ¶
Close cancels ongoing parsing, waits for workers, and returns accumulated errors.
func (*Conc) EventSlice ¶
EventSlice returns a slice of gocal.Event from the Conc object. If the Conc object is nil, it returns nil.
type Parser ¶
type Parser struct {
// contains filtered or unexported fields
}
Parser is a struct that holds the context, error list, HTTP client settings, and time period for parsing calendar events.
func NewParser ¶
func NewParser(opts ...parseOpts) *Parser
NewParser creates a new Parser instance with the given context and options.
func (*Parser) ParseOne ¶
ParseOne parses the calendar events from the given source string within the specified period. It returns the parsed events and any error encountered.
Example ¶
package main
import (
"context"
"fmt"
"sort"
"time"
"github.com/goark/concal"
)
func main() {
p := concal.NewParser(
concal.WithStartTime(time.Date(2026, time.November, 1, 0, 0, 0, 0, time.UTC)),
concal.WithEndTime(time.Date(2026, time.November, 30, 23, 59, 59, 999999999, time.UTC)),
)
evts, err := p.ParseOne(context.Background(), "testdata/holiday.ics")
if err != nil {
fmt.Printf("%+v\n", err)
return
}
sort.SliceStable(evts, func(i, j int) bool {
return evts[i].Start.Before(*evts[j].Start)
})
for _, e := range evts {
fmt.Printf("%s on %s\n", e.Summary, e.Start.Format("2006-01-02"))
}
}
Output: 文化の日 on 2026-11-03 勤労感謝の日 on 2026-11-23
type Source ¶
type Source interface {
Type() SourceType
Reader() io.Reader
Close() error
}
Source represents a generic source for calendar data, which can be a file or a URL.
type SourceType ¶
type SourceType int
SourceType represents the type of the source (file, URL, or unknown).
const ( // Source types for the parser TypeUnknown SourceType = iota // Unknown source type TypeFile // File source type TypeURL // URL source type )
