Loading...

My battle with time

Date updated: 2021-11-19

View count: loading...

In the past few months, I have been working on timezone integration and date calculation for my company's application. Being a collaboration software, there are many aspects of the application that rely on the accuracy of information displayed to parties at any given time. Parties are tied to each other by contracts which have deadlines. Within each contract, there is a myriad number of dates and times which the system must keep track of. This information drives the reminder workflow and keep parties in sync. By keeping track of times, we're taking snapshots of events that can be traced back like history. Who did what and when. Inaccurate time tracking will break users' trust in our application and can even render the entire application useless. Sounds a bit dramatic? I'm not exaggerating this by any bit. I've spent a lot of time thinking about this subject to find the optimal way for us to handle time effectively. I hope it's as easy as calculating a time object, record it in the database, read it, and serve it to some UI components. However, it's not.

When we take into account recurring cycles (daily, weekly, monthly, quarterly, annually, etc.), parties' timezones, handling of date objects depending on contexts and how they can be consumed by UI components, the whole thing can get complicated quickly. As time wraps our entire application, the blast radius of this work is huge. This means, at any time, a team member can mishandle a date object for a component and create inconsistency throughout the system. This kind of mistake can be easily overlooked during code reviews. This can quickly become a minefield which is waiting to explode whenever a new PR is merged. This is not good. The integration needs to be as simple as possible for other engineers to apply. I have done a few rounds of refactoring every part of our codebase that's time-related (which is a lot) and still haven't got to where I should be. The whole thing is still not simple enough to reason about or to test for anybody who hasn't starred at this as long as I have. Even I still miss timezone handling here and there. Not enough UI tests are in place. When I zoom in any code snippets, it's really just basic math and very easy to explain. The challenge is when I glue the pieces together and apply to different places with different contexts across our system. I'm quite confident in the accuracy of my calculation but there are still many rooms for errors when it comes to implementation. This is like telling a story with codes. It should be coherant and makes sense. I'm a very bad storyteller but I will keep trying.

This ongoing battle has taught me a lot about good engineering practices. I will continue to work with my team to improve on the solution and, hopefully, when we get over this mountain, I think we'll be very proud of what we have accomplished: a product that people can trust and rely on for their day-to-day business. This is what I love about software engineering. Scratching my head for a never-ending period of time just to enjoy that high moment when the problem is solved... until another problem arises :)

Loading...
by tuanab @ 2024