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

Date is not correctly parsed #27

Closed
dg76 opened this issue Jun 4, 2021 · 5 comments · Fixed by #28
Closed

Date is not correctly parsed #27

dg76 opened this issue Jun 4, 2021 · 5 comments · Fixed by #28

Comments

@dg76
Copy link

dg76 commented Jun 4, 2021

Hi!

DTSTART;TZID=Europe/Berlin:20210607T090000

is being parsed as

DateTime:<2021-10-31 01:00:00.000Z>

As you can see the date and time is incorrectly parsed. :-( I think using "DateTime.parse(text)" is not enough.

@TesteurManiak TesteurManiak added the bug Something isn't working label Jun 4, 2021
@TesteurManiak
Copy link
Owner

Hi, I'm going to look into it to see if I can parse it better, last resort solution would be to save it as a String instead of trying to parse it.

@TesteurManiak TesteurManiak removed the bug Something isn't working label Jun 4, 2021
@TesteurManiak
Copy link
Owner

TesteurManiak commented Jun 4, 2021

So it is not really a bug, the issue is that I do not supports parameters when parsing, and the DateTime object does not support the timezone, parsing with the timezone might be possible by using the package https://pub.dev/packages/timezone but it implies to rewrite the implementation, for now I might create a custom object to save the timezone and the non-parsed datetime as a String.
Would that work for you ?

@dg76
Copy link
Author

dg76 commented Jun 4, 2021

Actually I just wanted to tell you about the problem so that you could maybe fix that in the future if you like. I just needed it for a test case to verify an ICS file. But I have found another solution for me now: I have already parsed ICS files in Java and Objective C so I could just reuse some of the code and build a simple ICS parser in Flutter myself now that is sufficient for my test case. It is very simple and supports only strings but for my tests it is sufficient.

So for me you don't need to change it, I just wanted to mention it so that you know that this problem exists. :-) Thank you very much for your very quick replies! 👍

@dg76 dg76 closed this as completed Jun 4, 2021
@TesteurManiak TesteurManiak mentioned this issue Jun 4, 2021
TesteurManiak added a commit that referenced this issue Jun 4, 2021
@TesteurManiak
Copy link
Owner

From #28 (comment)

As DateTime doesn't support timezones I cannot provide a full parsing for ics datetime object. Still I've created an IcsDateTime object to keep all the data so you can easily finish the parsing by yourself using the timezone package:

Timezone example

import 'package:timezone/standalone.dart' as tz;

final icsDt = IcsDateTime(/* ... */);
final date = tz.TZDateTime.parse(tz.getLocation(icsDt.tzid), icsDt.dt);

IcsDateTime implementation

class IcsDateTime {
  final String? tzid;
  final String dt;

  IcsDateTime({this.tzid, required this.dt});

  DateTime? toDateTime() => DateTime.tryParse(dt);

  Map<String, dynamic> toJson() {
    final json = <String, dynamic>{'dt': dt};
    if (tzid != null) json['tzid'] = tzid;
    return json;
  }
}

@dg76
Copy link
Author

dg76 commented Jun 4, 2021

Thank you, that seems to be a good solution! :-)

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

Successfully merging a pull request may close this issue.

2 participants