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

Error parsing VTIMEZONES from tzurl.org #102

Closed
aluxnimm opened this issue Aug 20, 2016 · 11 comments
Closed

Error parsing VTIMEZONES from tzurl.org #102

aluxnimm opened this issue Aug 20, 2016 · 11 comments

Comments

@aluxnimm
Copy link

When trying to load a timezone with Calendar.LoadFromStream() from tzurl.org, e.g. http://tzurl.org/zoneinfo/Europe/Berlin.ics
I get the following exception

System.FormatException: Die Zeichenfolge wurde nicht als gültiges DateTime erkannt.
   bei System.DateTimeParse.Parse(String s, DateTimeFormatInfo dtfi, DateTimeStyles styles, TimeSpan& offset)
   bei System.DateTimeOffset.Parse(String input)
   bei Ical.Net.Serialization.iCalendar.Serializers.DataTypes.UtcOffsetSerializer.GetOffset(String rawOffset) in C:\dev\ical.net\ical.NET\Serialization\iCalendar\Serializers\DataTypes\UTCOffsetSerializer.cs:Zeile 42.
   bei Ical.Net.DataTypes.UtcOffset..ctor(String value) in C:\dev\ical.net\ical.NET\DataTypes\UTCOffset.cs:Zeile 26.
   bei Ical.Net.Serialization.iCalendar.Serializers.DataTypes.UtcOffsetSerializer.Deserialize(TextReader tr) in C:\dev\ical.net\ical.NET\Serialization\iCalendar\Serializers\DataTypes\UTCOffsetSerializer.cs:Zeile 32.
   bei Ical.Net.Serialization.iCalendar.Serializers.DataMapSerializer.Deserialize(TextReader tr) in C:\dev\ical.net\ical.NET\Serialization\iCalendar\Serializers\DataMapSerializer.cs:Zeile 56.
   bei Ical.Net.Serialization.iCalendar.iCalParser.property(ISerializationContext ctx, ICalendarPropertyListContainer c) in C:\dev\ical.net\ical.NET\Serialization\iCalendar\iCalParser.cs:Zeile 292.
   bei Ical.Net.Serialization.iCalendar.iCalParser.component(ISerializationContext ctx, ISerializerFactory sf, ICalendarComponentFactory cf, ICalendarObject o) in C:\dev\ical.net\ical.NET\Serialization\iCalendar\iCalParser.cs:Zeile 415.
   bei Ical.Net.Serialization.iCalendar.iCalParser.component(ISerializationContext ctx, ISerializerFactory sf, ICalendarComponentFactory cf, ICalendarObject o) in C:\dev\ical.net\ical.NET\Serialization\iCalendar\iCalParser.cs:Zeile 420.
   bei Ical.Net.Serialization.iCalendar.iCalParser.icalbody(ISerializationContext ctx, ICalendar cal) in C:\dev\ical.net\ical.NET\Serialization\iCalendar\iCalParser.cs:Zeile 207.
   bei Ical.Net.Serialization.iCalendar.iCalParser.icalendar(ISerializationContext ctx) in C:\dev\ical.net\ical.NET\Serialization\iCalendar\iCalParser.cs:Zeile 144.
   bei Ical.Net.Serialization.iCalendar.Serializers.CalendarSerializer.Deserialize(TextReader tr) in C:\dev\ical.net\ical.NET\Serialization\iCalendar\Serializers\iCalendarSerializer.cs:Zeile 81.
   bei Ical.Net.Serialization.iCalendar.Serializers.SerializerBase.Deserialize(Stream stream, Encoding encoding) in C:\dev\ical.net\ical.NET\Serialization\iCalendar\Serializers\SerializerBase.cs:Zeile 39.
   bei Ical.Net.Calendar.LoadFromStream(Stream s, Encoding e, ISerializer serializer) in C:\dev\ical.net\ical.NET\Calendar.cs:Zeile 113.
   bei Ical.Net.Calendar.LoadFromStream(TextReader tr, ISerializer serializer) in C:\dev\ical.net\ical.NET\Calendar.cs:Zeile 137.
   bei Ical.Net.Calendar.LoadFromStream(TextReader tr) in C:\dev\ical.net\ical.NET\Calendar.cs:Zeile 118.
@aluxnimm
Copy link
Author

The simplified versions for Outlook, e.g. http://tzurl.org/zoneinfo-outlook/Europe/Berlin.ics are working.

@rianjs
Copy link
Collaborator

rianjs commented Aug 28, 2016

In the future, please post a code snippet that shows how the error occurred instead of just a stack trace.

I assume you're doing something like:

const string berlin = "http://tzurl.org/zoneinfo/Europe/Berlin.ics";
var calendar = Calendar.LoadFromStream(new StringReader(berlin));

This isn't valid. You will have to download the contents of that URL, and then pass the ics contents as a string. The wiki has some examples of how to download a calendar, and then parsing the ics string.

ical.net will never support downloading resources from URLs. You will have to do that from within your application. The reasons for that are at the wiki section I linked above.

@aluxnimm
Copy link
Author

nope downloaded via httpclient or webclient and passed the string. problem is the utc offset with seconds I believe. Can post the code when I have access to the pc later.

@rianjs
Copy link
Collaborator

rianjs commented Aug 28, 2016

Yeah, behind the scenes, it's using the Parse() method from either DateTime or DateTimeOffset, which doesn't support seconds.

Historically, dday.ical's original implementation used regex's to parse the offset, but it didn't work in some normal use cases (like if you prefixed a positive offset with a + which is Microsoft's way of displaying offsets!), so I threw away that part of the code, and replaced it with the built-in parser. There was no need for dday to re-invent the wheel.

@aluxnimm
Copy link
Author

true a lot of redundant code in dday.ical :) still need me to find the code snippet or can you reproduce it?

@rianjs
Copy link
Collaborator

rianjs commented Aug 28, 2016

I can reproduce it, but I'm not going to fix it. It's a .NET library. It seems reasonable to use .NET conventions when they match the behavior of the BCL.

@aluxnimm
Copy link
Author

But since a lot of clients use that timezone definitions (Davdroid for example) the library shouldn't crash when loading a valid ics file or?

@rianjs
Copy link
Collaborator

rianjs commented Aug 28, 2016

My time isn't unlimited. :) I'm not going to re-implement offset parsing to catch some corner case that could reasonably be caught by the client. There are no time zones that have resolutions smaller than 15 minute intervals.

The quick and dirty alternative it to see if there is more than one : at the end of the string, and truncate everything from the second : on if there is. You can do that if you'd like, if you like. I merge other people's PRs all the time.

@aluxnimm
Copy link
Author

Ok will look into it in more detail, relevant code is in UTCOffsetSerializer.cs, right?

@aluxnimm
Copy link
Author

actually according to the rfc 5545

3.3.14. UTC Offset

Value Name: UTC-OFFSET

Purpose: This value type is used to identify properties that contain
an offset from UTC to local time.

Format Definition: This value type is defined by the following
notation:

   utc-offset = time-numzone

   time-numzone = ("+" / "-") time-hour time-minute [time-second]

there are no : in it and therefore nothing to truncate

@rianjs
Copy link
Collaborator

rianjs commented Feb 8, 2017

Fix published in nuget version 2.2.32:
https://www.nuget.org/packages/Ical.Net

@rianjs rianjs closed this as completed Feb 8, 2017
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