Firebase server time stamp same as local (almost) - firebase

Is firebase generated server time stamp automatically converted into local time as I am getting the time stamp same as my local time or am I missing something?
_firestore.collection("9213903123").document().setData(
{
"title": title,
"message": message,
"deviceTimeStamp": DateTime.now(),
"serverTimeStamp": FieldValue.serverTimestamp(),
},
);
after running the above statement I can see both devicetimestamp, and serverTimeStamp are same.
But their is slight delay in their seocons.
Data In firestore...
deviceTimeStamp
8 August 2020 at 16:39:08 UTC+5:30
(timestamp)
message
"26"
serverTimeStamp
8 August 2020 at 16:39:16 UTC+5:30
title
"26"
The thing I am trying to do is basically ordering on the basis of date time and the user can see when he has created the notes, but if someone creates a note and stores it into firestore anywhere from the world(irrespective of location). Will, he/she gets their local time by using server timestamp(as I want this so can user see when they have added their document). ANd for safety, I want to use server time stamp so if a device is not in sync with the current time .

Firestore's FieldValue.serverTimestamp() creates and stores the timestamp in UTC Epoch time at the moment the request reaches the Firestore server.
Calling serverTimestamp() doesn't create a timestamp at the time it is invoked and doesn't rely on your user's device time or timezone. Instead, it creates what could be thought of as a placeholder for the date/time. This placeholder is only converted to a timestamp once the request is received by the Firebase server. As a result, the Firestore timestamp will always be at least slightly later than your client date/time (assuming the client time is perfectly synced.)
Using Firestore's timestamp should generally meet your goals of storing dates/times for users across the world in a consistent way, retrieving / sorting notes by creation time, and converting the timestamps into the user's local timezone client side. You may, however, want to handle things slightly differently for scenarios when your users are offline.
See Doug Stevenson's article for a helpful, more detailed explanation of Firestore timestamps.

Related

Firebase Timestamp (serverValue) in seconds?

1. The problem
I'm trying to write some values organizing them by the timestamp value (in seconds, not milliseconds) they arrive to the database in order to trigger a function in the server every time data arrives.
I expect to register this every second because milliseconds will trigger too many times and I don't need it that often.
E.g.
|- timestampSecond1: true
|- timestampSecond2: true
|- ...
|- timestampSecondX: true
I'm using Firebase Realtime Database
2. What I've tried
2.1. ServerValue Timestamp:
Using this approach writes the timestamp in milliseconds. Since ServerValue Timestamp is a placeholder that gets replaced directly by the server the moment it arrives, I cannot modify it before it gets replaced or when I sent the post request to the server in order to convert it to seconds.
https://firebase.google.com/docs/reference/android/com/google/firebase/database/ServerValue
2.2. Cloud Functions: Phased server function to evaluate and calculate the range to the millisecond written by ServerValue and then writing in another branch the value in seconds.
2.3. Cloud Functions: Function triggered by the arrival of data and writing the data in seconds directly. Calculating internally the equivalence in seconds of the timestamp.
I'm aware 2.2. and 2.3. will work for what I'm trying to do, but I'm wondering if there is another way to do this without envolving server functions.
3. Help
Are there any workarounds to mark the timestamp in seconds using ServerValue or other methods that ensure the timestamp written is the same data arrives to the server?
Thank you.

Firebase cloud functions dynamic time zones

So in my android app, I am using the real-time database to store information about my users. That information should be updated every Monday at 00:00 o'clock. I am using a cloud function to do this but the problem here is the time zones. Right now I have set the time zone to 'Europe/Sofia' for testing purposes. In the documentation, it is said that the time zone for cloud functions must be from the TZ database. So I figured I could ask the user before registering in my app their preferred time zone and save it in the database. My question is after getting the user's prefered time zone is there a way to only write one cloud function and execute it dynamically for each time zone in the TZ database or do I have to create individual functions for each time zone in the TZ database?
If I correctly understand your question, you could have a scheduled Cloud Function which runs every hour from 00:00 to 23:00 UTC+14:00 on Mondays, and, for every execution (i.e. for every hour within this range), query for the users that should be updated and execute the updates.
I'm not able to enter more into details, based on the info you have provided.
It's not possible to schedule a Cloud Function using a dynamic timezone. You must know the timezone at the time you write the function and declare it statically in your code.
If you want to schedule something dynamically, read through your options in this other question: https://stackoverflow.com/a/42796988/807126
So, you could schedule a repeating function that runs every hour, and check to see if something should be run for a user at the moment in time that it was invoked. Or, you can schedule a single future invocation of a function with a service like Cloud Run, and keep rescheduling it if needed.

Can Azure Application Insights Kusto queries obtain the user's current time zone?

We have a chart that restricts details to "today". Today means something different depending on the viewer's time zone: right now for me (in Adelaide, AUS) today means everything in the last 15 hours but for someone in the UK it only means everything in the last 6.5 hours. Is there any way of retrieving the client's time zone in a Kusto query in Application Insights?
Go to settings of the query console:
Change timezone to "Local Time" (default is UTC)

Google Analytics export to BigQuery

I have a doubt related to the data export from Google Analytics into BigQuery.
Basically, I have configured the streaming export on the Google Analytics side to, in real time, export the data into the BigQuery (table ga_realtime_sessions_YYYMMDD). This streaming is working fine.
At some point at the end of the day, the data from this real timetable is exported into the ga_sessions_YYYYMMDD.
What I need to be explained is how this export (from the real timetable into the ga_sessions one) works.
I have several automatic processes that run around 8 AM (Portugal timezone) and, in the last days, these processes are failing due to the fact that the ga_sessions for the previous day are not created yet.
I checked the time that the ga_sessions are created for every day and this time is very volatile, and for some cases is around 2 AM, 3 AM but in another case is around 7 AM, 8 AM. This time difference could be due to the data size that needs to be exported from the real timetable into the ga_sessions one?
The exports of daily sessions in BigQuery are indeed not completed at the same time everyday. This is due to a fully managed backend, which depends on workloads worldwide.
I suggest that you create an event listener on file creation for ga_sessions_YYYYMMDD, so that only once it is created you can then safely run dependent processes.
E.g. you can export the file in a Cloud Storage bucket, then use a trigger with a Cloud Function.

Time Period of Firebase realtime profile operations

The official document of Firebase Realtime profiler says:
The profiler tool logs all the activity in your database over a given period of time, then generates a detailed report.
But it doesn't tell the specific time like last 24 hours.
My database usage shows that on a particular day, bandwidth consumed is X so I want to specify a particular day or time duration like last 24 hours in Firebase Realtime database profiler >
Q1. Is it possible to specify the duration in profile like last 24 hours?
Q2. How does profiler work?
I think, profiler just scans some log and keeps writing/streaming the operations to user console unless user stops the the profiling tool. Correct me if I am wrong here.
Q1. Is it possible to specify the duration in profile like last 24
hours?
No, it's not possible to profile "last" hours. But you can profile the next 24. (I'll get to that on Q2)
Q2. How does profiler work?
What the profiler does is it logs all the operations happening on your database from the time you run the command until the time you stop it. When you run the command, the console will show you how many operations have been logged so far and you can use Enter to stop logging. It will then show you (or save it to a file if you prefer) speed and bandwidth reports.
But it also has an option to set the logging duration (in seconds). For example, if you want to log the next 24 hours you can use:
firebase database:profile -d 86400
But have in mind that logging only happens if the computer that started it is still on. This means you'll need to keep your computer on for the next 24h.

Resources