I am working on a project where you book hotel reservations.In the add booking page, I have an input datetime-local where the user selects the date and the time of the booking.
I want to get the online time and not use the device time to disable the user from booking past datetimes.
I tried to get the server time Timestamp from Firebase but did not know how to work with it.
I want to know what is the best way to deal with this issue.
For firebase3, use firebase.database.ServerValue.TIMESTAMP
$scope.createdDate = firebase.database.ServerValue.TIMESTAMP
doc is available here
and for date time picker go for this code.
Related
In my current application, I store a value in Firestore for each user something along the lines of this:
User1Doc - hasUsedFeatureToday = true
User2Doc - hasUsedFeatureToday = false
...
At the end of the day, I run a scheduled function that resets all of these to false. This was fine while my application was relatively small, but does not scale very effectively as I'm sure you can imagine.
Each user can only use this aspect of my app once per day, so the only time this field is read is when they try to use it.
I would like to change this system to store a timestamp in the user's document when they use the feature and then check if this timestamp is the same day (Europe/London time) if someone tries to use it again.
Does Firebase offer a way to get a "timezoned" timestamp like this and store/check it with the Firestore?
You can just store a timestamp (UTC). Whenever users logs in to your app, just check the timestamp and update the same. You can always use libraries like Luxon to get local time from the UTC time.
If you want to allow the user to update this timestamp only once, you can use security rules to restrict the same. However, user may try to prevent the timestamp from being updated at first place.
You can instead use Cloud Function to serve the data only when the user requests it. This will be better than updating documents of all users even if they won't be using the feature every day.
In my flutter application I want to prevent users to enter their nominations after the cutoff date.
For example, there is an exam nomination with cutoff date 31st March 2020. I am inserting the nomination data from my flutter app to the Firebase database. In app I'm checking the current date should be before the 31st March and then only allow to enter the data. However if the user changes the mobile data to backward the the app will allow to enter the nominations for the exam.
I know if I write the Firebase Cloud Function and move my insert code there it will solve the issue. But I have lot of code that I will have to rewrite :-(. Is there any other solution that will allow me to know the actual current date? What if the internet is off?
Thanking you in advance
You could maybe write a small amount of backend code to read the Firebase server timestamp and use that to check the cutoff. See this code:
exports.currentTime = functions.https.onRequest((req, res) => {
res.send({"timestamp":new Date().getTime()})
})
I got this from this SO answer so don't ask me for more details :-)
How to save the current date/time when I add new value to Firebase Realtime Database
Not sure about how to handle the Internet off... but if you can't read the server date, they can't submit the results.
Your only option that doesn't involve writing backend code is to use security rules to restrict database writes based on the current date. What you will have to do is set up a rule on the collection that should be restricted, and it will have a line that looks something like this:
allow write: if request.time < timestamp.date(yyyy, mm, dd);
Where yyyy, mm, and dd are the components of the date. If you want something more specific, read the security rules API docs for timestamp functions - you will have to provide an time in epoch milliseconds. Note that timestamps in security rules are always measured in UTC.
I'm building a multisided app where people can sell and buy food. Thats the shortest summarize possible.
When an user make a food order to a restaurant and this order has been marked as dispatched, the app generates a comission on the restaurant profile in firestore.
When the commission is created it triggers a background firebase cloud function that check if the restaurant has an active billing cycle, if not, it creates one like this:
billingCycle: {
openDate: 'the moment where the fee was created',
endDate: '4th day after' //
}
This object its created in the user profile (with correct date) and works ok!
Now I want to emit an invoice when the date of the endDate prop value arrives, here comes the question.
How can I trigger a function when the date of the endDate meet?
I was thinking in moving that decition to the app. That way the app detects when its time to trigger while is using it, but what if the user is not?
How can I trigger the firebase cloud function for emit the invoice independent the interaction of the user with the client app?
I've researched a lot to find an answer but I didn't find anything related so any kind of help is so much appreciated.
*This is the first time Im using FCF.
You can use an onUpdate trigger on documents that may get updated that way. Write code in the function that checks, on every update, if the dates match in the document. If the dates match, emit the invoice, then update the document again with a flag value that indicates the invoice is emitted.
You will also have to use that new flag to determine not to emit the invoice again on further updates (otherwise your function will send an invoice every time it's updated, when the dates match - this boolean will indicate that it already happened).
I'm writing an app that reads a Google Sheet that I have read access to. This is working just fine. It contains upcoming dates for things. The sheet contains usually no more than 20 - 30 upcoming events. Events that have passed are ignored.
I need to take these upcoming events and add them to a calendar. Adding events is ok. The problem is that if the app runs again say a week later, the events that are already on the sheet are added again, so I need a way of searching for an event in a calendar based on the date of the event. If I find an event at that date and time, then I can ignore it and move to the next one. It seems that searching for an event requires a calendar ID and an event ID. Is there a way to search for an event by giving a date and time, and say a partial summary?
Failing that, any other options? The data in the Google Sheet I have read access to only. My app doesn't store anything locally. The intention is to read the sheet and add events but not add duplicate events.
To get events you either use events.get where you provide the calendarId and eventId to fetch a specific event or Events.list to get all events.
I want to get the date of birth of connections using LinkedIn api.I got some informations using
http://api.linkedin.com/v1/people/~/connections:(headline,first-name,last-name,location)
If i am trying to add dateOfBirth or date-of-birth parameter to this api but it is not working. Can anyone please help me to get the date of birth of all connections?
headline,first-name,last-name,location are comes under basic profile but date-of-birth comes under full profile. So you have add the permission(r_fullprofile) for this one. Try Like this
NSArray *grantedAccess = #[#"r_basicprofile ",#"r_fullprofile", #"r_network"];
According to this document, you will need to apply to be able to retrieve the full profile information, like date of birth:
Member profile fields available to Apply with LinkedIn developers
The following selection of profile fields are only available to applications that have applied and been approved for the Apply with LinkedIn program:
Full Profile Fields
(...)
For more information, visit the Apply with Linkedin page.
Note: This is an old question but things may have changed, so this is for future reference.