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

Add support for datetime properties #519

Closed
wants to merge 14 commits into from

Conversation

nirinchev
Copy link
Member

@nirinchev nirinchev commented Apr 28, 2022

This depends on #495 because I was halfway through testing dynamic access when I realized dates are not supported.

Fixes #520

UPDATE: Superseded by #569. Kept as a draft cause it has nullable datetime support as well

@cla-bot cla-bot bot added the cla: yes label Apr 28, 2022
@nirinchev nirinchev marked this pull request as ready for review April 28, 2022 23:09
@nirinchev nirinchev self-assigned this Apr 28, 2022
Copy link
Contributor

@nielsenko nielsenko left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks okay, but we should track down why the tests fails on some platforms

realm_value.ref.values.timestamp.seconds = microseconds ~/ 1000000;
realm_value.ref.values.timestamp.nanoseconds = (microseconds % 1000000) * 1000;
realm_value.ref.type = realm_value_type.RLM_TYPE_TIMESTAMP;
break;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So no timezone :-/ .. Was about to suggest using https://pub.dev/packages/timezone, but since core doesn't support there is little point.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, that's something we've never supported and it comes up occasionally as an annoyance.

throw Exception("Not implemented");
final seconds = ref.values.timestamp.seconds;
final nanoseconds = ref.values.timestamp.nanoseconds;
return DateTime.fromMicrosecondsSinceEpoch(seconds * 1000000 + nanoseconds ~/ 1000).toUtc();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks kosher, but I notice a lot of failing tests.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like a bug in date serialization in Core (or a bug in our code). Investigating.

});

final json = obj.toJson();
expect(json, contains('"dateProp":"${DateTime.utc(0).toRealmString()}"'));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
expect(json, contains('"dateProp":"${DateTime.utc(0).toRealmString()}"'));
expect(json['dateprop'], DateTime.utc(0).toRealmString()));

@@ -265,3 +278,14 @@ Future<void> baasTest(
extension RealmObjectTest on RealmObject {
String toJson() => realmCore.objectToString(this);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is surprising toJson by convention should return dynamic (runtime-type of objects will be Map<String, dynamic>). I would suggest running jsonDecode on the decoded String to follow convention.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm slightly worried about taking such approach because the json Core produces might not be the most valid json in the world - particularly, they'll serialize integers as strings, dates as non-roundtrippable strings, etc.

String toRealmString() {
final utc = toUtc();
// This is kind of silly, but Core serializes negative dates as -003-01-01 12:34:56
final utcYear = utc.year < 0 ? '-${utc.year.abs().toString().padLeft(3, '0')}' : utc.year.toString().padLeft(4, '0');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Weird, and why pad 3? Just curious

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have no idea - I believe it was likely overlooked by the core team.

@nirinchev
Copy link
Member Author

I filed realm/realm-core#5451 to track fixes for roundtripping zero/negative dates. I tried it on Windows and the values look correct in Studio, so I'm 99% confident it's a serialization bug in to_json and not an actual logic issue on our end.

@nielsenko
Copy link
Contributor

nielsenko commented May 10, 2022

@blagoev I think it would be nice to land this PR before release.

@nirinchev
Copy link
Member Author

This PR works around the issues with to_json on Windows, so the tests are not a blocker to merging it. It will need to be cherry picked on top of master though.

@blagoev
Copy link
Contributor

blagoev commented May 10, 2022

I was planning on doing that on top of master, but it can wait a bit to one of the next sprints

@blagoev blagoev mentioned this pull request May 15, 2022
@blagoev blagoev marked this pull request as draft May 15, 2022 17:21
@nirinchev
Copy link
Member Author

Added in #569.

@nirinchev nirinchev closed this May 23, 2022
@blagoev blagoev reopened this May 23, 2022
@blagoev
Copy link
Contributor

blagoev commented May 23, 2022

reopening since this has nullable datetime support.

@nirinchev
Copy link
Member Author

nirinchev commented May 23, 2022

@blagoev we already merged nullable datetime support (there was nothing special about this). Did you mean to reopen #462? Even so, we don't really need those PRs open - they'll still be accessible via the Github UI and we can't cherry pick them anyway since they've diverged too much from master. We'll probably need to update #459 to pull in oid and uuid support.

@nirinchev nirinchev closed this Aug 17, 2022
@nirinchev nirinchev deleted the ni/add-date-support branch August 18, 2022 23:26
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 15, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants