Home > Software design >  Business hours in different timezones
Business hours in different timezones

Time:02-09

I am trying to display a users business hours in one timezone to another timezone.

A users business hours is stored as below object for each day of the week

Timezone = Asia/Kolakata
Day number = 3 (Wednesday)
Hour = 7:00 (12 hour system)

the above is in IST

But now if i need to reteive this for a user in Australia, I can change the timezone and get the value. But this would be incorrect as a business hour available on Monday in one timezone might be valid for Tuesday in another. What is the best way to deal with this conversion?

The objects are being store and retrieved from Firestore.

Any help/guidance would be appreciated

thanks

CodePudding user response:

If you want to be able to query the business hours across all time zones in one go, you will have to store the hours in a single, normalized time zone (typically UTC) for all business.

So you'll Hour (and possibly Day number) field are the in UTC, and you'd use the Timezone field to indicate what timezone the store is in.

Then to query for the Australian user, you convert their local time zone to UTC too, and can query across all documents.

So in this approach, all times stored in the database are normalized, and you use a time zone only when converting the entered data to the database format, or when displaying the data from the database into a display value again.

  •  Tags:  
  • Related