Timezone Agnostic

Timezones drive me mad. I’m pretty sick of them. What is the best way to ensure your codebase is timezone agnostic?

In my case time is always the local time at the venue of the event. When I view or edit it regardless of my current location I would like it to show in the venue time and save in the venue time. I never have a use for time zones. Is there a way to just force all times to be UTC?

I’m tempted to just use strings :stuck_out_tongue:

I think you may be better off using strings or some other structure, this is just from experience on Java server side development where we use LocalDate and LocalTime which is a representation of date and times without the timezone components for any business dates.

Though I am not 100% sure, but momentjs should have something for that

A second vote for momentjs here. You can force everything into UTC, if that’s your prerogative.

Using momentjs definitely takes some of the hassle out of managing events across time zones, but if you do everything in UTC (without a pre-client conversion) you’re asking your users to do a bit more work…

Hey hey, I just solved this big time! On my site the user-account entering the times has a timezone property like user.timezone

Once you know the timezone of your user, you can essentially use moment.js to recreate the conditions his browser was in on the server.

Say the user reports that his date is “2016-04-04” and the hour is “5”

I pass that info along to the server and the server reconstructs it as absolute values for use elsewhere on the site.

Everything is drop dead easy with moment-timezones and the ability to recreate the exact conditions the user’s browser was in.

1 Like

Cool implementation!