Skip to content

Failed to import Apple ics #32

Open
@threez

Description

@threez

Thanks for your great library.

I found an issue when loading apple calendar exports. the dtstart/end isn't parsed because of a tailing line feed.

Adding dt = fmt.Sprintf("%sZ", strings.TrimRight(dt, "\r\n")) to the parsing func doe fix the problem.

// parses the event start time
func (p *Parser) parseTimeField(fieldName string, eventData string) (time.Time, string) {
	reWholeDay, _ := regexp.Compile(fmt.Sprintf(`%s;VALUE=DATE:.*?\n`, fieldName))
	re, _ := regexp.Compile(fmt.Sprintf(`%s(;TZID=(.*?))?(;VALUE=DATE-TIME)?:(.*?)\n`, fieldName))
	resultWholeDay := reWholeDay.FindString(eventData)
	var t time.Time
	var tzID string

	if resultWholeDay != "" {
		// whole day event
		modified := trimField(resultWholeDay, fmt.Sprintf("%s;VALUE=DATE:", fieldName))
		t, _ = time.Parse(IcsFormatWholeDay, modified)
	} else {
		// event that has start hour and minute
		result := re.FindStringSubmatch(eventData)
		if result == nil || len(result) < 4 {
			return t, tzID
		}
		tzID = result[2]
		dt := result[4]
		if !strings.Contains(dt, "Z") {
			dt = fmt.Sprintf("%sZ", strings.TrimRight(dt, "\r\n"))
		}
		t, _ = time.Parse(IcsFormat, dt)
	}

	return t, tzID
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions