user login from india at 9:00 am
other user from usa at other time.
how handle this if both the user having same server but login from different timezone
You haven't really told us what your problem is, but the best way to handle multiple timezones is to always store your timestamps in UTC, and convert from local to UTC on insert, and from UTC to local for display.
You could store timezone offset for each user (make the user select one timezone when he creates the account) and do the transformations based on that
Related
I have a firestore database that looks like this
/entries/ ....
/users/{userid}...
a bunch of documents is being sent into ... of entries and userid contains on 8 docs of user profile information.
my problem is that the entries doc contains field hours and no relation to the user doc which contains the field weekly_capacity
I need to aggregate this the two fields hours/weekly capacity setting them to Full-time equivalency variable
But the Full-time equivalency needs to be accurate and this company FTE can change so it would need to calculate the FTE over various date even if the user changed their FTE status x number of times.
And the current app only fetched the entries when the user logins into the app, which can be whenever.
None of the API requests that I am using will give me a json that holds both weekly_capacity and hours on the same fetch. If every time a user logs into the app firestore calls the http to fetch all entries then how can I compare the hours field on the collection's entries to the weekly_capacity field
Just a little context: FTE = Full-time equivalency and is used to measure as a standard to see if an employee compares to there core commit hours they signed up for which is 40. SO if I agreed to work 40 and I work actually work 40 hours then I would be 1 whole FTE. If I worked 20 and I suppose to work 40 I am .5 FTE. The math is really simple it's just that in my situation the variable FTE can change any time and the app will allow the user to enter a range of dates fetching the total actual hours they worked and FTE letting them know how many hours they were supposed to work vs how many hours they actually worked. Since the variable changes, I need some way in firestore to track the change and aggregate correctly against the hours actually worked. To give an error example: let's say I changed my FTE from 1 to .7 on March 20th, I then want to generate a report of March 1 to March 30th stating my hours worked and FTE status meaning did I reach my goal. The kicker is that I can't fetch or merge the entries which hold the var hours and /users/ which hold the var weekly_capacity.
I don't even think a cloud function would solve the problem since entries are only fetched when the user logins in right?
I'm assuming the following for answering your question.
Requirement: To calculate FTE for a user when user's weekly_capacity is updated or user logs in.
Problems:
Some way in firestore to track the change.
Calculate FTE correctly according to the change.
Here's what I think will solve the problems.
Google Cloud Firestore supports listeners for the collections in which you store the data. So you can listen for any change in users collection and entries collection. This is how you can track the change.
To calculate FTE, when a change is made to weekly_capacity of user document or a new entry is made to entries collection you need to query both collections separately to get the records corresponding to the user affected. You can also use a collections-group query for this purpose but that depends on your database design.
Hope that helps.
I have different users having different timeznoes. Suppose , one user has timezone set as GMT-8:00 (America/Los_Angeles) another has GMT+5:30 (Asia/Kolkata). I have one mysql function which returns current local date time on basis of user.
SELECT CONVERT_TZ(CONCAT(UTC_DATE(),' ',UTC_TIME()),'+00:00','-08:00');
Now this is not considering DST timezone. So how to find whether timezone is currently following DST and get date time on basis of that.
I know pages and pages have been written on this topics, however, I need to clarify this issue, and be sure I'm doing what is sensible.
The users of my app can be in any part of the world. I log a number of events/actions a user performs on my app. I want to be able to see what events/actions a user made in it's own time zone, or a timezone of my choosing.
At the moment, my app is sending the date and time of the event in UTC in the format "YYYY-MM-DD HH:MM:SS" and also, in a separate field, the time zone offset in minutes (e.g. -120 or +60).
When I get the events, I store them in MySQL in the following way: I use a DATETIME column to store the date and time of the event as is; I use an INT column to store the offset.
When I want to do a select and get back the event in the user's time zone, I just do:
SELECT cdate + INTERVAL tz_offset MINUTES FROM events WHERE uid=123;
I believe this is the best option for me, and offers versatility.
What do you think?
Thank you!
I'm trying to retrieve all the entries of the day in my model:
where('date(created_at) = date(?)', Date.today)
But, because of the timezone (My local time is UTC+2), I don't have the expected result. For example, if an entry has been created one minute after midnight, in the database, it will be stored at 22:01 (so not "Date.today").
Is there a way to do that ?
EDIT:
As the admin of the website, I want to display the number of the entries on my local time "today" (It's only for statistics purpose!). So I want to keep timestamps store in utc, but convert them to my local timezone during this request!
You can set the correct time zone in several ways. One is described in this answer:
https://stackoverflow.com/a/6118837/567126
adding following to application.rb works
config.time_zone = 'Eastern Time (US & Canada)'
where('date(created_at) = ?', Time.zone.now.to_date)
Time in the database should be stored as UTC. This way, when you do a worldwide website, you can serve each user with their own timezone.
It's the UI (views) responsibility to show the time in the user's local timezone.
For your where you should use Time.now.utc
This way, you are searching the DB with the common UTC.
Is there any query to insert country name and its time zone in GMT, for a mysql database. I want to add all the country name and its time zone difference with GMT or UTC
try to google the list but you may have to actually write extraction code
On top of that, large countries like USA, Canada & Russia have multiple time zones
Its all up to you how you want to design the database and code according to that.
This is the list Fedora is using...
http://unicode.org/repos/cldr/trunk/common/supplemental/windowsZones.xml
start from here
Here is another list
http://www.timegenie.com/world.time