SOMOS RECOMENDADO

Onde se hospedar em Caraíva — melhores pousadas. A vila de Caraíva é quase inteiramente dedicada ao turismo. Enquanto grande parte dos nativos mora na nova Caraíva (na outra margem do rio) ou na…

Smartphone

独家优惠奖金 100% 高达 1 BTC + 180 免费旋转




An analysis to resolve a perpetual year end bug

Here is a real life scenario in one of the payment gateway solution my peers have handled back in early 2000:

The date value has been stored correctly for most part of the year except during the transition to new year where the year fails to be in sync with the actual year when the transaction has occurred at the terminal end; e.g. 1231 gets stored as 191231 when it should be 181231, or 0101 gets stored as 180101 when it should have been 190101. This is due to the fact that all the payment terminals are scattered in different parts of the country and their clocks are not in sync with the host. They tend to be either few seconds ahead or few seconds behind the host and this creates a problem when the system is crossing to a new year. And for 3 consecutive years, problem was reported and programmers were called in to produce a solution which they duly declared fixed, only to receive another call the following year of the same problem.

By the time I was called in to investigate on the third year, what I saw was a nasty deeply nested if-then-else code which I have no idea where to start and what to look for. After spending some time understanding the issue, here is the possible scenario analysis that I have come up with which leads me to the eventual solution.

The first step of my analysis involves compiling all the different scenarios that may occur:

Note: Value in () denotes YY not send in by terminals

Upon studies, it is decided that scenario 8 will not occur in real life and is dropped out from the analysis.

Next is to figure out a way to be able to determine the correct value to compare and what I have thought of was to add another day to the date in host, and here is what I get:

By comparing the MMDD of date received (R), with the MMDD of next day in host (N), we get the result of R<H for scenario 1 because 1230 in R is less than 1231 in N. Likewise for scenario 2 where 1231 of R is identical to 1231 in N, thus R=H, and R>H for scenario 3 where 1230 of R is greater than 0101 of N.

After completing the analysis of all 7 scenarios, it is clear that only a single if statement is required to produce the desired result, which is to reduce YY of N by 1 when R>H. The code fragment in python is as follows:

Add a comment

Related posts:

Understanding the Power of Mobile POS Systems

Unlike traditional POS systems that require a stationary checkout point, mPOS systems allow you to take the checkout process to the customer, whether that’s on the shop floor, at a trade show, or…

Brantford Municipal Election 2018

The final STAR of my 5 STAR platform is Community Engagement. So let’s bring this equation all together. Safe Community + a Moving Community + Growing Local Economy + Healthy and Stable Community =…

Buy Google Reviews

Most businesses buy Google reviews because they understand the effects of spoken word or language and they know a lot of spoken language. Who understands how to move business forward. When it comes…