#community-help

Discussing Firebase Extension and Timestamp Implementation.

TLDR Loic enquired about timestamp inf Firebase implementation. Jason confirmed it's supported and shared the extension version, its functionality, and where the conversion happens. Loic planned to test this.

Powered by Struct AI

2

27
18mo
Solved
Join the chat
May 12, 2022 (18 months ago)
Loic
Photo of md5-3a88a602e4aba6a18b4a6c6985fcf08c
Loic
12:27 AM
hi Jason, are you planning to implement the timestamp like firebase in the field types?
Jason
Photo of md5-8813087cccc512313602b6d9f9ece19f
Jason
12:28 AM
Loic A contributor recently added support for this, along with nested fields in the extension
12:28
Jason
12:28 AM
So the Firebase extension will automatically convert Firebase data types to Typesense data types
12:28
Jason
12:28 AM
in this case, dates will be converted to unix timestamps automatically
Loic
Photo of md5-3a88a602e4aba6a18b4a6c6985fcf08c
Loic
12:29 AM
Is it live already on the current Firebase extension and schema v0.22.2?
Jason
Photo of md5-8813087cccc512313602b6d9f9ece19f
Jason
12:29 AM
Yup, you want to use v0.3.0 of the extension
Loic
Photo of md5-3a88a602e4aba6a18b4a6c6985fcf08c
Loic
12:29 AM
So in the schema you put int64 as field type to receive the timestamp data?
Jason
Photo of md5-8813087cccc512313602b6d9f9ece19f
Jason
12:29 AM
Correct
Loic
Photo of md5-3a88a602e4aba6a18b4a6c6985fcf08c
Loic
12:30 AM
Perfect thank you. Do you know if it converts the timestamp in DateTime.now().millisecondsSinceEpoch ?
Loic
Photo of md5-3a88a602e4aba6a18b4a6c6985fcf08c
Loic
12:31 AM
Yes, Math.floor(value.toDate().getTime() / 1000);
12:32
Loic
12:32 AM
I don’t know if it millisecondsSinceEpoch or millisecond
12:32
Loic
12:32 AM
I will try it out
12:32
Loic
12:32 AM
Thank you Jason
Jason
Photo of md5-8813087cccc512313602b6d9f9ece19f
Jason
12:32 AM
:thumbsup:
Loic
Photo of md5-3a88a602e4aba6a18b4a6c6985fcf08c
Loic
12:33 AM
congrats on the Google IO featured 🔥
Jason
Photo of md5-8813087cccc512313602b6d9f9ece19f
Jason
12:33 AM
Thank you! 😄
Loic
Photo of md5-3a88a602e4aba6a18b4a6c6985fcf08c
Loic
08:18 PM
Hi Jason ,
I was able to send Timestamp from Firebase -> to Typesense int64
When I do the other way, I search and receive the int64 in my app and it is the same value as in Typesense ✔️

However, this Timestamp (for example: 1652386231) is supposed to be in millisecondsSinceEpoch but for some reason if I want to compare a date I have to use the received Timestamp as millisecondsSinceEpoch but the other date as seconds

For example if I get the lastConnection from a Typesense search and I then want to compare I have to do:
lastConnection.millisecondsSinceEpoch > Timestamp.fromDate(DateTime.now().subtract(const Duration(seconds: 70))).seconds
08:20
Loic
08:20 PM
It seems to me that the Timestamp conversation is not going well in the process
08:20
Jason
08:20 PM
Notice the / 1000 part
Loic
Photo of md5-3a88a602e4aba6a18b4a6c6985fcf08c
Loic
08:21 PM
Yes but in reality it is not was it does. The Timestamp in Firebase is in nanoseconds.

Example of timestamp in second: 1652386236
Example of timestamp in millisecond: 1652386236975
Example of timestamp stored in typesense: 1652386231
Jason
Photo of md5-8813087cccc512313602b6d9f9ece19f
Jason
08:22 PM
Hm are you sure? Current epoch time is 1652386958: https://www.epochconverter.com/
08:23
Jason
08:23 PM
Just saw your edit

1

08:23
Jason
08:23 PM
You should see timestamps stored in seconds in Typesense
Loic
Photo of md5-3a88a602e4aba6a18b4a6c6985fcf08c
Loic
08:26 PM
Ok, I will edit everything for seconds then. Thank you Jason

1