Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Failed to import Apple ics #32

Open
threez opened this issue Aug 3, 2020 · 2 comments
Open

Failed to import Apple ics #32

threez opened this issue Aug 3, 2020 · 2 comments

Comments

@threez
Copy link

threez commented Aug 3, 2020

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
}
@PuloV
Copy link
Owner

PuloV commented Aug 6, 2020

Thanks for the feedback @threez!
Can you open a PR with the change and tests?

threez added a commit to threez/ics-golang that referenced this issue Aug 10, 2020
fix to be able to load apple calendars
@threez
Copy link
Author

threez commented Aug 10, 2020

Hi @PuloV I added the code and a test.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants