Why is the easiest solution often enough when solving a problem?

Why is the easiest solution often enough when solving a problem?

Working on an in house eCommerce application - that enables potential customers to buy products online - I am assigned a task whereby the date for a column is always two hours early, albeit only for a specific flow. If the same column value is used elsewhere, there is no such issue.

table_name -> column_name -> create or update.

For every other use case such as creating a new invoice or updating a product, the time is correct.

The technologies used are:

  • LuxonJS as an alternative to momentJS
  • NodeJS
  • MySQL
  • Sequelize
Photo by Safar Safarov / Unsplash

My first strategy is to try and reproduce the problem the user is having. Once confirmed, I document the process and try to understand the source of the problem.

I devise a list of questions that can help me based on my experience:

  • Are we using the correct timezone? Yes as the time is working well in the rest of the application.
  • Did I miss something when creating the Sequelize model? No it's of type Date. I verify in the table structure in MySQL and it's the same as elsewhere.
  • Do we have some sort of after hook in the Entity Schema? Nothing of interest.

I run the scenario a few times to check if there is an emerging pattern - but to no avail - I have the same result.

I try installing momentJS and doing the same thing; the same result.

After spending more than 8 hours on this task, with the issue being that the time is 2 hours early, I just add 2 hours, which is done as follow in LuxonJS:

const date = DateTime.local().plus({ hours: 2 });

Bam, problem solved.

Eventually everything hits the bottom, and all you have to do is wait until someone comes along, and turns it back again. ⌛️
Photo by Aron Visuals / Unsplash

I explains this solution to the PM, who tries escalating the problem to another dev (as it might not make sense). The latter finally arrives to the same conclusion.

"There is no magic in programming." ~ My University Lecturer

The easiest yet effective solution is adding 2 hours while time might be of constraint to drill into and understand the source of the problem.

Sometimes, writing software can be unpredictable. There is, however, no magic happening.

I think there might perhaps be a trigger in the database or a hook in Sequelize doing that, which might explain things, but at the same time, such an occurence can just happen. Or, there might be a bug with the NodeJS.

To conclude, not every time when solving problems do we need to look for the smartest or most challenging solution. In fact, with real life constraints, the most efficient can be the easiest one.