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 datetime support #569

Merged
merged 5 commits into from
May 19, 2022
Merged

add datetime support #569

merged 5 commits into from
May 19, 2022

Conversation

blagoev
Copy link
Contributor

@blagoev blagoev commented May 15, 2022

supersedes #519

@blagoev blagoev self-assigned this May 15, 2022
@nielsenko
Copy link
Contributor

Why not just continue with #519?

@blagoev
Copy link
Contributor Author

blagoev commented May 16, 2022

@nielsenko its not based on master

@nirinchev
Copy link
Member

We could have just rebased on #519 on master but I guess it doesn't matter that much.

throw Exception("Not implemented");
final seconds = ref.values.timestamp.seconds;
final nanoseconds = ref.values.timestamp.nanoseconds;
return DateTime.fromMicrosecondsSinceEpoch(seconds * _microsecondsPerSecond + nanoseconds ~/ _nanosecondsPerMicrosecond, isUtc: true);
Copy link
Contributor

Choose a reason for hiding this comment

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

I think there should be .toLocal() at the end. When we pass the value to core we convert it toUtc. Here we are receiving utc from core and we have to convert it back to local before to return.

Copy link
Member

Choose a reason for hiding this comment

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

I don't think we should be converting dates to local because Core doesn't store timezone info. It'll be misleading for developers if we returned local date here. Also, there's no guarantee that the original date the developer passed was in local time - it could be UTC or some completely different timezone.

Copy link
Contributor

@desistefanova desistefanova May 16, 2022

Choose a reason for hiding this comment

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

It is not needed the core to keep time zone. if you pass a local date from one device, then when you convert toUtc the method will use the current time zone of the device. And when they receive it on another device it will be converted to the device local time.
In case we want the users to manage their dates then we shouldn't convert their dates to UTC in _intoRealmValue method without they to know. Probably have to throw if (value as DateTime).isUtc==false before to change their date.

Copy link
Member

Choose a reason for hiding this comment

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

I think it's a little annoying if we force people to always convert dates to utc although I agree it's more correct as we explicitly tell them that Realm will lose the timezone information.

Copy link
Contributor

Choose a reason for hiding this comment

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

When they create a DateTime in Dart it is local by default unless they have used DateTime.utc constructor. It will be good to have at least some warning or api doc.

Copy link
Member

Choose a reason for hiding this comment

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

We should definitely document it in the main docs site. We could also generate an API doc on the user model property, though not sure how intrusive that will be.

@blagoev
Copy link
Contributor Author

blagoev commented May 16, 2022

@desistefanova @nirinchev Could you have your say on this so we could merge it. I see some comments but I am unsure if I need to take some action on the code. If there are changes needed please write a clear comment on that ?

@nirinchev
Copy link
Member

I wrote the code so I'm not sure it's me who should comment on whether to merge it or not.

@desistefanova
Copy link
Contributor

@desistefanova @nirinchev Could you have your say on this so we could merge it. I see some comments but I am unsure if I need to take some action on the code. If there are changes needed please write a clear comment on that ?

@blagoev could we discuss it? I will add this to the list.

@blagoev
Copy link
Contributor Author

blagoev commented May 16, 2022

sure let's discuss this.

Copy link
Contributor

@desistefanova desistefanova left a comment

Choose a reason for hiding this comment

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

Just a reminder for documenting DateTime UTC convertion.

@nielsenko
Copy link
Contributor

Needs a rebase though..

# Conflicts:
#	CHANGELOG.md
#	test/test.dart
#	test/test.g.dart
@blagoev blagoev merged commit f1a2391 into master May 19, 2022
@blagoev blagoev deleted the blagoev/datetime-support branch May 19, 2022 06:47
@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.

None yet

4 participants