mirror of
https://github.com/therootcompany/golib.git
synced 2025-11-20 05:54:29 +00:00
wip(calendar): rework field access
This commit is contained in:
parent
b811f0863d
commit
64fb761615
@ -24,9 +24,61 @@ type Rule struct {
|
|||||||
// Reminders are ignored for now – you can add them later.
|
// Reminders are ignored for now – you can add them later.
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type DayType int
|
||||||
|
|
||||||
|
const (
|
||||||
|
FEDERAL DayType = iota
|
||||||
|
BANK
|
||||||
|
BUSINESS
|
||||||
|
)
|
||||||
|
|
||||||
|
// format is either "<days> <time>" or <days> or <time> or <duration>
|
||||||
|
type Reminder struct {
|
||||||
|
//Parent string
|
||||||
|
Days int
|
||||||
|
DayType DayType
|
||||||
|
Duration time.Duration
|
||||||
|
Time Time
|
||||||
|
}
|
||||||
|
|
||||||
|
type Time struct {
|
||||||
|
Hour int
|
||||||
|
Minute int
|
||||||
|
Second int
|
||||||
|
}
|
||||||
|
|
||||||
|
type Fields struct {
|
||||||
|
NAME int
|
||||||
|
NTH int
|
||||||
|
WKDAY int
|
||||||
|
DATE int
|
||||||
|
TIME int
|
||||||
|
TZ int
|
||||||
|
LABEL int
|
||||||
|
DETAIL int
|
||||||
|
R1 int
|
||||||
|
R2 int
|
||||||
|
R3 int
|
||||||
|
}
|
||||||
|
|
||||||
|
var FIELDS = Fields{
|
||||||
|
NAME: 0,
|
||||||
|
NTH: 1,
|
||||||
|
WKDAY: 2,
|
||||||
|
DATE: 3,
|
||||||
|
TIME: 4,
|
||||||
|
TZ: 5,
|
||||||
|
LABEL: 6,
|
||||||
|
DETAIL: 7,
|
||||||
|
R1: 8,
|
||||||
|
R2: 9,
|
||||||
|
R3: 10,
|
||||||
|
}
|
||||||
|
|
||||||
// ---------- 2. CSV → []Rule ----------
|
// ---------- 2. CSV → []Rule ----------
|
||||||
func LoadRules(rd *csv.Reader) ([]Rule, error) {
|
func LoadRules(rd *csv.Reader) ([]Rule, error) {
|
||||||
// first line is the header
|
// first line is the header
|
||||||
|
// TODO create instance and map header names to column ints
|
||||||
if _, err := rd.Read(); err != nil {
|
if _, err := rd.Read(); err != nil {
|
||||||
return nil, fmt.Errorf("read header: %w", err)
|
return nil, fmt.Errorf("read header: %w", err)
|
||||||
}
|
}
|
||||||
@ -55,12 +107,12 @@ func LoadRules(rd *csv.Reader) ([]Rule, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func parseRule(rec []string) (Rule, error) {
|
func parseRule(rec []string) (Rule, error) {
|
||||||
event := rec[0]
|
event := rec[FIELDS.NAME]
|
||||||
nthStr := rec[1]
|
nthStr := rec[FIELDS.NTH]
|
||||||
dayStr := rec[2]
|
dayStr := rec[FIELDS.WKDAY]
|
||||||
dateStr := rec[3]
|
dateStr := rec[FIELDS.DATE]
|
||||||
timeStr := rec[4]
|
timeStr := rec[FIELDS.TIME]
|
||||||
tz := rec[5]
|
tz := rec[FIELDS.TZ]
|
||||||
|
|
||||||
var r Rule
|
var r Rule
|
||||||
r.Event = strings.TrimSpace(event)
|
r.Event = strings.TrimSpace(event)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user